Hi,
I need to set the whole XMP block in a PDF. I don’t want to set individual fields because that is already handled. There is a method to get the XMP in Aspose.Pdf.Facades.PdfXmpMetadata but I cannot se any way to set it. Have I missed something?
Thanks
Anders Bergman
Hi Anders,
Thanks for your inquiry. I am afraid I am not clear with your requirement. We will appreciate it if you please share some more details about the requirements. Which values and fields you want to set as whole? It will help us to understand the requirements.
Best Regards,
When I want to extract the full XMP block from a PDF file I have this code:
Aspose.Pdf.Document adoc = new Aspose.Pdf.Document(sourcePath);
Aspose.Pdf.Facades.PdfXmpMetadata xmp = new Aspose.Pdf.Facades.PdfXmpMetadata();
xmp.BindPdf(adoc);
byte[] xmpblock = xmp.GetXmpMetadata();
_createTextFile(xmpPath, System.Text.Encoding.UTF8.GetString(xmpblock));
Our system then processes the XMP data and it should be written back to the PDF file.
What we need is something like this:
Aspose.Pdf.Document adoc = new Aspose.Pdf.Document(sourcePath);
byte[] xmpblock = = _readXMPData(xmpPath)
// The constructor takes a byte array containing XMP data
Aspose.Pdf.Facades.PdfXmpMetadata xmp = new Aspose.Pdf.Facades.PdfXmpMetadata(xmpblock);
xmp.BindPdf(adoc);
xmp.save(sourcePath);
Or using the Pdf.Metadata class:
Aspose.Pdf.Document adoc = new Aspose.Pdf.Document(sourcePath);
byte[] xmpblock = = _readXMPData(xmpPath);
// A Set method would solve my problem
adoc.Metadata.Set(xmpblock);
Hi Anders,
Thanks for providing additional information. We have logged a new feature request PDFNEWNET-38167 for your requirements in our issue tracking system. We will notify you as soon as it is implemented.
We are sorry for the inconvenience caused.
Best Regards,
Hello,
I am using the latest Aspose.PDF for .NET 25.2 and I have encountered the method Aspose.Pdf.Document.SetXmpMetadata(stream). But it seems, it does not work as expected, the inserted block is beeing saved at the beginning of the file like so:
%PDF-1.7
%ÈÈÈÈÈÈÈ
%
69 0 obj
<</Length 2763>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">
...
</rdf:RDF></x:xmpmeta><?xpacket end="w"?>
endstream
endobj
...
And not like this at the end of the document:
...
endobj
260 0 obj
<</Length 4175/Type/Metadata/Subtype/XML>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
...
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="r"?>
...
Am I using this method wrong, or is it intended for another use? As the original post states, I would like to set the whole XMP block.
@daniel.castilla
Could you please share your sample code snippet along with sample input/output files? We need to test the scenario in our environment to address it accordingly.
The main problem is actually that the pdf obj block
<</Length 2760>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
should actually be:
<</Length 2760/Type/Metadata/Subtype/XML>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
to be recognized as the XMP Metadata. Also, if I convert the document after setting the XMP block to PDF/A it does not get recognized as PDF/A Standard (using doc.Convert()).
I guess, if the block gets written to the beginning of the file or the end of the file is not that important. Here are my sample files:
test-input.pdf (93,3 KB)
test-output.pdf (94,5 KB)
Here is my code:
using (var doc = new Document(input))
{
var stream = new MemoryStream();
byte[] contentBytes = Encoding.UTF8.GetBytes(xmlContent);
stream.Write(contentBytes, 0, contentBytes.Length);
stream.Position = 0;
doc.SetXmpMetadata(stream);
//optional converting: Does not get recognized as PDF/A Standard
var options = new PdfFormatConversionOptions(errorStream, PdfFormat.PDF_A_3B, ConvertErrorAction.None)
{
OptimizeFileSize = true,
ExcludeFontsStrategy = RemoveFontsStrategy.SubsetFonts | RemoveFontsStrategy.RemoveDuplicatedFonts
};
doc.Convert(options);
//save
doc.Save(output);
}
@Andy101
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-59857
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you have found earlier (filed as PDFNET-59857) have been fixed in Aspose.PDF for .NET 25.8.