我尝试创建一个PDF/A-3b文件,其中包含要符合ZUGFeRD的嵌入式XML。为此,我使用Perl和PDFLib。这里的PDFLib文档仅适用于Java和PHP。创建PDF很好,但是XML部分是我的问题。
那么,如何从xml创建pvf并将其加入到我的pdf中呢?
这是PDFLib在Java中推荐的:
// Place XML stream in a virtual PVF file
String pvf_name = "/pvf/ZUGFeRD-invoice.xml";
byte[] xml_bytes = xml_string.getBytes("UTF-8");
p.create_pvf(pvf_name, xml_bytes, "");
// Create file attachment (asset) from PVF file
int xml_asset = p.load_asset("Attachment", pvf_name,
"mimetype=text/xml description={ZUGFeRD invoice in XML format} "
+ "relationship=Alternative documentattachment=true");
// Associate file attachment with the document
p.end_document("associatedfiles={" + xml_asset + "}");因此,我想,以这个例子为例,并将其适用于perl:
my $xmldata = read_file($xmlfile, binmode => ':utf8'); #I use example xml at the moment
my $pvf_xml = "/pvf/ZUGFeRD-invoice.xml";
PDF_create_pvf($pdf, $pvf_xml, $xmldata, ""); #because no OOP i need to call it this way (works with all other PDF Functions)
my $xml_invoice = PDF_load_asset("Attachment", $pvf_xml, "mimetype=text/xml "
."description={Rechnungsdaten im Zugferd-Xml-Format} "
."relationship=Alternative documentattachment=true");
PDF_end_document($pdf, "associatedfiles={".$xml_invoice."}");在PHP示例中,也不需要在读取xml之后转换为ByteArray。进一步的尝试与解压,但似乎不是问题。
如果我打电话给我的剧本,我就会得到:
用法:load_asset(类型,文件名,optlist);在signatur_test.pl第41行。
我认为问题是pvf_xml之前没有创建过这个行。以前有人这么做过却没有办法解决这个问题?
发布于 2016-11-16 08:43:44
Arg,我只是缺少了load_asset方法中的PDF-句柄:
my $xml_invoice = PDF_load_asset($pdf, "Attachment", $pvf_xml, "mimetype=text/xml "
."description={Rechnungsdaten im Zugferd-Xml-Format} "
."relationship=Alternative documentattachment=true");这样就行了。
https://stackoverflow.com/questions/40626834
复制相似问题