Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1

TOPIC:

How to create a new pdf file from a template pdf 9 years 6 months ago #7402

  • Dotzler
  • Dotzler's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
Hi,

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?

Regards,
Josef

Please Log in or Create an account to join the conversation.

How to create a new pdf file from a template pdf 9 years 6 months ago #7403

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
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.
using loop:
for (index = 0; index < page.GetAnnotCount(); index++ )
{
Annotation annot = page.GetAnnot(index);
if( annot.GetFieldFullName2() == find_name ) ....
}
The following user(s) said Thank You: sappi

Please Log in or Create an account to join the conversation.

How to create a new pdf file from a template pdf 9 years 6 months ago #7412

  • Dotzler
  • Dotzler's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
Thank you very much for your fast response!

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:
m_doc.Open("/mnt/sdcard/test.pdf", null);

And this is the code to open the same pdf from the assets folder:
PDFAssetStream stream = new PDFAssetStream();
stream.open(getAssets(), "test.pdf");
m_doc.OpenStream(stream, null);

Interestingly, there is now problem to set checkbox states, only the edit field is affected. I didn't try other forms.

Is this a bug or have I missed something?

Regards,
Josef

Please Log in or Create an account to join the conversation.

How to create a new pdf file from a template pdf 9 years 6 months ago #7414

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
PDF file open from assets are read-only.
so you can extract PDF file from assets to sdcard.
then edit fields.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum