Is there any command line tool for Linux that will allow me to annotate a PS or PDF file with text or a particular font, color, and size with no loss of quality? I have tried ImageMagick's convert, and the resulting PDF is of pretty poor quality.

I have a template originally authored in Adobe Illustrator, and I would like to generate PDFs from it with names in certain places. I have a huge list of names, so I would like to do this in a batch (not interactively).

If anyone has any ideas I'd appreciate hearing them. Thanks, Carl

有帮助吗?

解决方案

I think it's better to create PDF form and fill it with pdftk fill_form in batch:

$ pdftk form.pdf fill_form data.fdf output out.pdf flatten

Form data should be in Forms Data Format (it's just XML file with field names and values specified).
Note the flatten command. It is required to convert filled form to plain document.

Another way is to create set of PDF documents "with names in certain places" and transparent background, and pdftk stamp each of them over the template:

$ pdftk template.pdf stamp words.pdf output out.pdf

其他提示

Another way to accomplish this would be to hack the postscript file itself. It used to be that AI files were postscript files, and you could modify them directly; I don't know if that's true anymore. So you may have to export it.

For simplicity, I assume there's a single page. Therefore, at the very end there will be a single call to showpage (perhaps through another name). Any drawing commands performed before showpage will show up on the page.

You may need to reinitialize the graphics state (initgraphics), as the rest of the document may have left it all funny, expecting showpage to clean up before anyone notices.

To place text, you'll need to set a new font (the old one was invalidated by initgraphics) measure the location in points (72 points/inch, 28.3465 points/cm).

/Palatino-Roman 17 selectfont %so much prettier than Times
x y moveto
(new text) show

To do the merging, you can use perl: emit the beginning of the document as a HERE-document, construct some text-writing lines by program, emit the tail of the document. Here's an example of generating postscript with PERL

Or you can take data from the command-line (with ghostscript) by using the -- option ($gs -q -- program.ps arg1 arg2 ... argn). These arguments are accessible to the program through an array named /ARGUMENTS.

So, say you have a nice graphic of a scary clown holding a blank sign about 1 inch wide, 3 inches tall, top left corner at 4 inches from the left, 4 inches from the bottom. You can insert this code into the ps program, just before showpage.

initgraphics
/Palatino-Roman 12 selectfont
4 72 mul 4 72 mul moveto
ARGUMENTS {
    gsave show grestore 0 -14 rmoveto
} forall

Now you can make him say funny things ($gs -- clown.ps "On a dark," "and stormy night...").

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top