[Best Practics] How i can update/overwrite all document metadata like author or subject?

Hello Support

i want to know what are the best practices to handle the document metadatas in writing new values? I know that is possible with the following code

`
var docInfo = pdfDoc.GetDocInfo();

docInfo.SetTitle(“my title”);
docInfo.SetAuthor(“my name”);

`

I try this way to overwrite the metadata in a example document (PDF Reference from Adobe) which includes some metadatas. After this i have a problem to view the new settings in different pdf viewers.
In Adobe Acrobat it works fine but in example the PDF X Change Viewer from Tracker Software works in correct. The viewer show the keywords correctly but the author or title were the old values. I try to erase some
metadatas from trailer

`

pdfDoc.GetTrailer().Erase("Info");

`

to clear all values but it has no effect on overwriting metadatas.

So the questions is how i can erase some old information’s and put on all places in the document the correct metadatas to view correctly in in the most of pdf viewers?

Regards

Daniel

The problem is that a PDF doc may also contain XML (i.e. XMP) metadata (use CosEdit http://www.pdftron.com/pdfcosedit/downloads.html - to find it under Metadata in doc catalog).

Frequently XMP metadata is out of sync with information in document catalog (i.e. pdfdoc.GetDocInfo()).
Unfortunately PDF consumers frequently choose very different strategies to visualize metadata :frowning:

One way to get consistent behavior is to remove the XMP stream:
doc.GetRoot().Erase(“Metadata”);

Another option could be to edit (or sync) XMP stream:

Edit XMP metadata: https://groups.google.com/d/msg/pdfnet-sdk/Mztv51jDpTo/5SIBwcTYmPIJ
In summary you would load XML blob, edit it, then replace the original blob.

Thank you for answering the question. After update the code with doc.GetRoot().Erase(“Metadata”); it work better and correctly!
Am Donnerstag, 8. Mai 2014 21:09:05 UTC+2 schrieb Support:

The problem is that a PDF doc may also contain XML (i.e. XMP) metadata (use CosEdit http://www.pdftron.com/pdfcosedit/downloads.html - to find it under Metadata in doc catalog).

Frequently XMP metadata is out of sync with information in document catalog (i.e. pdfdoc.GetDocInfo()).
Unfortunately PDF consumers frequently choose very different strategies to visualize metadata :frowning:

One way to get consistent behavior is to remove the XMP stream:
doc.GetRoot().Erase(“Metadata”);

Another option could be to edit (or sync) XMP stream:

Edit XMP metadata: https://groups.google.com/d/msg/pdfnet-sdk/Mztv51jDpTo/5SIBwcTYmPIJ
In summary you would load XML blob, edit it, then replace the original blob.

On Thursday, May 8, 2014 12:25:40 AM UTC-7, Daniel Lutz wrote:

Hello Support

i want to know what are the best practices to handle the document metadatas in writing new values? I know that is possible with the following code

`
var docInfo = pdfDoc.GetDocInfo();

docInfo.SetTitle(“my title”);
docInfo.SetAuthor(“my name”);

`

I try this way to overwrite the metadata in a example document (PDF Reference from Adobe) which includes some metadatas. After this i have a problem to view the new settings in different pdf viewers.
In Adobe Acrobat it works fine but in example the PDF X Change Viewer from Tracker Software works in correct. The viewer show the keywords correctly but the author or title were the old values. I try to erase some
metadatas from trailer

`

pdfDoc.GetTrailer().Erase("Info");

`

to clear all values but it has no effect on overwriting metadatas.

So the questions is how i can erase some old information’s and put on all places in the document the correct metadatas to view correctly in in the most of pdf viewers?

Regards

Daniel