I'm trying to read a specific property from a Word file with GemBox.Document, but in some cases, it might not be in the document, so I get an error.
var document = DocumentModel.Load("ovl-last.docx");
var documentProperties = document.DocumentProperties;
var ovldoctype = documentProperties.Custom["DocType"];
In the Document Properties example, I noticed that we can iterate through the properties. Is this the only "safe" way to get a property and prevent an exception, or is there another way to check its existence?
Also, when I save the DocumentModel to PDF I noticed that I get a hard-coded "GemBox.Document XYZ" value for the "PDF Producer" property. I can see it in: Adobe Reader -> File -> Properties... -> Advanced -> PDF Producer
Can I change this to something else?
Note that both
DocumentProperties.BuiltInandDocumentProperties.Customare dictionaries, so you can either useTryGetValueto try retrieving the "DocType" value or useContainsKeymethod to check if the "DocType" key exists.For instance, something like this:
Or this:
Regarding the "PDF Producer", try adding the "Producer" property: