Author Topic: GS adding text to pdf's  (Read 8689 times)

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 270
  • Karma: +3/-0
    • View Profile
GS adding text to pdf's
« on: February 28, 2023, 04:22:56 pm »
Hi,

I'm using gsos2 to add text to pdf-files and it has worked fine until I had to insert some special Norwegian characters.
Instead of inserting the characters æ, ø and å it creates blank spaces. (The ps-file that gsos2 uses for adding the text
shows the special characters correctly.)
The third line in the attached test.pdf is added by gsos2, should be identical to the first word in line 1 but three special
characters are missing.

Ideas anyone?

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1354
  • Karma: +26/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #1 on: March 01, 2023, 03:56:07 am »
Your PDF file shows:

1) Times-Roman as 'Not embedded'
2) NimbusSanL-Bold as 'Embedded subset'

Do you know which font the special characters are coming from?

What is your input file to create this PDF with? If you have it handy I can give it a try here and pipe it through gs9.18 to compare the results...

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 270
  • Karma: +3/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #2 on: March 01, 2023, 12:19:23 pm »
According to source.ps they should come from NimbusSanL-Bold.

Did some more tests with a new pdf, but still the same problem.

The files I'm using are attached.

source.pdf
source.ps - had to rename it to source.txt since *.ps is cannot be uploaded
result.pdf

Using following command:
gsos2 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=result.pdf source.ps -f source.pdf

Thomas Fauster

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #3 on: March 02, 2023, 01:02:24 pm »
The problem is not OS/2 related. The example gives the same result on Linux.
To get it to work, you have to write the special characters as octal escape sequencies: Blab\361rsyltet\371y
However "å" (aring) is not in the standard encoding vector. The solution would be to reencode the font (see Postscript green book).
With a properly reencoded font you may use the standard keyboard encoding of your system, but it might not work on other systems.
/NimbusSanL-Bold is the Ghostscript replacement for the Postscript standard font Helvetica-Bold.
« Last Edit: March 02, 2023, 01:34:43 pm by Thomas Fauster »

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 270
  • Karma: +3/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #4 on: March 02, 2023, 04:29:12 pm »
Thanks, when using \361 and \371 I get the correct characters.
Found a table with octal codes for "Standard+" and it shows \375 for "Å" and \376 for "å", unfortunately GS produces blank spaces with these codes.
Any suggestions for an application that can be used for "opening" the font file to see how it's coded and possibly reencode it?

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1354
  • Karma: +26/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #5 on: March 03, 2023, 04:07:40 am »
Per,
Well, as it turns out, attempting to use gsos2 from CLI here just causes a bunch of "can't find the font file" error messages...which I suspect is either the result of some wrong font mapping on my system or maybe even a broken gscript install?

I suspect a bad environment variable though because I can normally successfully create PDFs with PDFMergeNX, which itself uses gsos2 but has the following set as the libpath:

\usr\share\fonts\default\ghostscript;G:\usr\share\fonts\default\type1;g:\psfonts

Indeed, there are pile of fonts in the \usr\share\fonts\default\ghostscript subdirectories.

Sorry...but no test results here.

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 270
  • Karma: +3/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #6 on: March 03, 2023, 05:05:47 am »
Just noticed this ticket, maybe it solves the problem finding font files.
(I'm using gs9.15, installed from zip-file.)

https://trac.netlabs.org/ports/ticket/100


Thomas Fauster

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #7 on: March 03, 2023, 11:39:02 am »
Hi Per,

attached is a modified version of your source.txt including the reencoding of the character table of the postscript font.
(Note that you have to apply ReEncodeSmall to each font you want to use.)
It is copied from the Postscript Language Tutorial & Cookbook (a.k.a. BlueBook, can be found in the internet).
If the octal codes are adjusted to match the character encoding of your system
you may use the characters as you type them on your keyboard.

Good luck, Thomas

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 270
  • Karma: +3/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #8 on: March 03, 2023, 02:26:45 pm »
Thank you, Thomas.

That code adds correct text to the pdf's.
By the way, I opened the font file at a couple of online "font editors", but could not find a way to make any adjustments for octal values.

What version of GS are you using on Linux? 

Thomas Fauster

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #9 on: March 03, 2023, 03:48:25 pm »
GPL Ghostscript 9.55.0 (2021-09-27) version on Linux

The adjustments are made via the encoding vector which maps the character codes entered on the keyboard to the character names known to postscript.
In the example /scandvec maps 8#362 to aring = å
The attached table from the Postscript Red Book shows that aring is not mapped in standard encoding and in ISO it would be mapped to 8#345.
If your keyboard uses the ISO-8859-1 (Western Europe) character set
then you would have to modify the entry to 8#345 aring, add lines 8#346 ae and 8#370 oslash
and you should be able to enter the text as you type it on the keyboard.

Good luck, Thomas

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 270
  • Karma: +3/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #10 on: March 04, 2023, 05:06:37 pm »
Do you happen to know which file(s) I need to modify?
I've been looking through a lot of files in my  ghostscript folder but I have not found any that has entries like  8#345 etc.

Thomas Fauster

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: GS adding text to pdf's
« Reply #11 on: March 04, 2023, 07:18:34 pm »
You can't make the modifications in the ghostscript files or fonts.
(At least I don't know how to do that.)
Use sourcenc.txt  (possibly adjusted) in place of your source.txt