Update PDF view after page and form field changes

Q:

I am using PDFViewCtrl on Android to view PDF and would like to clone the current set of pages that contain some form fields. The code is as follows:

doc.lock(); // Lock PDF from any changes

int page_num = doc.getPageCount();

for (int page = 1; page <= page_num; page++) {

Page curpage = (Page)(doc.getPage(page));

doc.pagePushBack(curpage);

}

// doc.save(output_path, SDFDoc.e_linearized, null);

doc.unlock();

The output file is fine but the PDF viewer control does not show newly added pages (also the last page is truncated is truncated at the bottom).

Also when the PDF page is copied that contains field names….(for example last name and first name), how do you reference

field names in the copied page?

A:

Since you are copying pages in a document that is opened in PDFViewCtrl (i.e. PDF widget), you need to call pdfview.updatePageLayout() to reflect your document changes / edits in the control.

So, whenever you update page layout (e.g. add/remove pages, change page dimensions, etc) you need to call pdfview.updatePageLayout().

Regarding the second question, you may want to take a look at InteractiveForms

If you want to use different fields on each page you may need to rename them as shown in:

http://www.pdftron.com/pdfnet/samplecode/InteractiveFormsTest.java

static void renameAllFields(PDFDoc doc, String name) throws PDFNetException

{

FieldIterator itr = doc.getFieldIterator(name);

for (int counter=0; itr.hasNext(); itr=doc.getFieldIterator(name), ++counter) {

Field f = (Field)(itr.next());

f.rename(name + counter);

}

}