Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 2 years ago.
i searching for methods or libarys to edit metadata of a pdf file like the programm becypdfmetaedit.
I want to write a program and i need this opton in this program.
Perhaps you have some samples for c#.
Thanks
Using PDF Sharp works like this:
using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main (string[] args)
{
Program p = new Program();
p.Test();
}
public void Test ()
{
PdfDocument document = PdfReader.Open ("Test.pdf");
document.Info.Author = "ME";
document.Save ("Result");
}
}
}
For PDFSharp:
If you would like to change/add the metadata on the Custom Properties of a PDF you can use the PdfDocument.Info.Elements object.
String filename = @"d:\temp\Hugo-input.pdf";
String outputfile = @"d:\temp\Hugo-output.pdf";
PdfDocument document = PdfReader.Open(filename);
document.Info.Elements.Add(new KeyValuePair<String,PdfItem>("/MyKey",new PdfString("MyValue")));
document.Save(outputfile);
Always start a custom key with a slash!
You can find the key and value when you open this document in Adobe Acrobat Reader -> File -> Properties -> Custom.
This works with PDFSharp 1.32
I suppose you can do it with iTextSharp.
Does the PdfDocumentInformation class from PDF Sharp fulfill your requirements.
Pimping here - my company, Atalasoft, makes .NET components for working with images. Part of the suite includes the ability to read/write PDF document metadata. It's not free, but it is run-time royalty free for desktop applications.
The code for reading is simple:
PdfDocumentMetadata metadata = PdfDocumentMetadata.FromStream(sourceStream);
to edit it and write it back to the same stream:
meta.Title = "Knicholas Knickleby";
meta.Author = "Edmund Wells";
sourceStream.Seek(0, SeekOrigin.Begin);
meta.Append(sourceStream, false); // false means don't merge - overwrite
Custom fields are supported through a hashtable.
Aspose.PDF or Aspose.PDF.Kit can do this for you.
Docotic.Pdf library can be used to read and update metadata in PDF documents.
There is PdfDocument.Info
property that can be used to change metadata of a PDF document (properties such as "Author", "Title").
And there is also PdfDocument.Metadata
property that is useful if you need to access embedded XMP metadata in a PDF document. The library supports pre-defined XMP schemas and can also be used to set custom application-defined properties.
The library is free for non-commercial applications. (The library is no longer free since the 15th of February 2012)
Disclaimer: I work for the company.