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.
CodePudding user response:
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");
}
}
}
CodePudding user response:
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.