简体   繁体   English

DynamicPDF api 来渲染 PDF forms 在 ZD52387880E1EA22817A72D3759213819

[英]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.我有 PDF forms 并且我使用 adobe acrobat pro 版本 9 在 javascript 中添加了一些隐藏字段、按钮和一些验证。

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. 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.但是,在渲染动态 PDF 时,我的 forms 被搞乱了。 Its not showing buttons perfectly that I added using adobe.它没有完美地显示我使用 adobe 添加的按钮。 Buttons are displayed with NO LABEL on it and if I click it shows * on it.按钮显示为 NO LABEL,如果我点击它会显示* Don't know why.不知道为什么。

I am using Dynamic PDF as a replacement to FDF Merge.我正在使用 Dynamic PDF 作为 FDF Merge 的替代品。 So I want same functionality from dynamicPDF and I am total beginner to both APIs.因此,我希望 dynamicPDF 具有相同的功能,而且我完全是这两个 API 的初学者。

Any suggestion?有什么建议吗?

This is my helper class to write and PDF---这是我的帮手 class 写和 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 ----在 servlet/caller(struts 动作)方面----

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.这个字节数组被转发到 JSP 以进行渲染。 It doesnt display buttons correctly.它没有正确显示按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM