iText7不会使用值填充单选按钮

时间:2019-11-11 21:34:14

标签: pdf-generation itext7

我正在使用iText 7生成具有XFDF功能的PDF文件。 我在iText网站上使用了给定的示例。我已成功与iTextSharp一起使用的同一XFDF文件看起来并没有在新的iText7版本中填充唯一的单选按钮(复选框和文本字段都可以)。

有人遇到同样的问题吗?

    using System;
    using System.IO;
    using iText.Forms.Xfdf;
    using iText.Kernel.Pdf;

    namespace iText.Samples.Sandbox.Acroforms
    {
        public class FillFormXfdf
        {
            public static readonly String sourceFolder = "../../resources/pdfs/";

            public static readonly String DEST = "../../results/sandbox/acroforms/setFields.pdf";


            public static void Main(String[] args)
            {
                FileInfo file = new FileInfo(DEST);
                file.Directory.Create();

                new FillFormXfdf().setFields(DEST);
            }

            // Currently iText xfdf implementation works in the following way:
            // the XFDF file is used to insert data from it directly into the PDF.
            public void setFields(String dest)
            {
                String pdfForm = sourceFolder + "simpleRegistrationForm.pdf";
                String xfdf = sourceFolder + "register.xfdf";
                PdfDocument pdfDocument = new PdfDocument(
                    new PdfReader(new FileStream(pdfForm, FileMode.Open, FileAccess.Read)),
                    new PdfWriter(new FileStream(dest, FileMode.Create)));
                XfdfObjectFactory factory = new XfdfObjectFactory();
                XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdf, FileMode.Open, FileAccess.Read));
                xfdfObject.MergeToPdf(pdfDocument, pdfForm);
                pdfDocument.Close();
            }
        }
}

0 个答案:

没有答案