[ALUG] Scripted editing of PDF files

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Jul 10 11:47:44 BST 2008


On 10-Jul-08 10:22:49, Mark Rogers wrote:
> Does anyone have any idea how to perform command-line PDF editing?
> 
> The sort of thing I am talking about is adding text to the document 
> maybe even editing existing text if that's possible. (The PDF will be a
> poster for printing, I need to change some details and return it. The 
> quality of the PDF is therefore important and converting (say) to JPEG,
> adding the content, then converting back, will probably not give 
> adequate results (unless someone knows better?)
> 
> For test purposes I have tried things like:
>     convert test.pdf test.png
>     convert test.png test2.pdf
> .. and the quality difference between test.pdf and test2.pdf is 
> noticable (colour definition has reduced, and the image has become 
> grainy). In fact, even:
>     convert test.pdf test2.pdf
> .. gives almost identical results to the via-jpeg test, which makes me 
> think something like that is happening anyway.
> 
> It may be that I can improve the above tests with convert if anyone has
> any suggestions?

You've been converting from a vector-graphics (in principle) format
to a bit-mapped format, and the loss of quality you describe is
inevitable in such conversions.

I'm deducing from the above that you don't have access to PDF-editing
software (such as Adobe supplies -- at cost!)

One obstacle you may face (since this is a poster) is that the PDF
be itself be bit-mapped graphics (partly or even wholly). If that's
the case then I think you're stuck unless you can get access to the
"source code" of the PDF.

On the other hand, if the PDF was simply uses text fonts and vector
graphics, then you can (in theory) export it (e.g. from Acrobat Reader)
to a PostScript file -- just "print to file".

Then -- PostScript being written in ASCII -- you have a chance to
edit it using a text editor. How feasible this is will depend on the
complexity of the PostScript code.

If you succeed in adequately editing the POstScript, you can then
convert it back to PDF using, for instance, ps2pdf (which it might
be worth slightly modifying for better results). The graphics
quality of the final PDF should then be as good as the original.

I've done this sort of thing a number of times, but (as I state
above) the chance of success is very strongly contingent on what's
in the PDF file (and therefore in the resulting PS file).

If you want some off-list discussion for this particular case,
drop me a line.

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 10-Jul-08                                       Time: 11:47:41
------------------------------ XFMail ------------------------------




More information about the main mailing list