开发者

Edit or remove PDF header information in C

I need to edit the header information of several PDF files. What I'd like to achieve is to remove all header data before %PDF-X.Y.Z.

What I came up with as a possible solution was to open the PDF in binary mode, read each character until %PDF-X.Y.Z is found. Then continue reading the rest of the stream and save it to a new file. I thought this way I will end up with an exact binary copy of the PDF, just with different header information.

What's the easiest/best way 开发者_JS百科to do this in C? Are there any libraries available that could help me do this? I'm also interested in hearing different approaches to solve this problem.

Thanks.


Actually you can trow away all information before %PDF tag, BUT you make xref table at the end of file invalid. This table contains offset references to PDF objects.

Easiest way was: remove the part before %PDF and count, how much you trow away, reduce values in xref according.


Assuming that stripping the beginning of the file really does solve your problem, all you need are fopen, fread, fwrite and fclose.

You open the file for reading in binary mode. Read up until you find the magic %PDF string. Open the output file for binary writing. Write out to that file, starting with your new %PDF string. When you are done writing, close both files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜