Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit Metadata of PDF File with C# [closed]

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

like image 521
subprime Avatar asked Sep 23 '09 11:09

subprime


People also ask

Can you modify PDF metadata?

Choose File > Properties, click the Description tab, and then click Additional Metadata. Select Advanced from the list on the left. To edit the metadata, do any of the following, and then click OK. To add previously saved information, click Append, select an XMP or FFO file, and click Open.


3 Answers

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");
    }
  }

}

like image 86
crauscher Avatar answered Oct 24 '22 15:10

crauscher


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

like image 39
Hugo Geijteman Avatar answered Oct 24 '22 14:10

Hugo Geijteman


I suppose you can do it with iTextSharp.

like image 32
Carles Company Avatar answered Oct 24 '22 13:10

Carles Company