I am trying to merge two PDFs together using gs
, the following command does the job:
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=/tmp/output.pdf input1.pdf input2.pdf
I got error:
Error: /undefined in findresource
Operand stack:
--dict:11/11(L)-- 1.0 0.999999 --dict:11/11(L)-- 1 10 Sota-Regular 56.8 --dict:6/6(L)-- --dict:6/6(L)-- Sota-Regular --dict:10/12(ro)(G)-- --nostringval-- CIDFontObject --dict:7/7(L)-- --dict:7/7(L)-- Arial
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1862 1 3 %oparray_pop 1861 1 3 %oparray_pop 1845 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 1 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- 1810 7 11 %oparray_pop --nostringval-- false 1 %stopped_push 1809 7 11 %oparray_pop --nostringval-- (gstatetype) --dict:0/0(L)-- --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %loop_continue
Dictionary stack:
--dict:1152/1684(ro)(G)-- --dict:1/20(G)-- --dict:75/200(L)-- --dict:75/200(L)-- --dict:106/127(ro)(G)-- --dict:285/300(ro)(G)-- --dict:22/25(L)-- --dict:4/6(L)-- --dict:22/40(L)-- --dict:20/25(L)-- --dict:1/1(ro)(G)-- --dict:8/15(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.70: Unrecoverable error, exit code 1
Doing some googling, and I found this bug http://bugs.ghostscript.com/show_bug.cgi?id=691345. Great! At least I think I have some clue now.
Reading the stacktrace shows that:
--dict:11/11(L)-- 1.0 0.999999 --dict:11/11(L)-- 1 10 Sota-Regular 56.8 --dict:6/6(L)-- --dict:6/6(L)-- Sota-Regular --dict:10/12(ro)(G)-- --nostringval-- CIDFontObject --dict:7/7(L)-- --dict:7/7(L)-- Arial
The Sota-Regular font is missing, thus gs will try to fallback to Arial font which is not yet installed by default on Centos 6.3 So I decided to google again for the RPM, and I found this blog post http://oimon.wordpress.com/2011/09/05/msttcorefonts-on-rhel6-centos-6-sl6/.
To summarize all the steps in that blog post, here are main steps to create the msttcorefonts.rpm:
sudo yum install rpm-build
sudo yum install cabextract
sudo yuim install ttmkfdir
# Download spec file into /tmp
cd /tmp
wget http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec
Then use your favorite text editor and create msttcorefonts.rhel6.patch
file with content:
--- msttcorefonts-2.0-1.spec 2011-09-05 11:09:57.206756336 +0100
+++ msttcorefonts-2.0-1.1.spec 2011-09-05 11:23:56.925761649 +0100
@@ -19,8 +19,8 @@
BuildPrereq: %{ttmkfdir}
BuildPrereq: wget
BuildPrereq: cabextract
-Prereq: /usr/sbin/chkfontpath
-Packager: Noa Resare <noa@resare.com>
+#Prereq: /usr/sbin/chkfontpath
+#Packager: Noa Resare <noa@resare.com>
%description
The TrueType core fonts for the web that was once available from
@@ -152,7 +152,7 @@
%post
if test $1 -eq 1
then
- /usr/sbin/chkfontpath --add %{fontdir}
+ ln -s /usr/share/fonts/msttcorefonts/ /etc/X11/fontpath.d/msttcorefonts
fi
# something has probably changed, update the font-config cache
if test -x /usr/bin/fc-cache
@@ -163,7 +163,7 @@
%preun
if test $1 -eq 0
then
- /usr/sbin/chkfontpath --remove %{fontdir}
+ /bin/rm -f /etc/X11/fontpath.d/msttcorefonts
fi
%files
and we patch the spec file:
patch < msttcorefonts.rhel6.patch
then build and install it:
rpmbuild -bb msttcorefonts-2.0-1.spec
cd ~/rpmbuild/RPMS/noarch
sudo yum localinstall msttcorefonts-2.0-1.spec
and now you can verify by checking the /usr/share/fonts/msttcorefonts/
Please edit /etc/ghostscript/8.70/cidfmap.local
and add following content:
/Arial << /FileType /TrueType /Path (/usr/share/fonts/msttcorefonts/arial.ttf) /SubfontID 0 /CSI [(Artifex) (Unicode) 0] >> ;
That's it. It should fix the problem now for you :)