Search code examples
javapdfghostscript

What causes the error **** Error: Invalid 0.0 horizontal text scaling given for Tz when running ghostscript and how do I solve it?


Hi I am writing a java application that needs to use ghostscript on electrical drawings saved as pdf. Some of the drawings cause ghostscript to printout an error message:

**** Error: Invalid 0.0 horizontal text scaling given for Tz

I assume that the original application used to build the drawings and save them as pdf have not followed the spec correctly and created some bad pdf:s. The command i use is:

gswin64c -sDEVICE=pdfwrite -dNOPAUSE -sOutputFile="output.pdf" "test.pdf"

The command I run in the java application has alot more options to change the pdf in various ways.

I have tried using PDFBox to simply resave the file in the hopes it would automatically fix any problems before running ghostscript.

I also tried using ghostscript to save the pdf as a ps file using the GS device ps2write:

gswin64c -sDEVICE=ps2write -dNOPAUSE -sOutputFile="output.ps" "test.pdf"

Then running the ghostscript command on the ps file to create a pdf:

gswin64c -sDEVICE=pdfwrite -dNOPAUSE -sOutputFile="output.pdf" "output.ps"

This creates a pdf that doesn't output error when running ghostscript. So I may end up running ghostscript twice to resolve this. But I would like to here what other think and if they have any better solutions.

Since the error was regarding text scaling I figured that it may be due to a problem with the fonts so I tried using the fontmap file to substitute the font when running ghostscript to see if it would work better with other fonts. That didn't help though.

First I would like some info on the error message and why it is complaining. I would also like some suggestions on how to solve an issue where you don't know how well formed the pdf:s are and what you can do to try and fix any issues a pdf has before running ghostscript.

Thanks!


Solution

  • I ended up using PDFBox to save the pdf before using ghostscript. PDFBox is able to fix any issues ghostscript had with the pdf.