简体   繁体   中英

How to add custom property/metadata to PDF 2.0 file

I am trying to add custom property/metadata to PDF 2.0 file (like this customprop ). I have used PDFSharp, ITextSharp and PDFBox but I couldn't. Is there any free package that can fix the problem.

link for sample pdf 2.0

Have you tried SpirePDF? There is a free Nuget that you can try, it worked fine for me with that snippet:

using Spire.Pdf;

namespace App
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"C:\Users\User\Downloads\output.pdf");
            doc.DocumentInformation.SetCustomProperty("Name", "Test");
            doc.DocumentInformation.SetCustomProperty("Company", "StackOverflow");
            doc.SaveToFile(@"C:\Users\User\Downloads\result.pdf");
        }
    }
}

You can add custom metadata using Docotic.Pdf library like that:

// NOTE: 
// When used in trial mode, the library imposes some restrictions.
// Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx for more information.
BitMiracle.Docotic.LicenseManager.AddLicenseData("temporary or permanent license key here");

using (var pdf = new PdfDocument("Simple_pdf_2.0_file.pdf"))
{
    pdf.Metadata.Custom.Properties.Add("CustomKey", "CustomValue");

    pdf.Save("SetCustomXmpProperties.pdf");
}

Here is the more comprehensive sample: https://github.com/BitMiracle/Docotic.Pdf.Samples/tree/master/Samples/Metadata/SetCustomXmpProperties

Disclaimer: I am the co-author of Docotic.Pdf library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM