I want to use a pdf file which includes forms like edit fields and checkboxes as a template. The pdf file has to be read, partially filled and written to a new file. This has to be done without user interaction, the pdf is not displayed at this step. The newly created pdf file will be read and displayed at a later stage.
How can this be done? Is there existing sample code?
if the PDF run as fill fields:
1. copy template file to another file.
2. open the pdf file copied.
3. get page, and invoke page.ObjsStart();
4. fill the fields, by field name.
using Annotation.GetFieldFullName2() or Annotation.GetFieldFullName()
5. close the page and save the document.
6. close document
you can check filed full name one by one.
for (index = 0; index < page.GetAnnotCount(); index++ )
Annotation annot = page.GetAnnot(index);
if( annot.GetFieldFullName2() == find_name ) ....
But I still have problems to fill an edit field. If I open a pdf from sdcard, the method setEditText returns true and the text appears in the edit field. But when I open the same pdf from the assets folder, the method setEditText returns false and the edit field remains emtpy.
Here is the code to open the pdf from sdcard:
And this is the code to open the same pdf from the assets folder:
PDFAssetStream stream = new PDFAssetStream();
Interestingly, there is now problem to set checkbox states, only the edit field is affected. I didn't try other forms.