开发者

DynamicPDF api to render PDF forms in Java

I have PDF forms and I used adobe acrobat pro version 9 to开发者_开发百科 add some hidden fields, buttons and some validation in javascript to it.

Also I am using dynamicPDF api (first time) in java to read that PDF and pre-populate few fields with some values (eg date with current date and some url fields) and drawing it into byte array and sending back to render.

But while rendering dynamic PDF is messing up my forms. Its not showing buttons perfectly that I added using adobe. Buttons are displayed with NO LABEL on it and if I click it shows * on it. Don't know why.

I am using Dynamic PDF as a replacement to FDF Merge. So I want same functionality from dynamicPDF and I am total beginner to both APIs.

Any suggestion?


This is my helper class to write and PDF---

public class PDFMerge {

    private MergeDocument document = null;



    public PDFMerge(File template) throws Exception {

        if (templatePdfFile == null)  {
            throw new Exception( );
                document = new MergeDocument(template.getAbsolutePath(), new MergeOptions(true));
        }


           }

    public MergeDocument mergePDF(String pdfformid, String url,
            ) {

        Calendar cal = Calendar.getInstance();

        if (document != null) {

                               //hidden fields on PDF form 


                if (document.getForm().getFields().getFormField("url_to_submit") != null) {
                    document.getForm().getFields().getFormField("url_to_submit")
                            .setValue(url);

                }


                //Date fields to prepopulate before rendered on browser

                if (document.getForm().getFields().getFormField("date.mm") != null) {
                    document
                            .getForm()
                            .getFields()
                            .getFormField("date.mm")
                            .setValue(
                                    String.valueOf(cal.get(Calendar.MONTH) + 1));

                }

                if (document.getForm().getFields().getFormField("date.dd") != null) {
                    .....

                }

                if (document.getForm().getFields().getFormField("date.yyyy") != null) {
                    ....
                }




            }
        }
                //document is drawn into byte array in servlet to send to output stream.

        return document;

    }


}

On servlet/caller (struts action) side ----

PDFMerge pdfmerge = new PDFMerge(form.getTemplateFile());
MergeDocument mergedPDF = printTool.mergePDF(String
.valueOf(form.getFormId()), URL);


byte[] pdfArray = mergedPDF.draw();

This byte array is forwarded onto JSP to be rendered. It doesnt display buttons correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜