Update PDF view after page and form field changes

90 views
Skip to first unread message

Support

unread,
Nov 23, 2012, 5:41:29 PM11/23/12
to pdfne...@googlegroups.com
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  sample that comes as part of the SDK. You current code performs simple page clone. This means that all widget annotations will point the same shared field, so if you set a field name to "Joe" all instances of the widget all pages will show "Joe".

 

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);                       

   }

}

 

 

 

Reply all
Reply to author
Forward
0 new messages