我需要讀取和寫入PDF/A文件的XMP元數據。在PDF/A文檔中讀取和寫入xml元數據
我使用的是itextsharp 7,並嘗試了幾種方法來實現我的目標,但沒有取得太大的成功。像control:Anzahl_Zeichen_Titel
這樣的字段是我的目標。 下面的代碼應該做的工作,但我不明白究竟如何。
PdfADocument pdfADocument = new PdfADocument(new PdfReader(Vorlage), new PdfWriter(Ausgabe), new StampingProperties());
XMPMeta xmpMeta = XMPMetaFactory.ParseFromBuffer(pdfADocument.GetXmpMetadata());
XMPProperty test1 = xmpMeta.GetProperty("ftx:ControlData", "control:Anzahl_Zeichen_Vorname");
XMPProperty test2 = xmpMeta.GetProperty("http://www.aiim.org/pdfa/ns/schema#", "ControlData");
當我使用test1版本時,它顯示了一個XMPException「未註冊模式名稱空間URI」。 第二個似乎工作,但test2變量爲空。
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c015 84.159810, 2016/09/10-02:41:30 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/"
xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#"
xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#"
xmlns:pdfaType="http://www.aiim.org/pdfa/ns/type#"
xmlns:pdfaField="http://www.aiim.org/pdfa/ns/field#"
xmlns:ftx="http://ns.ftx.com/forms/1.0/"
xmlns:control="http://ns.ftx.com/forms/1.0/controldata/">
<xmp:CreatorTool>QuarkXPress(R) 8.12</xmp:CreatorTool>
<xmp:CreateDate>2017-03-14T08:56:49+01:00</xmp:CreateDate>
<xmp:ModifyDate>2017-04-11T14:35:21+02:00</xmp:ModifyDate>
<xmp:MetadataDate>2017-04-11T14:35:21+02:00</xmp:MetadataDate>
<dc:format>application/pdf</dc:format>
<!-- snip -->
<ftx:ControlData rdf:parseType="Resource">
<control:Anzahl_Zeichen_Titel>0</control:Anzahl_Zeichen_Titel>
<control:Anzahl_Zeichen_Vorname>0</control:Anzahl_Zeichen_Vorname>
<control:Anzahl_Zeichen_Namenszusatz>0</control:Anzahl_Zeichen_Namenszusatz>
<control:Anzahl_Zeichen_Hausnummer>0</control:Anzahl_Zeichen_Hausnummer>
<control:Anzahl_Zeichen_Postleitzahl>0</control:Anzahl_Zeichen_Postleitzahl>
<control:Anzahl_Zeichen_Wohnsitzlaendercode>0</control:Anzahl_Zeichen_Wohnsitzlaendercode>
<control:Auftragsnummer_Einsender>0</control:Auftragsnummer_Einsender>
<control:Formularnummer>10</control:Formularnummer>
<control:Formularversion>07.2017</control:Formularversion>
</ftx:ControlData>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
如何使用這些方法來創建和讀取有效數據?
這只是部分可用。 itext和itextsharp之間有區別。如果沒有適當的命名空間,GetProperty不起作用。它不能爲空或空字符串。但第一個版本更進一步。當我查看數據結構時,它會返回我需要的值。 – Booser
但它沒有任何訪問它們的方法。我正在用不同的方法來獲得最終的價值。 'control:Formularnummer'等等。他們不能像所顯示的那樣閱讀。 'xmpMeta.DoesPropertyExist(「http://ns.ftx.com/forms/1.0/controldata/」,「control:Formularnummer」);'說不。 – Booser