Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).

New Forum | Previous | Next | (P-PDF) Developers

Topic: How modify a pdf file with a xmp stream
Conf: (P-PDF) Developers, Msg: 132880
From: ibarm
Date: 5/17/2005 07:12 PM

I am a new bee on pdf file manipulation, i did not read all the pdf spec, sorry, and i am trying to make a short library in python to insert and extract XMP metadata from pdf files.
When i insert xmp metadata, there's no problem to read it but some tools said me that my file is corrupted and i have to apply a repair tool in order to obtain a valid pdf, what is work, after this repair i have a valid pdf with my new xmp metadata. So i think i forgot something in my file manipulation .....
How i manipulate my pdf file:
1/ I look for a trailer dict, i search a dict inside the pdf file similar with :
<< .... /Root NUM NUM R .... /Size NUM >> (Root and Size could be inverted)
If i find more than one, i take the last on in the file (i understood that pdf are incremental by the end, so ...)
2/ I change the size to size+1 (my future new xmp stream)
3/ I take the Root dict object with the number found in the trailer (if there more than one dict, i take the last, same reason than the trailer)
4/ I look for a metadata entry inside the Root dict ("/Metadata NUM NUM R")
5/ if found one metadata entry i replace it with my new metadata object number, calculate from the size in the trailer, or i create one entry if there's no metadata:
/Metadata SizeFromTrailer 0 R
5 bis/ If i want to extract the xmp, i use the metadata entry found to extract the metadata stream at this point and return it
6/ I create my stream ready to be insert:
SizeFromTrailer 0 obj
<</Type /Metadata
/Subtype /XML
/Length CalculateLength>>
.... my xmp stream ....
7/ I insert my new stream just before the root object i worked with
8/ i save all inside a new file

It is what i made, but now, can someone tell me what i have to do in order to make a valid pdf file
- Is my method correct, or what i forgot ??
- I have to modify some xref table entries, no ?? how ???
- Is there any file marker like md5 entry in the pdf file or other validation entry i have to modify ???

Please, if someone could help it will be very useful because i think i am not so far from what i want ...


PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.