Android fill PDF form

前端 未结 2 768
借酒劲吻你
借酒劲吻你 2021-02-04 08:46

I have .pdf file and multiple forms are there. I want to open my .pdf file, fill the forms and save it from Android development.

Is there any API for A

2条回答
  •  有刺的猬
    2021-02-04 08:52

    DynamicPDF Merger for Java allows you to do just that. You can take an existing PDF document, fill out the form field values and then output that newly filled PDF.

    There was a recent blog post on dynamicpdf.com on setting up DynamicPDF for Java in an Android application and creating a simple PDF from it, http://www.dynamicpdf.com/Blog/post/2012/06/15/Generating-PDFs-Dynamically-on-Android.aspx.

    You can easily take that example one step further and use it to accomplish your task of form filling. The following (untested) code is an example of what it would take to form fill an existing PDF on an Android device using DynamicPDF Merger for Java:

    InputStream inputStream = this.getAssets().open("PDFToFill.pdf");
    long avail = inputStream.available();
    byte[] samplePDF = new byte[(int) avail];
    inputStream.read(samplePDF , 0, (int) avail);
    inputStream.close();
    PdfDocument objPDF = new PdfDocument(samplePDF);    
    
    MergeDocument document = new MergeDocument(objPDF);
    document.getForm().getFields().getFormField("FormField1").setValue("My Text");
    document.draw("[PhysicalPath]/FilledPDF.pdf");
    

提交回复
热议问题