Modify Meta Data using PdfStamper

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Modify Meta Data using PdfStamper

Sam  Collett
How do you modify meta data on an existing document? I understand you have to create a PdfStamper to modify fields, but how to you then edit the title, author etc (without creating a new document)

I have tried:

MemoryStream m = new MemoryStream();
string file = "c:\path\to\file.pdf";
PdfReader reader = new PdfReader(file);
PdfStamper stamper = new PdfStamper(reader, m);
Hashtable info = stamper.MoreInfo;
info["Title"] = "New Title";


However stamper.MoreInfo is null, even though the existing document does have meta data.
Reply | Threaded
Open this post in threaded view
|

RE: Modify Meta Data using PdfStamper

Paulo Soares
You must always create a new document. The correct use is:

MemoryStream m = new MemoryStream();
string file = "c:\path\to\file.pdf";
PdfReader reader = new PdfReader(file);
PdfStamper stamper = new PdfStamper(reader, m);
Hashtable info = new Hashtable();
info["Title"] = "New Title";
stamper.MoreInfo = info;

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On
> Behalf Of Sam Collett
> Sent: Wednesday, September 28, 2005 11:45 AM
> To: [hidden email]
> Subject: [itextsharp-questions] Modify Meta Data using PdfStamper
>
> How do you modify meta data on an existing document? I
> understand you have to create a PdfStamper to modify fields,
> but how to you then edit the title, author etc (without
> creating a new document)
>
> I have tried:
>
> MemoryStream m = new MemoryStream();
> string file = "c:\path\to\file.pdf";
> PdfReader reader = new PdfReader(file);
> PdfStamper stamper = new PdfStamper(reader, m);
> Hashtable info = stamper.MoreInfo;
> info["Title"] = "New Title";
>
>
> However stamper.MoreInfo is null, even though the existing
> document does have meta data.
>
>


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Reply | Threaded
Open this post in threaded view
|

Re: Modify Meta Data using PdfStamper

Sam  Collett
Didn't think it would be that simple. Thanks for the quick response. Can you read existing data (from the PdfReader object), or do you have to set all of the meta data (i.e. you may just want to change author)?

Very good tool you have by the way.

On 28/09/05, Paulo Soares <[hidden email]> wrote:
You must always create a new document. The correct use is:

MemoryStream m = new MemoryStream();
string file = "c:\path\to\file.pdf";
PdfReader reader = new PdfReader(file);
PdfStamper stamper = new PdfStamper(reader, m);
Hashtable info = new Hashtable();
info["Title"] = "New Title";
stamper.MoreInfo = info;

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On
> Behalf Of Sam Collett
> Sent: Wednesday, September 28, 2005 11:45 AM
> To: [hidden email]
> Subject: [itextsharp-questions] Modify Meta Data using PdfStamper
>
> How do you modify meta data on an existing document? I
> understand you have to create a PdfStamper to modify fields,
> but how to you then edit the title, author etc (without
> creating a new document)
>
> I have tried:
>
> MemoryStream m = new MemoryStream();
> string file = "c:\path\to\file.pdf";
> PdfReader reader = new PdfReader(file);
> PdfStamper stamper = new PdfStamper(reader, m);
> Hashtable info = stamper.MoreInfo;
> info["Title"] = "New Title";
>
>
> However stamper.MoreInfo is null, even though the existing
> document does have meta data.
>
>