Michael,

Thanks for your help tracking this down.  This is a follow-up to explain how I 
resolved this problem.

As you noted, the metadata in my source document does not contain the 
<x:xmpmeta> elements that iText expects.  Adobe's XMP spec 
(http://www.adobe.com/devnet/xmp/pdfs/xmp_specification.pdf) says:

    Page 21:
      "The outermost XML element is optionally an x:xmpmeta element, which 
contains a single rdf:RDF element (or the rdf:RDF element can be outermost)."

    Page 22:
      "It is recommended that an x:xmpmeta element be the outermost XML element 
in the serialized XMP data,"

These tags are officially optional, so I think my documents are technically 
"valid", and iText's handling of the metadata is incorrect.

For a workaround, I have found that I can clean up the document by directly 
injecting the opening and closing tags.  Here are the BEFORE and AFTER shots:

  BEFORE:
  <?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='770'?>
  <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
      xmlns:iX='http://ns.adobe.com/iX/1.0/'>
    [...]
  </rdf:RDF>
  <?xpacket end='r'?>

  AFTER (the only difference is the xmpmeta open and close tags):
  <?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='770'?>
  <x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF 
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
      xmlns:iX='http://ns.adobe.com/iX/1.0/'>
    [...]
  </rdf:RDF></x:xmpmeta>
  <?xpacket end='r'?>

With this cleanup, I can read and write the file multiple times without any 
error, and the metadata is preserved from one version to another.

For the record, before I found this solution I was still seeing the error 
message even with iText-5.0.3.  The difference in displaying this error must be 
dependent on the Java version or something like that (I'm using Java 1.6.0_18).

 Thanks again,
-Chip Whitmer

-----Original Message-----
From: mkl [mailto:[email protected]] 
Sent: Thursday, July 29, 2010 1:16 AM
To: [email protected]
Subject: Re: [iText-questions] PdfStamper error: Premature end of file


Chip,

Chip Whitmer-2 wrote:
> If I understand you correctly, my original document may be incorrect,
> because it doesn't include the <x:xmpmeta> elements that iText expects.  I
> receive these documents from an external source, so I don't control their
> construction.

More exactly, I don't know whether your the metadata stream of your document
or iText is incorrect (you could check by comparing with the appropriate
documentation available on the Adobe web site).

I think, though, that the approach of iText looks quite harsh: First it
parses the existing metadata and manipulates them, not caring about the very
structure, but when it writes the data back it suddenly makes assumptions
concerning the structure. Maybe those assumptions are well-founded by the
specs, but as they can result in information loss as in your case, they
aren't good style.

Chip Whitmer-2 wrote:
> Can someone recommend a workaround of some kind?  Can I use PdfStamper to
> clean up the original file?  What would make the file "correct"?

Update iText --- as mentioned, I don't see your error output when running
your code with iText trunk.

Regards,   Michael.
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/PdfStamper-error-Premature-end-of-file-tp2304334p2306048.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to