将.xfdf保存为.pdf [英] Saving .xfdf as .pdf

查看:169
本文介绍了将.xfdf保存为.pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Excel填写带有表单字段的PDF文件。它一切正常,但它将它作为.xfdf导出。有没有人知道如何将其保存为pdf?

  FullFileName = FilePath& 申请 - &修剪(MyRecord.CompanyName)&  - & _ 
年份& - &月& - &日& - &小时 - &分钟& - &秒和.xfdf
打开FullFileName作为#1
打印#1,<?xml version =1.0encoding =ISO-8859-1?&
打印#1,< xfdf xmlns =http://ns.adobe.com/xfdf/xml:space =preserve>
打印#1,< fields>

打印#1,< field name =由提交>< value> +修剪(MyRecord.RequestedBy)+< / value>< / field>
打印#1,< field name =作业名>< value> +自动卡+< / value>< / field>
打印#1,< field name =运送地址>< value> +修剪(MyRecord.StreetNumber)& &修剪(MyRecord.StreetName)& ,Unit&修剪(MyRecord.Suite)& ,&修剪(MyRecord.City)& ,&修剪(MyRecord.Province)& ,&修剪(MyRecord.PostalCode)+< / value>< / field>
打印#1,< field name =特殊说明>< value> +打印+< / value>< / field>
打印#1,< / fields>
打印#1,< f href =.. \Requisition_Fillable.pdf/>

打印#1,< / xfdf>
关闭#1'关闭文件。


解决方案

XFDF是FDF的XML风格。 FDF代表表单数据格式。它是一种用于存储数据而不具有PDF实际内容的文件格式。 FDF使用PDF语法存储此数据。 XFDF使用XML。



您不能将FDF或XFDF文件转换为PDF,因为缺少信息太多。您可以将(X)FDF文件导入具有相应AcroForm字段的PDF。



请查看





显然这只有在表单(在这种情况下 Requisition_Fillable.pdf )与XFDF流中的数据对应时才有效。例如:我的模板将与您的数据提交者运送地址的数据一起使用。对于作业名称特殊说明的字段不起作用,因为这些字段不存在于我的模板在我的模板中,这些字段名为工作名称特殊说明;您是否看到较小的案例,而不是大写?



如果要使用我的模板,您必须更改这两个字段名称,无论是在XFDF中文件或PDF模板中。另外:我的例子是用Java编写的。在VB中工作时,您必须使用iTextShtml的.NET版本,即iTextSharp。经验丰富的VBA开发人员不应该将我的例子从Java移植到VB。只要将Java看作伪代码就可以了。



免责声明:上述示例需要iText。我是iText集团的首席执行官,这个例子来自我的书iText in Action - Second Edition。


I am currently using Excel to populate a PDF file with form fields. It all works but it exports it as a .xfdf. Does anyone know how I can save it as a pdf instead?

FullFileName = FilePath & "Requisition - " & Trim(MyRecord.CompanyName) & " - " & _
Year & "-" & Month & "-" & Day & "-" & Hour & "-" & Minute & "-" & Seconds & ".xfdf"
Open FullFileName For Output As #1
    Print #1, "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"
    Print #1, "<xfdf xmlns=""http://ns.adobe.com/xfdf/"" xml:space=""preserve"">"
    Print #1, "<fields>"

    Print #1, "<field name=""Submitted by""><value>" + Trim(MyRecord.RequestedBy) + "</value></field>"
    Print #1, "<field name=""Job Name""><value>" + "Auto Cards" + "</value></field>"
    Print #1, "<field name=""Shipping address""><value>" + Trim(MyRecord.StreetNumber) & " " & Trim(MyRecord.StreetName) & ", Unit " & Trim(MyRecord.Suite) & ", " & Trim(MyRecord.City) & ", " & Trim(MyRecord.Province) & ", " & Trim(MyRecord.PostalCode) + "</value></field>"
    Print #1, "<field name=""Special Instructions""><value>" + "Print" + "</value></field>"
    Print #1, "</fields>"
    Print #1, "<f href=""..\Requisition_Fillable.pdf""/>"

    Print #1, "</xfdf>"
Close #1    ' Close file.

解决方案

XFDF is the XML flavor of FDF. FDF stands for Forms Data Format. It is a file format to store data without the actual content of a PDF. FDF uses PDF syntax to store this data. XFDF uses XML.

You can't "convert" an FDF or XFDF file to PDF because there is too much information missing. You can import an (X)FDF file into a PDF that has corresponding AcroForm fields.

Please take a look at the ImportXFDF example. For that example, I wrote a simple XFDF file: data.xfdf:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>
<field name="Submitted by"><value>Santaaimonce</value></field>
<field name="Job name"><value>Developer</value></field>
<field name="Shipping address"><value>Alphabet Street
Minneapolis
Minnesota</value></field>
<field name="Special instructions"><value>Use iText to fill out interactive form using data stored in XFDF file.
If you are a C# developer, use iTextSharp.</value></field>
</fields>
<f href="Requisition_Fillable.pdf"/>
</xfdf>

This information is not sufficient to create a PDF, but as you can see, there is a reference to a template PDF file: Requisition_Fillable.pdf.

If you put data.xfdf and Requisition_Fillable.pdf in the same directory and you open data.xfdf, you will see the following message:

Adobe Reader opened the XFDF file, found the reference to the PDF template, opened the template and now asks you if you want to import the data. If you click on the Options button and you allow the import, you will get this result:

The problem you are experiencing is simple: you don't have the file Requisition_Fillable.pdf anywhere. You may also want to avoid that people are able to change the data that is filled in.

You can solve this by merging the XFDF file and its template programmatically:

protected void fillXfdf(String SRC, String XFDF, String DEST) throws IOException, DocumentException {
    // We receive the XML bytes
    XfdfReader xfdf = new XfdfReader(new FileInputStream(XFDF));
    // We get the corresponding form
    PdfReader reader = new PdfReader(SRC);
    // We create an OutputStream for the new PDF
    FileOutputStream baos = new FileOutputStream(DEST);
    // Now we create the PDF
    PdfStamper stamper = new PdfStamper(reader, baos);
    // We alter the fields of the existing PDF
    AcroFields fields = stamper.getAcroFields();
    fields.setFields(xfdf);
    // take away all interactivity
    stamper.setFormFlattening(true);
    // close the stamper
    stamper.close();
    reader.close();
}

Mind the following line:

stamper.setFormFlattening(true);

This will flatten the form: the fields will no longer be fields, they will just be like any other content. You end up with a regular PDF: xfdf_merged.pdf

Obviously this will only work if the form (in this case Requisition_Fillable.pdf) corresponds with the data in the XFDF stream. For instance: my template will work with your data for the fields "Submitted by" and "Shipping address". It won't work for the fields "Job Name" and "Special Instructions", because those fields don't exist in my template. In my template those fields are named "Job name" and "Special instructions"; do you see the lower cases instead of the upper case?

If you want to use my template, you'll have to change those two field names, either in your XFDF file or in the PDF template. Also: my example is written in Java. As you are working in VB, you'll have to use the .NET version of iText, which is called iTextSharp. An experienced VBA developer shouldn't have any problem porting my example from Java to VB. Just think of the Java as if it were pseudo-code.

DISCLAIMER: the above example requires iText. I am the CEO of the iText Group and the example was taken from my book "iText in Action - Second Edition".

这篇关于将.xfdf保存为.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆