Discussion:
[iText-questions] How to remove XMP Metadata inside Stamper?
Roger Misteli
2005-08-12 11:07:09 UTC
Permalink
Hiyas

In a previous life, I added my XMP metadata using this:

byte[] xmpBuffer = getXMLDocumentAsByteArray();
PdfStream xmp = new PdfStream(xmpBuffer);
xmp.put(PdfName.TYPE, PdfName.METADATA);
xmp.put(PdfName.SUBTYPE, new PdfName("XML"));
PdfIndirectReference ref = writer.addToBody(xmp).getIndirectReference();
writer.getExtraCatalog().put(PdfName.METADATA, ref);

which works very nicely.

Now I have a PDF document that contains PDF Form fields which I want to
fill and flatten and that file contains XMP metadata. I want to remove
that metadata and write my own metadata (using the code above) OR, as
alternative (as better alternative actually), I want to merge the two
XML XMP streams (the old one that already exists plus my new one).

Does anyone know how I can do that?

Best regards and thanks
Rog
bruno
2005-08-12 11:21:02 UTC
Permalink
Post by Roger Misteli
Now I have a PDF document that contains PDF Form fields which I want to
fill and flatten and that file contains XMP metadata. I want to remove
that metadata and write my own metadata (using the code above)
If you have a PdfReader, you can ask for its catalog with getCatalog().
If you change this catalog, these changes will be reflected in the
PdfStamper
that is created with the reader object. (As far as I remember, I could
be wrong.)

So you could remove the metadata like this:
catalog.remove(PdfName.METADATA)
or replace it with other metadata:
catalog.put(PdfName.METADATA, ref)

Catalog is a PdfDictionary and internally all the entries are kept in a
HashMap.
br,
Bruno
Bruno Lowagie
2005-08-13 06:08:05 UTC
Permalink
Hi Bruno
Unfortunately, this didn't solve my problem.
Apparently (I looked into the PDF itself) the PDF I have as template has
more than one XMP Metadata object stored. If I remove(PdfName.METADATA)
I seem to remove, well, one of them. The rest is still there.
I attached the PDF I use as template, maybe I'm overlooking something
here?
My wife has limeted my 'online time' during the long weekend, so I could
only throw a quick look at your file ;-)
I thought you had been adding metadata to the catalog using iText, but
now I see you have a file that was linearized by Adobe Illustrator 10.
XMP Metadata can be added to any PdfDictionary for which it is relevant
to have metadata. In your case, you have several Page Dictionaries that
are referring to an XMP Stream. You can probably retrieve those
dictionaries with PdfReader and remove the metadata entry and the
corresponding object containing the XMP stream, but I can't tell you
from memory how it is done; I don't even know if it's possibe without
making some changes to iText.
br,
Bruno
Paulo Soares
2005-08-13 18:18:24 UTC
Permalink
It's very easy to set/get the XMP metadata, the problem is what to put
there.

----- Original Message -----
From: "Bruno Lowagie" <***@lowagie.com>
To: "Roger Misteli" <***@abacus.ch>
Cc: <itext-***@lists.sourceforge.net>
Sent: Saturday, August 13, 2005 8:39 AM
Subject: Re: [iText-questions] How to remove XMP Metadata inside Stamper?
Post by Bruno Lowagie
Hi Bruno
Unfortunately, this didn't solve my problem.
Apparently (I looked into the PDF itself) the PDF I have as template has
more than one XMP Metadata object stored. If I remove(PdfName.METADATA)
I seem to remove, well, one of them. The rest is still there.
I attached the PDF I use as template, maybe I'm overlooking something
here?
My wife has limeted my 'online time' during the long weekend, so I could
only throw a quick look at your file ;-)
I thought you had been adding metadata to the catalog using iText, but
now I see you have a file that was linearized by Adobe Illustrator 10.
XMP Metadata can be added to any PdfDictionary for which it is relevant
to have metadata. In your case, you have several Page Dictionaries that
are referring to an XMP Stream. You can probably retrieve those
dictionaries with PdfReader and remove the metadata entry and the
corresponding object containing the XMP stream, but I can't tell you
from memory how it is done; I don't even know if it's possibe without
making some changes to iText.
br,
Bruno
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Post by Bruno Lowagie
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
l***@tonybull.com
2005-08-17 07:22:00 UTC
Permalink
Paulo,

It would be very helpful if you could provide examples (as I've not been
able to find any elsewhere) of how easy it is when you say...

"It's very easy to set/get the XMP metadata, the problem is what to put
there."

Thanks!

Tony Bull
bruno
2005-08-30 08:47:14 UTC
Permalink
Post by l***@tonybull.com
Paulo,
It would be very helpful if you could provide examples (as I've not been
able to find any elsewhere) of how easy it is when you say...
"It's very easy to set/get the XMP metadata, the problem is what to put
there."
I have studied the XMP specs and added a simple XmpWriter to CVS.
PdfWriter now has a method addXmpMetadata.
Try it out and let me know if it works.
br,
Bruno
Bruno Lowagie
2005-08-30 09:16:12 UTC
Permalink
Post by bruno
I have studied the XMP specs and added a simple XmpWriter to CVS.
PdfWriter now has a method addXmpMetadata.
Try it out and let me know if it works.
Small sample:
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmpWriter xmp = new XmpWriter(os);
XmpSchema dc = new DublinCoreSchema(XmpSchema.FULL);
dc.setProperty(DublinCoreSchema.SUBJECT,
"<rdf:bag><rdf:li>Hello World</rdf:li>"
+ "<rdf:li>XMP</rdf:li>"
+ "<rdf:li>Metadata</rdf:li></rdf:bag>");
xmp.addRdfDescription(dc);
PdfSchema pdf = new PdfSchema(XmpSchema.SHORTHAND);
pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata");
pdf.setProperty(PdfSchema.VERSION, "1.4");
xmp.addRdfDescription(pdf);
xmp.close();
writer.setXmpMetadata(os.toByteArray());

(Will only work with the CVS version!!!)
Bruno Lowagie
2005-08-30 09:16:15 UTC
Permalink
Post by bruno
I have studied the XMP specs and added a simple XmpWriter to CVS.
PdfWriter now has a method addXmpMetadata.
Try it out and let me know if it works.
Small sample:
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmpWriter xmp = new XmpWriter(os);
XmpSchema dc = new DublinCoreSchema(XmpSchema.FULL);
dc.setProperty(DublinCoreSchema.SUBJECT,
"<rdf:bag><rdf:li>Hello World</rdf:li>"
+ "<rdf:li>XMP</rdf:li>"
+ "<rdf:li>Metadata</rdf:li></rdf:bag>");
xmp.addRdfDescription(dc);
PdfSchema pdf = new PdfSchema(XmpSchema.SHORTHAND);
pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata");
pdf.setProperty(PdfSchema.VERSION, "1.4");
xmp.addRdfDescription(pdf);
xmp.close();
writer.setXmpMetadata(os.toByteArray());

(Will only work with the CVS version!!!)
Leonard Rosenthol
2005-08-30 10:44:11 UTC
Permalink
Post by bruno
I have studied the XMP specs and added a simple XmpWriter to CVS.
Cool!

Also be sure to read the PDF/A specification, specifically
the section concerning the "crosswalk" of XMP to /Info dict.


Leonard

---------------------------------------------------------------------------
Leonard Rosenthol <mailto:***@pdfsages.com>
Chief Technical Officer <http://www.pdfsages.com>
PDF Sages, Inc. 215-938-7080 (voice)
215-938-0880 (fax)
bruno
2005-08-30 11:04:17 UTC
Permalink
Also be sure to read the PDF/A specification, specifically the
section concerning the "crosswalk" of XMP to /Info dict.
Found the crosswalk table.
Trying to figure out what to do with it.

Are you suggesting I should have some
method PdfDocument.generateXmpData()
to be called after adding the metadata?

This method would then automatically
generate XMP with information that
corresponds with the metadata in the
Info dictionary.

That way you wouldn't have to care
about the XML. It would be generated
behind the screens...
Would that be a good idea?
br,
Bruno
Leonard Rosenthol
2005-08-30 11:20:09 UTC
Permalink
Post by bruno
Are you suggesting I should have some
method PdfDocument.generateXmpData()
to be called after adding the metadata?
As an ALTERNATIVE to users having to understand the details
of XMP - yes!
Post by bruno
This method would then automatically
generate XMP with information that
corresponds with the metadata in the
Info dictionary.
Exactly!
Post by bruno
That way you wouldn't have to care
about the XML. It would be generated
behind the screens...
Would that be a good idea?
For the average user of iText - YES! AND it would be a
nice marketing tool for iText, since it would make it only the THIRD
program to support this.


Leonard

---------------------------------------------------------------------------
Leonard Rosenthol <mailto:***@pdfsages.com>
Chief Technical Officer <http://www.pdfsages.com>
PDF Sages, Inc. 215-938-7080 (voice)
215-938-0880 (fax)
bruno
2005-08-30 13:16:11 UTC
Permalink
Post by bruno
That way you wouldn't have to care
about the XML. It would be generated
behind the screens...
Would that be a good idea?
For the average user of iText - YES! AND it would be a nice
marketing tool for iText, since it would make it only the THIRD
program to support this.
Done. See the CVS repository.

Code snippet:
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(filename));
document.addTitle("Hello World example");
document.addSubject("This example shows how to add metadata");
document.addKeywords("Metadata, iText, step 3");
document.addCreator("My program using iText");
document.addAuthor("Bruno Lowagie");
writer.createXmpMetadata();
Leonard Rosenthol
2005-08-30 13:28:08 UTC
Permalink
Post by bruno
Post by Leonard Rosenthol
For the average user of iText - YES! AND it would be a
nice marketing tool for iText, since it would make it only the
THIRD program to support this.
Done. See the CVS repository.
VERY COOL!!

Nice job - and thanks!


Leonard

---------------------------------------------------------------------------
Leonard Rosenthol <mailto:***@pdfsages.com>
Chief Technical Officer <http://www.pdfsages.com>
PDF Sages, Inc. 215-938-7080 (voice)
215-938-0880 (fax)
Paulo Soares
2005-08-17 07:50:11 UTC
Permalink
There are examples in the mailing list to get/set the metadata in the
catalog and for other objects it's the same.
-----Original Message-----
Sent: Wednesday, August 17, 2005 10:21 AM
Subject: Re: [iText-questions] How to remove XMP Metadata
inside Stamper?
Paulo,
It would be very helpful if you could provide examples (as
I've not been
able to find any elsewhere) of how easy it is when you say...
"It's very easy to set/get the XMP metadata, the problem is
what to put
there."
Thanks!
Tony Bull
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development
Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams *
Testing & QA
Security * Process Improvement & Measurement *
http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
Paulo Soares
2005-08-30 13:28:10 UTC
Permalink
PdfDate.W3C cant't be static or if it is must be synchronized.

Best Regards,
Paulo Soares
-----Original Message-----
Behalf Of bruno
Sent: Tuesday, August 30, 2005 4:12 PM
To: Leonard Rosenthol
Subject: Re: [iText-questions] How to remove XMP Metadata
inside Stamper?
Post by Leonard Rosenthol
Post by bruno
That way you wouldn't have to care
about the XML. It would be generated
behind the screens...
Would that be a good idea?
For the average user of iText - YES! AND it would
be a nice
Post by Leonard Rosenthol
marketing tool for iText, since it would make it only the THIRD
program to support this.
Done. See the CVS repository.
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(filename));
document.addTitle("Hello World example");
document.addSubject("This example shows how to add metadata");
document.addKeywords("Metadata, iText, step 3");
document.addCreator("My program using iText");
document.addAuthor("Bruno Lowagie");
writer.createXmpMetadata();
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development
Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams *
Testing & QA
Security * Process Improvement & Measurement *
http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
Bruno Lowagie
2005-08-30 14:40:07 UTC
Permalink
Post by Paulo Soares
PdfDate.W3C cant't be static or if it is must be synchronized.
OK, fixed it in the CVS.
br,
Bruno

Loading...