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

122 views
Skip to first unread message

Daniel Lutz

unread,
May 8, 2014, 3:25:40 AM5/8/14
to pdfne...@googlegroups.com
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

Support

unread,
May 8, 2014, 3:09:05 PM5/8/14
to pdfne...@googlegroups.com

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 :(

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:

In summary you would load XML blob, edit it, then replace the original blob.

Daniel Lutz

unread,
May 9, 2014, 2:09:16 AM5/9/14
to pdfne...@googlegroups.com
Thank you for answering the question. After update the code with doc.GetRoot().Erase("Metadata"); it work better and correctly!
Reply all
Reply to author
Forward
0 new messages