Hi there,
I’m already doing some exercises with the demo version of Aspose.PDF for .NET, I find it pretty easy an understandable. But now, I’m a little bit confused of working with the XMPMetata model. I want to do the following:
1.) Load an existing PDF
2.) Add default and custom Metadata (doc.Metadata ???)
3.) Convert into PDF/A (validate, convert)
4.) Save it again (save)
I’m using the simple Document Object, but I can’t find the class for the XMP stuff… Or do I have to load a specific stylesheet for my custom Metadata? I’ve heard of this, but not according to Aspose…
Maybe you could give me the key which I don’t see… Would be perfect!
Thanks a lot
Anika
Hi Anika,
Thank you for considering Aspose.PDF.
Both Aspose.PDF DOM and Aspose.Pdf.Facades supports working with XMP Matadata in an existing PDF file. Please see the following documentation links with details and sample code.
Aspose.PDF DOM
Aspose.Pdf.Facades
- Set XMP Metadata in an Existing PDF File (Facades)
- Get XMP Metadata from an Existing PDF File (Facades)
In case you need any further assistance, please feel free to contact support.
Thank You & Best Regards,
Hello Nausherwan Aslam,
thanks for your quick reply.
I used the setting method as described in your example, but I still don’t get the expected result. In the generated log.xml are some errors which I don’t understand properly:
E.g.:
"Document information entry ‘Creator’ not synchronized with metadata property ‘xmp:CreatorTool’“
or
"Required property ‘pdfaid:part’ for schema ‘pdfaid’ missing” - can you give me a hint, how I can solve that? I guess those errors are the reason, that my xmp metadata are not set in the PDF.
Last general question: The XMP metadata are shown in the properties of the generated PDF, or? The custom metadata are usually shown in the advanced tab?! So I don’t need to write an extra application, that reads out the set metadata - I could see them directly in the new file?!
Thanks a lot for your support!
Kind regards
Anika
Hi Anika,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for the details.
E.g.:
"Document information entry 'Creator' not synchronized with metadata
property 'xmp:CreatorTool'"
or
"Required property 'pdfaid:part' for schema 'pdfaid' missing" - can
you give me a hint, how I can solve that? I guess those errors are the reason,
that my xmp metadata are not set in the PDF.
I used the following sample code and it does produce the errors in the log as your mentioned. However, as the log tag “Convertible” against these items is true that means these items are converted to PDF/A. I checked my generated PDF/A file and it does show the properties under Document PropertiesàAdditional Metadataà Advanced. Also, you cannot change the “CreatorTool” value and it will remain “Aspose Ltd.”
//open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("Test.pdf");
//set properties
pdfDocument.Metadata["xmp:Nickname"] = "Nickname";
pdfDocument.Metadata["xmp:CreatorTool"] = "Test Value";
pdfDocument.Metadata["xmp:CustomProperty"] = "Custom Value";
//Convert to PDF/A compliant document
pdfDocument.Validate("log.xml", PdfFormat.PDF_A_1A);
pdfDocument.Convert("log.xml", PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
//save output document
pdfDocument.Save("output_XMP.pdf");
Please share your sample code and template PDF file with us, so we can test your issue and identify the cause of the issue soon.
Last general question: The XMP metadata are shown in the properties of the
generated PDF, or? The custom metadata are usually shown in the advanced tab?!
So I don't need to write an extra application, that reads out the set metadata
- I could see them directly in the new file?!
XMP properties are available under Document PropertiesàAdditional Metadataà Advanced.
Please feel free to contact support in case you need any further assistance.
Sorry for the inconvenience,
Hi,
thanks for your example.
I do it quite similar, only in VB.NET. Here is my code:
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:DoNotShowComments/>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>DE</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val=“–”/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–>
'open document
Dim pdfdoc As New Document("C:\Dokumente und Einstellungen\delzeita\Desktop\Testdokument.pdf")
'set properties
pdfdoc.Metadata("xmp:Nickname") = "Nickname"
pdfdoc.Metadata("xmp:CustomProperty") = "Custom Value"
'Convert to PDF/A compliant document
pdfdoc.Validate("C:\Dokumente und Einstellungen\delzeita\Desktop\log.xml", PdfFormat.PDF_A_1A)
pdfdoc.Convert("C:\Dokumente und Einstellungen\delzeita\Desktop\log.xml", PdfFormat.PDF_A_1A, ConvertErrorAction.Delete)
pdfdoc.Metadata("pdf:Keywords") = "Test, XMP, PDF, PDF_A"
pdfdoc.Metadata("dc:title") = "Mein Testdokument"
'save output document
<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;mso-ansi-language:DE;mso-fareast-language:DE;mso-bidi-language:
AR-SA;mso-no-proof:yes”>pdfdoc.Save(“C:\Dokumente
und Einstellungen\delzeita\Desktop\output_XMP.pdf”)<!–[if gte mso 10]>
<![endif]–>
I only see the pdf-Metadata “Keywords” afterwards. I can’t find the custom metadata in the properties of the document. Do I have to define it in advance with a namespace and so on to be able to set a value to it?
Also the dc-Metadata is not there after generating the PDF.
Maybe I still have a little understanding problem according to the work with XMP metadata on the PDF …
Kind regards
Anika
Hi Anika,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for sharing the template file and sample code.
I tested your issue with the latest version of Aspose.Pdf for .NET v7.4 and I am unable to reproduce your issue. Please see the attached resultant file for reference. It shows the XMP properties as shown in the screenshot attached. If you are using some older version of Aspose.Pdf for .NET, please download and try the latest version and let us know if it works fine for you.
Sorry for the inconvenience,
Thanks a lot - I have found my mistake - I used only the AdobeReader and tried to find the custom metadata stupid. I tried it now with Adobe Acrobat and everything is fine (I guess it was from the beginning) :).
Hi Anika,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for the feedback and confirmation regarding the resolution of your issue. Please feel free to contact support in case you need any further assistance.
Thank You & Best Regards,
Hi there,
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(pdfPath)
pdf.Convert(temptext, PdfFormat.PDF_A_1A, ConvertErrorAction.Delete)
pdf.Metadata[“xmp:CreatorTool”] = “TestCreatorTool”;
pdf.Save(pdfPath);
In the code itself I see that the metadata has changed. Yet when I open the PDF file in Adobe Acrobat, I can still see the old metadata. Any idea how to fix this?
Kind regards,
Subhash
Hi Subhash,