Search code examples
c#pdfgembox-document

Edit file properties in PDF with GemBox.Document


How can we modify all properties in PDF file?
I've seen the document properties example and ended up with this:

DocumentModel document = DocumentModel.Load("Input.docx");

document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Application] = "My Application";
document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Title] = "My Title";
document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Author] = "My Author";
// Etc ...

document.Save("Output.pdf");

But some properties are missing, for instance there is no Producer and Creator enums in BuiltInDocumentProperty. Am I missing something?


Solution

  • The BuiltInDocumentProperty enums are based on Word documents, but nevertheless try the following example:

    // The "BuiltInDocumentProperty.Application" is the PDF's "Creator" property.
    // If you're experiencing an issue with it, try downloading the latest bug fix version:
    // https://www.gemboxsoftware.com/document/downloads/BugFixes.htm
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Application] = "My Application";
    
    // The PDF's "Producer" property is missing, but you can use the following:
    document.DocumentProperties.Custom.Add("Producer", "My Producer");
    
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Title] = "My Title";
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Author] = "My Author";
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Subject] = "My Subject";
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.Keywords] = "My Keywords";
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.DateContentCreated] =
        new DateTime(2000, 1, 1).ToString("s") + "Z";
    document.DocumentProperties.BuiltIn[BuiltInDocumentProperty.DateLastSaved] =
        new DateTime(2000, 1, 1).ToString("s") + "Z";
    

    I hope this helps.