GhostScript Convert error /undefined in findresource

Ghostscript Logo

Ghostscript Logo

At my work I had to correct a bug related to the conversion of a PDF to a jpeg. To do that we use the convert command line tools from ImageMagick.

The server which is doing the conversion run an Ubuntu with the latest version of the package ghostscript ( 8.71).

Here is the error:

11:04 1442 ~/Desktop : convert corrup1.pdf toto.jpg
Error: /undefined in findresource
Operand stack:
–dict:8/17(L)– C2_1 1 –dict:5/5(L)– –dict:5/5(L)– Arial –dict:9/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– false 1 %stopped_push 1878 1 3 %oparray_pop 1877 1 3 %oparray_pop 1861 1 3 %oparray_pop –nostringval– –nostringval– 2 1 1 –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
Dictionary stack:
–dict:1161/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:26/40(L)–
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.71: Unrecoverable error, exit code 1
convert: Postscript delegate failed `corrup1.pdf’: No such file or directory @ pdf.c/ReadPDFImage/634.
convert: missing an image filename `toto.jpg’ @ convert.c/ConvertImageCommand/2838.

Weird. A google of the Error: /undefined in findresource will lead you to this bug.
To sum up the installer of ghostscript is fucked up, and no new version of the package is deploy to solve it. Awesome.

ghostscript is not able to find a font ( Adobe-Identity ) and try to find a substitution font ( Arial ) but can’t find it.
So let’s correct the configuration manually.

First make sur that you have install the microsoft webfont on your system.

Then we need to edit our cidmap which is the configuration file which tell ghostscript substitution font. Mine looks like after adding the last line:
/var/lib/defoma/gs.d/dirs/fonts/cidfmap

1 /Dotum-Bold << /FileType /TrueType /Path (/usr/share/fonts/truetype/unfonts/UnDotumBold.ttf) /SubfontID 0 /CSI [(Korea1) 0] >> ;
2 /Batang-Regular << /FileType /TrueType /Path (/usr/share/fonts/truetype/unfonts/UnBatang.ttf) /SubfontID 0 /CSI [(Korea1) 0] >> ;
3 /Batang-Bold << /FileType /TrueType /Path (/usr/share/fonts/truetype/unfonts/UnBatangBold.ttf) /SubfontID 0 /CSI [(Korea1) 0] >> ;
4 /Dotum-Regular << /FileType /TrueType /Path (/usr/share/fonts/truetype/unfonts/UnDotum.ttf) /SubfontID 0 /CSI [(Korea1) 0] >> ;
5 /Arial << /FileType /TrueType /Path (/usr/share/fonts/truetype/msttcorefonts/arial.ttf) /SubfontID 0 /CSI [(Artifex) (Unicode) 0] >> ;

Make sur to use the correct path for the arial.ttf file.

Doing that produce a second error:

1:16 1442 ~/Desktop : convert corrup1.pdf toto.jpg
Can’t find CMap Identity-UTF16-H building a CIDDecoding resource.
Error: /undefinedresource in findresource
Operand stack:
–dict:8/17(L)– C2_1 1 –dict:5/5(L)– –dict:5/5(L)– Arial –dict:9/12(ro)(G)– –nostringval– CIDFontObject –dict:7/7(L)– –dict:7/7(L)– Arial CIDFont true Arial false Arial –dict:23/26(G)– Unicode.Unicode CIDDecoding true Unicode.Unicode –dict:28/48(ro)(G)– Identity-UTF16-H
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 1 –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– –nostringval– 1829 13 9 %oparray_pop findresource %errorexec_pop –nostringval– –nostringval– –nostringval– –nostringval– –nostringval– –nostringval– –nostringval– –nostringval– %loop_continue –nostringval– –nostringval– –nostringval– 1829 20 10 %oparray_pop findresource %errorexec_pop –nostringval– –nostringval– –nostringval– –nostringval– –nostringval– –nostringval– %array_continue –nostringval–
Dictionary stack:
–dict:1161/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:26/40(L)– –dict:20/26(ro)(G)– –dict:18/25(ro)(G)– –dict:16/25(ro)(G)–
Current allocation mode is global
Last OS error: 2
GPL Ghostscript 8.71: Unrecoverable error, exit code 1
convert: Postscript delegate failed `corrup1.pdf’: No such file or directory @ pdf.c/ReadPDFImage/634.
convert: missing an image filename `toto.jpg’ @ convert.c/ConvertImageCommand/2838.

The error is Can’t find CMap Identity-UTF16-H. Ghostscript can’t find this, so let’s create it !

Mine need to be created in /usr/share/ghostscript/8.71/Resource/CMap/Identity-UTF16-H

The content of this file can be find here. Or copy it from here:

% Copyright (C) 2003 Artifex Software. All rights reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
%
% $Id: Identity-UTF16-H 7095 2006-10-10 10:03:37Z leonardo $
% Identity-UTF16-H CMap
% An identity mapping of UTF16 codes to CIDs.

/CIDInit /ProcSet findresource begin

12 dict begin

begincmap

/CIDSystemInfo 3 dict dup begin
/Registry (Artifex) def
/Ordering (Unicode) def
/Supplement 0 def
end def

/CMapName /Identity-UTF16-H def
/CMapVersion 1.000 def
/CMapType 1 def

/UIDOffset 0 def
% No XUID yet obtained.

/WMode 0 def

1 begincodespacerange

endcodespacerange

1 begincidrange
0
endcidrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end

%%EndResource
%%EOF

And it is working !!! Woot !

Mots-clés: mac folder icon, mac folder, thomas genin, mac applications icon, applications icon mac
Posted in Command Line | Tagged , , , , , , , , , | Leave a comment

Google Chrome : see thumbnail of your current tabs

Google Chrome logo

Google Chrome logo

Firefox 4 ship with the feature Tab Group ( previously Tab Candy ) which allow you to see and manage all your tabs in a smart and beautiful way.

Google Chrome has the same feature since version 8 if I’m not wrong. you can see a thumbnail of your current tab and easily move to one with a smooth animation. But this feature is hidden and you need to turn a flag to enable it.
Continue reading

Mots-clés: mac applications icon, google chrome thumbnails, applications folder mac terminal, mac folder, chrome tabs recent thumbnail
Posted in Google Chrome | Tagged , , , , , , , , , | Leave a comment

qunit and Rhino : JavaScript unit test in the console

If you are wondering if it is possible to use qunit and rhino, the answer is : yes you can.

  1. download Rhino
  2. download qunit-cli
  3. download qunit
  4. Unzip every thing
  5. Go in your qunit directory, and copy the directory qunit and test
  6. Paste them in qunit-cli/qunit
  7. qunit directory structure

    qunit directory structure

  8. Now open your terminal / console and move into qunit-cli/rhino
  9. Run the command to test that it is working
  10. java -cp ../../rhino1_7R2/js.jar org.mozilla.javascript.tools.shell.Main -opt -1 suite.js
    
  11. TADAAAA
  12. qunit rhino output

    qunit rhino output

  13. Edit qunit-cli/rhino/suite.js to load your source files ( at the top ) and your test files ( at the bottom )

You can also change the formating of the output by editing the suite.js file and using the right functions.

Note:
You should consider the creation of an alias to run the command :

export RHINO_HOME="~/development/rhino1_7R2"
alias js="java -cp $RHINO_HOME/js.jar org.mozilla.javascript.tools.shell.Main -opt -1"
alias jsd="java -cp $RHINO_HOME/js.jar org.mozilla.javascript.tools.debugger.Main"

Links:
http://twoguysarguing.wordpress.com/2010/11/02/make-javascript-tests-part-of-your-build-qunit-rhino/
https://github.com/asynchrony/qunit
https://github.com/benjaminplee/QUnit-CLI
http://www.mozilla.org/rhino/download.html
http://docs.jquery.com/Qunit

Mots-clés: rhino javascript, QUnit console, qunit rhino, qunit download, qunit cli
Posted in JavaScript | Tagged , , , , , , , , , | 2 Comments

jQuery conf 2011 San Francisco

jQuery conference San Francisco 2011 badge and Tshirt

jQuery conference San Francisco 2011 badge and Tshirt

I was there. It was ok. Some great talks and some other less good ( no offense ).

Mots-clés: jquery, jquery t-shirt, jquery tshirts
Posted in jQuery | Tagged , , , , , , , , , | Leave a comment

A Google Chrome toolbar

When you build a Google Chrome extension, you have only 2 UI hooks.

The browser action on the top right corner of the browser.

Browser Action icon

Browser Action icon

Or the page action at the right of the address bar

Page Action icon

Page Action icon

So how can you create a toolbar ?

Well Google Chrome provide you “content scripts“. These scripts are running in the parallel of the page. So this script can manipulate the DOM of the page. So we can inject something in the page. And if this something is an iframe, we could inject a “page” without worrying about JavaScript or CSS collision. And this iframe can be host on a server or in the extension. In this case you can use the chrome.extension.getURL method to get the path of the file.

Et voilà !

Mots-clés: google chrome toolbar, google chrome content script creating a toolbar
Posted in Google Chrome | Tagged , , , , , , , , , | Leave a comment

Giant Table is dead, long live jQuery UI !

Hey,

jQuery UI logo

jQuery UI logo


Last week, the jQuery UI team made a great announcement : they are finally going to include into the core a plugin to do table manipulation.
http://blog.jqueryui.com/2011/02/unleash-the-grid/

I did in the past a jQuery plugin to do that. Here is the problem I tried to solve: when you have an HTML table with thousand of lines, it is very long to display, instable, impossible to search or to sort element. Even plugins like http://tablesorter.com/docs/ can’t do th job when you have 10 000 lines. Or they use a pager which give a bad user experience.

So tried to solve this problem and I succeed. Instead of displaying every thing, I keep the data in an array in the memory. Every operation will be done on this array : sorting, filtering, search, selection, …
And I just display the number of row that the screen can display.
I check every scroll event or action on the fake scrollbar I have create to update the display.

And it works well with 90 000 lines !!! \o/

My plugin also support plugins to change the behavior or to customize the display.

But I’m sur the jQuery team is going to do something awesome ! Be sur that I will look at their progress very closely and try to be involve into this.

Mots-clés: jquery ui table, jqueryui table, jquery ui dead, jquery long table, jqueryui dead?
Posted in jQuery | Tagged , , , , , , , , , | Leave a comment

Mac OS Terminal – How to easily repeat a command with sudo

Terminal icon

Terminal icon

Very often, you need to repeat the previous command but with more parameters, or to use sudo.

Look at this example: I want to delete a file, but it own by an other user.

rm delete a file

rm delete a file

I’m sur that I can delete the file, so I have to use the sudo command before the rm command.
Continue reading

Mots-clés: shortcut repeat command mac, repeat last terminal command, repeat command on mac, repeat terminal command mac, mac os terminal
Posted in Mac OS Terminal | Tagged , , , , , , , , , | Leave a comment

Mac OS – Get an application icon in high resolution

Dashboard icon

Dashboard icon


If you want to get the icon for a specific Mac OS application, you have to follow the same kind of path than for the system icon.

But with some difference. In this how to, I’m going to get the icon for the Dashboard application.
Continue reading

Mots-clés: macos "application/icon", application icon
Posted in Mac OS | Tagged , , , , , , , , , | 1 Comment

Mac OS – How to get Mac OS icon in full resolution

How you notice that when you change the size of your icon in your folder, they always are beautiful, even when the size in very big ? And there is a lot of details on them ? Like mirror effects, shadow ?
Look at the Application Folder in full res :

Applications Folder Icon

Applications Folder Icon

Where is it store ?
Continue reading

Mots-clés: application icon for mac, content icon png, Mac folder icon png, High resolution icon for Folder, applications folder png
Posted in Mac OS | Tagged , , , , , , , , , | 1 Comment

Mac OS Terminal – Copy output of a command directly to the clipboard

Terminal icon

Terminal icon

Sometimes, when you use the command-line, you need to copy the output to send it by email for example.
But when there is many many lines, it can be very difficult !

So I found this small command which can be handy:
Continue reading

Mots-clés: mac os terminal copy command
Posted in Mac OS Terminal | Tagged , , , , , , , , , | Leave a comment