New Forum | Previous | Next | (P-PDF) Developers
Topic: How modify a pdf file with a xmp stream
Conf: (P-PDF) Developers, Msg: 132880
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
.... 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 ...