Adding Times New Roman to Ghostscript in Ubuntu - pdf

Using Ghostscript 8.71 in Ubuntu, but having trouble reading a PDF file that has the times new roman font on all its pages.
I downloaded the msttcorefonts package and created a Fontmap file for Ghostscript, but this just doesnt seem to work.
My Fontmap file looks like this:
/Times (/usr/share/fonts/truetype/msttcorefonts/times.ttf);
/Times-Roman (/usr/share/fonts/truetype/msttcorefonts/times.ttf);
/Times-Bold (/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf);
/Times-BoldItalic (/usr/share/fonts/truetype/msttcorefonts/timesbi.ttf);
/Times-Italic (/usr/share/fonts/truetype/msttcorefonts/timesi.ttf);
The Ghostscript command I use:
gs -sFONTMAP=/usr/share/ghostscript/8.71/Fontmap bad.pdf -o good.pdf
And this is the error I get:
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 3.
Page 1
Error: /undefined in --run--
Operand stack:
--dict:5/14(L)-- F2 11.0 FontObject --dict:8/8(L)-- --dict:8/8(L)-- 397 --dict:8/8(L)--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1878 1 3 %oparray_pop 1877 1 3 %oparray_pop 1861 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 3 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1151/1684(ro)(G)-- --dict:1/20(G)-- --dict:75/200(L)-- --dict:75/200(L)-- --dict:108/127(ro)(G)-- --dict:288/300(ro)(G)-- --dict:22/25(L)-- --dict:6/8(L)-- --dict:25/40(L)-- --dict:1151/1684(ro)(G)-- --dict:10/10(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.71: Unrecoverable error, exit code 1
Could anyone please help me on this? I feel like I've exhausted all possibilities that I can think of.
Here is the PDF file I'm trying to run through Ghostscript: bad.pdf
If I load all fonts like so:
gs -c 'loadallfonts quit'
Then the only references to the Times New Roman font is:
Loading TimesNewRomanPS-BoldItalicMT font from /usr/share/fonts/truetype/msttcorefonts/timesbi.ttf... 4310316 2923512 4001304 2206507 1 done.
Reading the properties of the attached PDF, I can see the font it actually wants is TimesNewRomainPSMT. Why is gs not loading all fonts in the msttcorefonts folder?

This is what the pdffonts utility reports about bad.pdf:
pdffonts bad.pdf
name type encoding emb sub uni object ID
--------------------------- ----------------- ---------------- --- --- --- ---------
Times-Roman Type 1 WinAnsi no no no 12 0
DejaVuSerifCondensed Type 1 WinAnsi yes no no 13 0
DejaVuSansCondensed Type 1 WinAnsi yes no no 16 0
DejaVuSansCondensed-Bold Type 1 WinAnsi yes no no 19 0
This means the following:
The font's name which is not embedded is Times-Roman, not TimesNewRomanPSMT as you think. (I guess you used the Adobe Acrobat/Reader "file properties" dialog to look at the font properties? And there you saw this font name tagged as "Actual Font" or similar? This means that Acrobat is using this font named TimesNewRomanPSMT as a substitute, because it does not have a font named Times-Roman itself!)
There are 3 fonts from the DejaVu family embedded. These are not subsetted, but embedded as full fonts.
So far, so good...
Or?
Now see what happens if I try to let the newest Ghostscript version, compiled from current Git sources, process this bad.pdf:
gs -o new.pdf -sDEVICE=pdfwrite bad.pdf
GPL Ghostscript GIT PRERELEASE 9.16 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 3.
Page 1
**** Warning: can't process font stream, loading font by the name.
Substituting font Helvetica-Narrow for DejaVuSerifCondensed.
Loading NimbusSanL-ReguCond font from %rom%Resource/Font/NimbusSanL-ReguCond... 4671296 3041958 2433440 1055875 3 done.
Loading NimbusRomNo9L-Regu font from %rom%Resource/Font/NimbusRomNo9L-Regu... 4688240 3115971 2494016 1110728 3 done.
Page 2
**** Warning: can't process font stream, loading font by the name.
Substituting font Helvetica-Narrow for DejaVuSerifCondensed.
Page 3
**** Warning: can't process font stream, loading font by the name.
Substituting font Helvetica-Narrow for DejaVuSerifCondensed.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** ====== mPDF 4.6 ======
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
Your embedded fonts cannot be processed by Ghostscript.
There seems to be much more wrong with this particular PDF than what you think.

Related

Postscript to PDF with EPS reference

I am trying to convert a PS file to PDF via Ghostscript (version 9.52). My problem is that the PS file has a reference to an external EPS file, this is a logo file which is normally in the printer memory. I have the source of this EPS file as well. When using the 'ps2pdf' script installed with Ghostscript I get an error on loading the EPS file. The code where the EPS gets loaded looks like this:
/showpage {} def
/setpagedevice /pop load def
(logo.eps) run
restore
When I run 'ps2pdf' the following error is shown:
Error: /invalidfileaccess in --run--
Operand stack:
--nostringval-- (logo.eps) (r)
Execution stack:
%interp_exit .runexec2 --nostringval-- run --nostringval-- 2 %stopped_push --nostringval-- run run false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- run --nostringval-- 2 %stopped_push --nostringval-- 1990 2 3 %oparray_pop run
Dictionary stack:
--dict:739/1123(ro)(G)-- --dict:0/20(G)-- --dict:82/200(L)--
Current allocation mode is local
Any suggestions on how to convert a PS file with EPS references to PDF?
As noted in the recent release notes (and warned about for literally years) Ghostscript now ships with SAFER as the default.
When SAFER is actiuve the PostScript file operators are disabled, and will fail with an invalidfileaccess error. You need to either set -dNOSAFER (NOT recommended) or add the files you want to be able to access to the list of accessible files, reading and writing are treated separately).
This is all covered in the docuementation, you can find it online here (look for -dSAFER lower down the page from that link) or locally in ghostpdl/doc/Use.htm

How can I fix "gsicc_open_search(): Could not find" Error message while using gs

I am trying to fix my pure black colored text problem in PDF conversion. I am able to convert my sRGB pdf to CMYK pdf but text colors are not kept in pure black. I already tried to use ghostscript: convert PDF into CMYK preserving pure Black for text trick but even I compiled "apple_..." files in my current directory, I always get :
gsicc_open_search(): Could not find ~/temp/AdobeCPs/CMYK/apple_to_jNP_neutrals.icc .
the command I am using:
gs -q -sDEVICE=pdfwrite -o sample.pdf -sColorConversionStrategy=CMYK
-sSourceObjectICC=control.txt test.pdf
My output is :
./base/gsicc_manage.c:1088: gsicc_open_search(): Could not find Graphic_RGB apple_to_jNP_neutrals.icc 0 1 0
+ ./base/gsicc_manage.c:660: gsicc_set_srcgtag_struct(): setting of control.txt src obj color info failed
| ./base/gsicc_manage.c:2731: gs_setsrcgtagicc(): cannot find srctag file
While reading gs_lev2.ps:
Error: /unknownerror in --.setuserparams--
Operand stack:
(gs_res.ps\000gs_typ42.ps\000gs_cidfn.ps\000gs_cidcm.ps\000gs_fntem.ps\000gs_cidtt.ps\000gs_cidfm.ps\000gs_cmap.ps\000gs_setpd.ps\000gs_fapi.ps\000gs_typ32.ps\000gs_frsd.ps\000gs_ll3.ps\000gs_mex_e.ps\000gs_mro_e.ps\000gs_pdf_e.ps\000gs_wan_e.ps\000pdf...) (gs_lev2.ps) --dict:31/31(G)-- --dict:1/1(G)-- --dict:1/1(G)--
Execution stack:
%interp_exit --nostringval-- --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push --nostringval-- --nostringval--
Dictionary stack:
--dict:798/1123(G)-- --dict:71/200(L)-- --dict:798/1123(G)-- --dict:133/251(G)-- --dict:21/25(L)--
Last OS error: No such file or directory
Current file position is 24631
Unrecoverable error: syntaxerror in --nostringval--
Operand stack:
gs_res.psgs_typ42.psgs_cidfn.psgs_cidcm.psgs_fntem.psgs_cidtt.psgs_cidfm.psgs_cmap.psgs_setpd.psgs_fapi.psgs_typ32.psgs_frsd.psgs_ll3.psgs_mex_e.psgs_mro_e.psgs_pdf_e.psgs_wan_e.pspdf_ops.psgs_l2img.pspdf_rbld.pspdf_base.pspdf_draw.pspdf_font.pspdf_main.pspdf_sec.psgs_cff.psgs_mgl_e.psgs_ttf.psgs_icc.psgs_dps.psgs_dpnxt.psgs_epsf.psgs_pdfwr.ps gs_lev2.ps --nostringval-- --nostringval-- --nostringval-- false
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
gs_res.psgs_typ42.psgs_cidfn.psgs_cidcm.psgs_fntem.psgs_cidtt.psgs_cidfm.psgs_cmap.psgs_setpd.psgs_fapi.psgs_typ32.psgs_frsd.psgs_ll3.psgs_mex_e.psgs_mro_e.psgs_pdf_e.psgs_wan_e.pspdf_ops.psgs_l2img.pspdf_rbld.pspdf_base.pspdf_draw.pspdf_font.pspdf_main.pspdf_sec.psgs_cff.psgs_mgl_e.psgs_ttf.psgs_icc.psgs_dps.psgs_dpnxt.psgs_epsf.psgs_pdfwr.ps gs_lev2.ps --nostringval-- --nostringval-- --nostringval-- false
My control.txt file is :
Image_RGB apple_to_jNP_photo.icc 0 1 0
Graphic_RGB apple_to_jNP_neutrals.icc 0 1 0
Text_RGB apple_to_jNP_neutrals.icc 0 1 0
echo $GS_LIB
/usr/share/ghostscript/9.18/Resource
ls /usr/share/ghostscript/9.18/Resource
CIDFont CIDFSubst CMap ColorSpace Decoding Encoding Font IdiomSet Init SubstCID
current directory :
~/temp/AdobeCPs/CMYK$ ls
AppleRGB.icc CoatedGRACoL2006.icc JapanColor2003WebCoated.icc USWebCoatedSWOP.icc
apple_to_jNP_neutrals.icc control.txt JapanWebCoated.icc USWebUncoated.icc
apple_to_jNP_photo.icc JapanColor2001Coated.icc sample.pdf WebCoatedFOGRA28.icc
CoatedFOGRA27.icc JapanColor2001Uncoated.icc test.pdf WebCoatedSWOP2006Grade3.icc
CoatedFOGRA39.icc JapanColor2002Newspaper.icc UncoatedFOGRA29.icc WebCoatedSWOP2006Grade5.icc
Could you help ?
Even though this is a quite old thread it seems not yet solved.
I had the same error as mentioned above with blanks as separators in the control.txt instead of tabs (as mentioned in the Ghostscript version Color Management WhitePaper).
Changing to tabs fixed the problem for me.
Your command line and input file isn't relevant to the problem, the failure is during startup:
| ./base/gsicc_manage.c:2731: gs_setsrcgtagicc(): cannot find srctag
file While reading gs_lev2.ps:
gs_lev2.ps is part of Ghostscript's startup code. That's all executed before you even get to the point of reading the command line options.
You haven't said which version of Ghostscript you are using, on which OS, or where you got it from, but it looks to me like you version is fundamentally broken.
I infer from your text that you are using version 9.18, that's 5 versions (2.5 years) out of date, the current version is 9.23. I'd suggest you get the vanilla Ghostscript source from the downloads page and compile that.

convert png to pdf using ghostscript

as the title says I am trying to convert png to pdf.
I could not find well described example anywhere about this.
I used this command
gs sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=test.pdf test.png
but all I get is
Error: /syntaxerror in (binary token, type=137)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1894 1 3 %oparray_pop 1893 1 3 %oparray_pop 1877 1 3 %oparray_pop 1771 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:1161/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
GPL Ghostscript 9.07: Unrecoverable error, exit code 1
this error message. And now I started wodering if such feature is possible in ghostscript. Should I use other software?
** I'm runing the latest 9.07 version
Ghostscript can output multiple formats (png included) but I don't believe it is able to take png as an input. You may be able to accomplish your goal using something like imagemagick's convert utility, though: convert test.png test.pdf
Yes, image magick can do this no problem - here's the cmd line for looping through all the pngs in a folder and converting to pdf:
cd to the folder with the pngs
mogrify -format pdf -density 300 -units PixelsPerInch *png

Ghostscript fonts using the api

I've got a bit of an issue with Ghostscript. I'm writing an application in .NET that uses the Ghostscript API, gs32dll.dll. It works just fine for a number of pdfs, but there a couple that have this little movie can dingbat, and ghostscript throws an error about not having that font. I know I have to make a listing for that font in the cidfmap file, but since I'm not using an actual install of ghostscript, I don't have local paths pointing to that file. I want this program to be installed on a number of computers, but I'd rather not install the full blown ghostscript on these computers. So, I was wondering if it would be possible to put a copy of cidfmap in with the dll. I figured it might look in its path first. I'd even be cool with ghostscript skipping the conversion of that character. I'm open to any ideas.
About the program:
I teach math. We have these note taking guides on pdf. Every section in each chapter has two pdfs, one with and one without answers. I'm using ghostscript to convert the pdfs to images (jpegs). Once finished, the user will be able to use the smartboard pen to highlight the area where an answer would be, and the answer will be cut from the answer document image and pasted on the same location of the blank document. I plan on giving this out to the other math teachers once I've finished. I'd like to keep the program self contained, so I don't have to explain to them how to install ghostscript and whatnot. I'd just like to hand them a folder.
Revision = 900
RevisionDate = 20100914
Product = GPL Ghostscript
Copyright = Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
GPL Ghostscript 9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 5.
Page 1
Page 2
Can't find CID font "ZapfDingbats".
Substituting CID font /Adobe-Identity for /ZapfDingbats, see doc/Use.htm#CIDFont
Substitution.
The substitute CID font "Adobe-Identity" is not provided either. Will exit with
error.
Error: /undefined in findresource
Operand stack:
--dict:11/20(L)-- G27 1 --dict:5/5(L)-- --dict:5/5(L)-- ZapfDingbat
s-Identity-H --dict:10/12(ro)(G)-- --nostringval-- CIDFontObject --dict:
7/7(L)-- --dict:7/7(L)-- Adobe-Identity
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-
- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- fa
lse 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_
pop 1893 1 3 %oparray_pop --nostringval-- --nostringval-- 3 1
5 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval--
--nostringval-- --nostringval-- %array_continue --nostringval-- false
1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nos
tringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval
-- %array_continue --nostringval-- --nostringval-- --nostringval-- --n
ostringval-- --nostringval-- %loop_continue
Dictionary stack:
--dict:1158/1684(ro)(G)-- --dict:1/20(G)-- --dict:82/200(L)-- --dict:82
/200(L)-- --dict:108/127(ro)(G)-- --dict:293/300(ro)(G)-- --dict:23/30(L)-
- --dict:6/8(L)-- --dict:22/40(L)-- --dict:14/15(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.00: Unrecoverable error, exit code 1
On a Linux commanline, invoke
gs -h
on Windows, invoke
gswin32c.exe -h
This should show you the search path(s) used by your instance of Ghostscript. This may help you to determine where in your folder structure you'd have to place your font resource.
You can also use an additional CLI parameter to override any builtin search paths:
gswin32c.exe ^
-I"d:/absolute/path/to/dir;../relative/path/to/dir;c:/other dir with spaces" ^
[...]
Note that on Windows Ghostscript is able to use forward slashes as directory delimiters for paths.
I'm sure you can somehow add that sort of invocation (-I...) to your software.
How about separating your program in a client and a server part?
Then a server could have all of Ghostscript and all kinds of fonts installed on it, and the clienst accessing this server would not need Ghostscript at all.
Might help with licensing issues too, depending on your situation.
In response to edited question:
Probably you can install Ghostscript locally to a portable folder within your program drectory:
Look at this forum comment for inspiration. I know others have succeeded too.

What parameters will allow Ghostscript to read font names in Chinese correctly from a PDF?

I tried
gswin32c -sDEVICE=jpeg -sOutputFile=foo.jpg foo.pdf
but I get the ff. output from Ghostscript on the page where the Chinese font is used.
Substituting CID font resource/Adobe-CNS1 for /·s²Ó©úÅé.
Error: /undefinedresource in --findresource--
Operand stack:
--dict:4/4(L)-- F3 12.96 --dict:6/6(L)-- --dict:6/6(L)-- ·s²Ó©úÅé --dict:9/12(ro)(G)-- --nostringval-- --dict:8/8(L)-- --dict:8/8(L)-- Adobe-CNS1 CIDFont Adobe-CNS1
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop --nostringval-- --nostringval-- 3 1 33 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %loop_continue --nostringval-- 12 9 %oparray_pop --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1122/1686(ro)(G)-- --dict:2/20(G)-- --dict:75/200(L)-- --dict:75/200(L)-- --dict:105/127(ro)(G)-- --dict:253/347(ro)(G)-- --dict:21/24(L)-- --dict:4/6(L)-- --dict:26/31(L)-- --dict:20/26(ro)(G)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.54: Unrecoverable error, exit code 1
It's obvious that Ghostscript's encoding is non-Unicode because it got garbage (/·s²Ó©úÅé) when it read the font name which is in Chinese. Here is a screen shot of the Chinese fonts used as listed by Adobe Reader 9.
Interesting problem.
However, it's not necessarily Ghostscript's fault here, that you only see /·s²Ó©úÅé.
From your command, I see you was using Ghostscript on Windows, inside a cmd.exe shell window. And it is cmd.exe which may not be able to display properly what Ghostscript asks it to display. This could have two separate reasons (or both at the same time)
the 'codepage' your cmd.exe window uses cannot handle CID or Unicode characters/glyphs.
the font used by your cmd.exe does not contain and therefore cannot handle CID/Unicode glyphs.
You should query your cmd.exe window first, which 'codepage' it uses. Type:
chcp
and see if it is anything that can NOT display multi-byte characters and glyphs (like "codepage 850").
If so, try to change your codepage in your current cmd.exe window, using this command:
chcp 65001
or
chcp 65000
This should switch you to Unicode (65001 == UTF-8-Unicode; 65000 == UTF-7-Unicode). If you did so, you also have to make sure that the font used in your cmd.exe window can display all (most) of the glyphs in question: therefore you should go into the settings of the cmd.exe window (click the top left corner icon of window title bar) and change the font to 'Lucida Console'.
Here are a few more codepage numbers which may help you:
932 : Japanese Shift-JIS
936 : Simplified Chinese GBK
949 : Korean
950 : Traditional Chinese Big5
But note, you may not be able to switch to these codepages, unless your computer is installed with Japanese/Chinese/Korean language support.
See also here:
http://en.wikipedia.org/wiki/Windows_code_page
http://en.wikipedia.org/wiki/Mojibake
Having said all this above, this may still not solve your problem. Ghostscript may still show the same error, because it is not finding the font it wants to use (CID font resource/Adobe-CNS1) in place of ·s²Ó©úÅé. But at least you would understand better, which font it wants to replace. Your console would display the same asian glyphs as your Adobe Reader screenshot shows... ;-)
Chry Cheng: I'm still trying to find a solution to your problem with Ghostscript, but I didn't have time to do the required research yet...
I don't know if you must use Ghostscript for some reason. But if not, here is another option: MuPDF. Brought to you by artofcode LLC & Artifex Inc. -- the same people that develop Ghostscript.
And MuPDF didn't have any problem for me to render your example file! (Funnily, Ghostscript chokes on page 2; Acrobat Reader also choked, but offered to download and install an additional Asian font, not naming it, but saying it was "to support traditional Chinese". After installing it, Acrobat Reader however does not show a single chinese glyph on page 2!)
MuPDF:
Open Source;
multiplatform (Windows, Mac OS X, Unix, ...soon maybe Android, iPhone too?);
very lightweight (see screenshots below);
very fast;
secure (no JavaScript support);
very surely not bloated with features;
does display all pages of your example PDF
interface is very simple (keyboard navigation only, no menues or icons):
(Chry Cheng: I wonder if you also notice that one little thing in my screenshots that was a bit surprising and mysterious for me...)