0

want to write header over pdf files using ghostscript. i tried several thread of this forum

can I use Ghostscript to overlay a text (fax) header onto a PDF and/or TIFF?

How can I make a program overlay text on a postscript file?

i tried this code and it works. i cant see the header but when i search header using find function i can see header somewhere but its not visible.

gs \
 -o /5/7007.pdf \
 -sDEVICE=pdfwrite \
 -g5030x5320 \
 -c "/Helvetica-Italic findfont 15 scalefont setfont 453 482 moveto (544) show" \
 -f /5/77.pdf

and other code is

gs -dBATCH  -dNOPAUSE  -sDEVICE=pdfwrite \
-sOutputFile=/5/7007.pdf \
-c "/Times findfont 12 scalefont setfont 50 765 moveto (header text) show" \
-f /5/77.pdf

both codes generate the pdf fileand header also but header is not visible.

my output of ghostscript is

Page 2
Page 3
Page 4
Page 5
Can't find (or can't open) font file %rom%Resource/Font/Arial-ItalicMT.
Can't find (or can't open) font file Arial-ItalicMT.
Can't find (or can't open) font file %rom%Resource/Font/Arial-ItalicMT.
Can't find (or can't open) font file Arial-ItalicMT.
Didn't find this font on the system!
Substituting font Helvetica-Oblique for Arial-ItalicMT.
Page 6
Page 7
Page 8
Page 9
Page 10
Page 11

i want to write header and footer in all pages and i am ok with any font or if possible can change

. i used fc-list which listed several fonts . i used one of them then also getting similar error. seems ghostscript is trying to match each page font.i am not interested in matching each page font. just want to use some font for header which is available.

partial list of fonts are here

fc-list
Liberation Mono:style=Regular
Utopia:style=Bold Italic
Nimbus Sans L:style=Regular Italic
DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book
Hershey\-Gothic\-English:style=Regular
URW Palladio L:style=Roman
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic
Century Schoolbook L:style=Bold Italic
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold
Liberation Sans:style=Regular
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
DejaVu Sans Mono:style=Bold Oblique
Carlito:style=Italic
Liberation Serif:style=Bold Italic
Caladea:style=Bold
DejaVu Serif:style=Bold Italic
Nimbus Sans L:style=Bold
OpenSymbol:style=Regular
Utopia:style=Bold
Caladea:style=Bold Italic,Italic
Hershey\-Plain\-Duplex\-Italic:style=Regular
Community
  • 1
  • 1
Steeve
  • 423
  • 2
  • 9
  • 23

1 Answers1

2

You need to add the code to make marks on the page as an EndPage procedure, otherwise you first make the marks on the 'page', then write the content of the PDF file. I assume you want to do that the other way around, first write the content of the PDF file then write the additional content afterwards.

You should also set the colour you want the text to be in, otherwise it will use the current colour, which might be white. 0 setgray 0 0 0 setrgbcolor or 0 0 0 1 setcmykcolor will set the current colour to black.

So something like:

-c "<</EndPage {0 setgray /Times 20 selectfont 453 482 moveto (544) show}>> setpagedevice" -f

should probably work well enough.

As regards the warning about Arial-ItalicMT this means your PDF file uses that font, but does not include it. You must either:

  1. Accept the substitution offered by Ghostscript (Helvetica-Oblique)
  2. Supply a different substitute
  3. Supply the real font

In order to do either of 2 or 3 you will need to modify fontmap.GS or cidfmap, depending on whether its a font or a CIDFont which is missing.

Add corrected code:

-sDEVICE=pdfwrite -sOutputFile=\temp\out.pdf -c "<</EndPage {2 ne {0.5 setgray /Times 20 selectfont 453 48 moveto (Test) show pop true}{pop false} ifelse} >> setpagedevice" -f
KenS
  • 30,202
  • 3
  • 34
  • 51
  • either it is giving page with only header or full page without header – Steeve Sep 18 '16 at 11:31
  • Then you've done something wrong. You **should** have got an error. I've modified the code in the edit above, this works for me. – KenS Sep 18 '16 at 13:07
  • my complete code is gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=/8/3999937.pdf -c "<> setpagedevice" –f /8/77.pdf giving GPL Ghostscript 9.19: Unrecoverable error, exit code 1 – Steeve Sep 18 '16 at 13:15
  • Error: /undefined in ▒ – Steeve Sep 18 '16 at 13:28
  • Error: /undefined in ▒ Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- Dictionary stack: --dict:1197/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)-- Current allocation mode is local Last OS error: No such file or directory GPL Ghostscript 9.19: Unrecoverable error, exit code 1 – Steeve Sep 18 '16 at 13:43
  • Well you've got some undefined binary stuff in there, I have no idea how. The error is (apparently) telling you that 'something' is undefined, I have no idea what. You didn't copy and paste from here did you ? If you did copy and paste, try typing the command instead. Without seeing your original PDF file there's little more I can say, the supplied code works as expected for me using 9.19 and a random PDF file I happened to have lying around to test with.. – KenS Sep 18 '16 at 14:17
  • thanks for your reply. i will try with other pdf file – Steeve Sep 18 '16 at 14:23
  • after -f input file path is required or not – Steeve Sep 18 '16 at 16:52
  • You need a fully qualified path to the input file, unless its in the current working directory. And yes, it comes after the -f – KenS Sep 18 '16 at 18:17
  • thanks its working for header. one more question. how to add footer with increasing no. like 1 for first page, 2 for second page etc – Steeve Sep 19 '16 at 04:45
  • The 'pop' in the EndPage code removes an integer representing the 'count of pages so far' from the operand stack (because it wasn't needed for that code). You can instead use that as your page number. Converting an integer into a string, and incorporating that variable string into a template are left as exercises for the student ;-) – KenS Sep 19 '16 at 07:07
  • your code works fine is pdf which is readable. i mean where we can right click and select text. but for scanned pdf its not working and command line just exit without giving any error. any solution for scanned pdf ? Processing pages 1 through 1. Page 1 Loading NimbusRomNo9L-Reg font from %rom%Resource/Font/NimbusRomNo9L-Reg... 4642732 3148219 2513504 1167941 3 done. – Steeve Sep 19 '16 at 11:35
  • It should work the same for any PDF regardless of its contents. Note that the message you quote means that it did not 'exit without giving an error', it clearly did process a page. Its almost impossible to diagnose problems by text description. If you want me to look at this you are going to have to make an example available. – KenS Sep 19 '16 at 15:01
  • you are right .its working. that time i dont know what happened – Steeve Sep 20 '16 at 02:45