Author Topic: Insert text on pdf's  (Read 8936 times)

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 251
  • Karma: +3/-0
    • View Profile
Insert text on pdf's
« on: June 03, 2019, 04:04:31 pm »
I need to insert text, actually the filename of the pdf, to lots of pdf's.
Does anyone know about a "OS/2-utilty" that can do this, preferably in batch mode?
(Attached a sample, 12345.pdf)

Thomas Fauster

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Insert text on pdf's
« Reply #1 on: June 04, 2019, 09:59:22 am »
One way would be to convert the files to postscript using pdftops from the xpdf utilities.
Then Insert before the showpage command at the end of the postscript file the text e.g.
/Helvetica findfont 12 scalefont setfont 1 0 0 setrgbcolor
490 755 moveto (TEXT) show
Finally convert the postscript file back to PDF using ghostscript..
You could write a rexx script to automate the process.

Edit: Ghostscript provides command files pdf2ps and ps2pdf for file cenversion


« Last Edit: June 04, 2019, 02:51:10 pm by Thomas Fauster »

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 251
  • Karma: +3/-0
    • View Profile
Re: Insert text on pdf's
« Reply #2 on: June 04, 2019, 11:01:22 pm »
Thanks, I already have ghostscript, did some more searching and found;

https://askubuntu.com/questions/872482/adding-a-logo-in-a-pdf-by-ghostscript

My infile test.pdf contains only one line with the word "test.pdf"
(No need to, but I changed "Sample" to "AddedText" and saved it as sample.ps)

Running

gsos2 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf sample.ps -f test.pdf

and it produced the attached out.pdf

So, it looks like this can be done without conversion.

Just noticed that it also added the number "1" in the lower right corner. Guess this can be controlled
by the ps-file, font, size, where to place text etc.

xynixme

  • Guest
Re: Insert text on pdf's
« Reply #3 on: June 05, 2019, 01:02:36 am »
If possible, it may help to use "readable" and broadly supported PDF 1.1 instead of PDF 1.4. 12345.PDF is PDF 1.4, and so is OUT.PDF. With PDF 1.1 it may be quite easy to replace, for example, the "1" by a space.

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 251
  • Karma: +3/-0
    • View Profile
Re: Insert text on pdf's
« Reply #4 on: June 05, 2019, 10:15:27 pm »
At this stage I didn't think about pdf versions at all, but in any case the pdf's I produce are only meant for our auditor and "IRS", plus internal use.
I assume that they use "latest everything" under Windows and so far they have not complained about pdf 1.4. (Latest pdf version is now at 1.7 I think.)

The number "1" which was added to lower right corner was my mistake. Created the pdf in OO and I think it automatically added page numbering.
Have done several tests with "new" pdfs and no numbers are added.

ivan

  • Hero Member
  • *****
  • Posts: 1557
  • Karma: +17/-0
    • View Profile
Re: Insert text on pdf's
« Reply #5 on: June 05, 2019, 11:19:16 pm »
Hi Per,

I should have mentioned this earlier.  There is a java app that will do what I understand you want.  They do it by adding a watermark that you set and there is a batch mode as well.

Have a look at http://jpdftweak.sourceforge.net

If you think it will do what you want I can send you the information necessary to make a program object that runs it using our openjava6.

Edit:
On consideration I have added the information and zip as attachments
« Last Edit: June 05, 2019, 11:43:28 pm by ivan »

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 251
  • Karma: +3/-0
    • View Profile
Re: Insert text on pdf's
« Reply #6 on: June 07, 2019, 10:26:06 pm »
Good that you supplied the setup.txt, Ivan, now it's working.

Looks like it can add watermarks in batch mode but only one watermark can be defined so I would end up with identical watermarks on all pdf's.
(I need the filename of the pdf added/inserted as text.)
Also, I don't see any options for adjusting the placement of the watermark. Tried with the text watermark and it is placed diagonally on the page.

I think REXX and Ghostscript will be the solution.

ivan

  • Hero Member
  • *****
  • Posts: 1557
  • Karma: +17/-0
    • View Profile
Re: Insert text on pdf's
« Reply #7 on: June 08, 2019, 12:48:49 am »
Sorry it doesn't appear to work for you.  I haven't tried that section yet, my main use is dividing up multi language PDFs into separate language versions for a client.

xynixme

  • Guest
Re: Insert text on pdf's
« Reply #8 on: June 12, 2019, 10:41:43 am »
I assume that they use "latest everything" under Windows and so far they have not complained about pdf 1.4.
Sure. A generic advantage of the old version(s) just is that documents can be edited, and an apparently irrelevant specific advantage is that Acrobat/2 should be able to open the files too. PDF isn't that P, and other tools don't always work.