Showing posts with label PDF. Show all posts
Showing posts with label PDF. Show all posts

Monday, September 05, 2011

Running BIRT Reports in Tomcat

Context: You have database and you need to do data analysis: draw charts, build some tables, calculate totals, etc. You want it all to be available over the web and secured with a password.

Your database is any JDBC-supported database (I use MySQL 5.1.49).
Your server is running any OS where Java can run (I use Ubuntu Linux 10.10 available through SSH).

I will show how to implement this using Eclipse BIRT 3.7.

Developer Environment
  1. Download "Eclipse IDE for Java and Report Developers" package here.
    Unzip to install.
  2. Design new report (I created sales.rptdesign). This is really straightforward.
JDBC Driver. You will need MySQL JDBC driver to create Data Source for report. I got mysql-connector-java-5.1.17-bin.jar here.
Installing the driver in BIRT designer is easy using "Manage drivers..." dialog. But you will probably have problems deploying it to the runtime.

Fonts. You probably won't have any problems with fonts in BIRT designer. And again you will likely have problems with fonts in runtime.

Connection Profile Store. With BIRT 3.7 you can use Connection Profiles to hold database connections. After you've finished designing and testing your report, double click report Data Source to bring properties dialog and create new connection profile store in there. Save it to some file (I saved to planet33_v2.xml).
Here's what I have in there:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<DataTools.ServerProfiles version="1.0">
    <profile autoconnect="No" desc=""
        id="ecc3bc60-d4fd-11e0-957a-e0e31b9a34ee" name="planet33_v2"
        providerID="org.eclipse.datatools.enablement.mysql.connectionProfile">
        <baseproperties>
            <property
                name="org.eclipse.datatools.connectivity.db.connectionProperties"
                value="" />
            <property name="org.eclipse.datatools.connectivity.db.savePWD"
                value="true" />
            <property name="org.eclipse.datatools.connectivity.drivers.defnType"
                value="org.eclipse.datatools.enablement.mysql.5_1.driverTemplate" />
            <property name="jarList"
                value="/usr/local/share/mysql-connector-java-5.1.17-bin.jar" />
            <property name="org.eclipse.datatools.connectivity.db.username"
                value="your_username" />
            <property name="org.eclipse.datatools.connectivity.db.driverClass"
                value="com.mysql.jdbc.Driver" />
            <property name="org.eclipse.datatools.connectivity.db.databaseName"
                value="planet33_v2" />
            <property name="org.eclipse.datatools.connectivity.db.password"
                value="your_password" />
            <property name="org.eclipse.datatools.connectivity.db.version"
                value="5.1" />
            <property name="org.eclipse.datatools.connectivity.db.URL"
                value="jdbc:mysql://127.0.0.1:3306/planet33_v2" />
            <property name="org.eclipse.datatools.connectivity.db.vendor"
                value="MySql" />
        </baseproperties>
        <org.eclipse.datatools.connectivity.versionInfo>
            <property name="server.version" value="5.1.49" />
            <property name="technology.name.jdbc" value="JDBC" />
            <property name="server.name" value="MySQL" />
            <property name="technology.version.jdbc" value="4.0.0" />
        </org.eclipse.datatools.connectivity.versionInfo>
        <driverreference>
            <property name="driverName" value="MySQL JDBC Driver" />
            <property name="driverTypeID"
                value="org.eclipse.datatools.enablement.mysql.5_1.driverTemplate" />
        </driverreference>
    </profile>
</DataTools.ServerProfiles>

Note: I bet you can use JDNI data sources here (and I suppose this is even preferable because of connection pooling, etc.). Please, drop a few lines in comments below with instructions how you do this.

You can now edit XML source of you report and replace /report/data-sources with something like this:

<data-sources>
    <oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc.dbprofile"
        name="Planet33 V2 Data Source" id="359">
        <property name="OdaConnProfileName">planet33_v2</property>
        <property name="OdaConnProfileStorePath">../conf/planet33_v2.xml</property>
    </oda-data-source>
</data-sources>

Several things to mention here:
  • planet33_v2.xml (Connection Profile Store)
    • Check all properties and change them according to your connection.
    • Note the jarList property, there you should specify path(s) to where your JDBC drivers located (I copied driver that I've downloaded to /usr/local/share/mysql-connector-java-5.1.17-bin.jar).
    • When you create connection profile store file from designer it places property with name="org.eclipse.datatools.connectivity.driverDefinitionID". You should remove this property because of this issue.
  • sales.rptdesign (The Report)
    • You should keep value of ida-data-source@id attribute the same that was in your design.
    • Value of OdaConnProfileName should match value of DataTools.ServerProfiles/profile@name attribute from planet33_v2.xml.
    • Note that OdaConnProfileStorePath is relative path (see below). But you can keep it absolute if you want. 

Server Environment

(Note: I recommend to configure Tomcat instance on your developer machine first to make it easier to verify report settings, and then transfer the entire $CATALINA_HOME to production server. Of course, you can do all these steps on production server directly.)
  1. Download Apache Tomcat (any Java application server should be fine).
    Unzip to some folder (I used /usr/local/share/apache-tomcat-5.5.33/) -- this will be $CATALINA_HOME.
  2. Download BIRT "Runtime" package here.
    Copy birt.war (BIRT Web Viewer application) to $CATALINA_HOME/webapps.
  3. Edit $CATALINA_HOME/catalina.sh and paste these lines somewhere after JAVA_OPTS variable initialized (this prepares workspace for DTP plugin):
    
    
    java_io_tmpdir=$CATALINA_HOME/temp
    org_eclipse_datatools_workspacepath=$java_io_tmpdir/workspace_dtp
    mkdir -p $org_eclipse_datatools_workspacepath
    
    JAVA_OPTS="$JAVA_OPTS -Dorg.eclipse.datatools_workspacepath=$org_eclipse_datatools_workspacepath"
    
    
  4. Start Tomcat by running $CATALINA_HOME/startup.sh. After this BIRT Report Viewer application should be available by http://localhost:8080/birt. Also birt.war should be now extracted to $CATALINA_HOME/webapps/birt -- this will be $BIRT_HOME. You can now delete $CATALINA_HOME/webapps/birt.war.
  5. Copy planet33_v2.xml to $CATALINA_HOME/conf as (remember OdaConnProfileStorePath property in sales.rptdesign file?).
  6. Copy your sales.rtpdesign file to $BIRT_HOME.
At this point you should be able to execute the report by simply following the address http://localhost:8080/birt/frameset?__report=sales.rptdesign&__dpi=600.

Note the __dpi URL parameter -- it controls DPI of chart images rendered in HTML/PDF. You will probably want to modify like this it to increase image quality. Also note that if you set chart output format to SVG you will get vector graphics quality in PDF output.

Security

There are obvious reasons why you may want to keep your reports secure.

Besides that keep in mind that in BIRT Web Viewer application all reports sources (*.rptdesign files) available to user by request. Try navigating to http://localhost:8080/birt/sales.rptdesign and you'll see what I mean. I think this is a good reason, why you should use connection profile store (or at least JNDI data sources), because that files not available through HTTP.

Implementing simple (HTTP BASIC AUTH) security with Tomcat is pretty simple.

First, modify $BIRT_HOME/WEB-INF/web.xml, by adding this (you can change role names as you want):
<!-- Define a security constraint on this application -->
<security-constraint>
  <web-resource-collection>
    <web-resource-name>Entire Application</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <!-- This role is not in the default user directory -->
    <role-name>manager</role-name>
  </auth-constraint>
</security-constraint>             
<!-- Define the login configuration for this application -->
<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>BIRT Report Viewer</realm-name>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
  <description>
    The role that is required to log in to the BIRT Report Viewer
  </description>
  <role-name>manager</role-name>
</security-role>

You may also do the same for $CATALINA_HOME/conf/web.xml to secure all applications in this Tomcat instance.
Second, you should edit $CATALINA_HOME/conf/tomcat-users.xml to define user login and password.

Thats all, you're secured :) This is should be fine for most cases, but I would recommend you to read about HTTPS if your data is extremely secure.

Deploy to server

  1. Copy Tomcat to the server:
    Tip: Use scp command in terminal to transfer files from your machine to the server over SSH:
    scp /usr/local/share/apache-tomcat-5.5.33 dmitrygusev@planet33.ru:/usr/local/share/
  2. Copy JDBC Driver to the server:
    • Copy this driver to the same path as specified in the jarList property from planet33_v2.xml file.
    • DO NOT COPY this driver to $BIRT_HOME/WEB-INF/lib, because it may lead to ClassNotFoundException.
Fix file permissions. When you copy files over scp you may need to chmod them to grant read/execute access. This should fix it:

chmod a+r /usr/local/share/mysql-connector-java-5.1.17-bin.jar
chmod -R a+r /usr/local/share/apache-tomcat-5.5.33/
chmod a+x /usr/local/share/apache-tomcat-5.5.33/bin/*.sh

Now you should be able to start tomcat and run reports on the server.

Fonts. BIRT PDF output doesn't work good for Russian fonts out-of-the-box, because of licensing issues with fonts. One simple solution to fix this is:
  1. Get the *.ttf font files you need (you can copy them from any Windows installation, look in c:\Windows\Fonts). These 8 files should be enough in most cases (these are "Arial" and "Times New Roman" fonts):

    arialbd.ttf  arialbi.ttf  ariali.ttf  arial.ttf
    timesbd.ttf  timesbi.ttf  timesi.ttf  times.ttf
  2. Copy these files to /usr/share/fonts/truetype (or any other place that is referenced from fontsConfig.xml).
  3. Don't forget to fix file permissions:
    chmod a+r /usr/share/fonts/truetype/*.ttf
  4. Reference the fonts from *.rptdesign (or configure font-aliases):
    /report/styles
    <style name="report" id="4">
        <property name="fontFamily">"Arial"</property>
        <property name="fontSize">9pt</property>
    </style>
    
  5. Restart Tomcat:
    • $CATALINA_HOME/bin/shutdown.sh
    • $CATALINA_HOME/bin/startup.sh
Russian Localization. I used this method to do it. Although you may want to try BIRT Language Packs.


Troubleshooting.

  • Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
    At least one of these environment variable is needed to run this program

    You should define JAVA_HOME variable. Execute this command before running Tomcat's *.sh files in terminal:

    export JAVA_HOME=/usr/bin/java
  • If you get OutOfMemoryError you may want to give JVM more memory. Edit $CATALINA_HOME/bin/catalina.sh to include this (see this thread on stackoverflow, and read more about JVM memory settings):

    JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx512m -XX:MaxPermSize=256m"
  • If you got OutOfMemoryError you most likely couldn't restart Tomcat using $CATALINA_HOME/bin/shutdown.sh script.

    To kill Tomcat instance use htop command in terminal. In htop interface select Tomcat process (this is /usr/lib/java), press 'k', select 9 SIGKILL in "Send signal" area, and press Enter. To exit htop press 'q'.
  • Executing report never stops. Tomcat process consumes all CPU resources.

    I've seen this situation when used charts in report and they were on page break. I fixed this by moving charts to other place (far from page break). Changing page size to avoid page breaks also fixes this issue.

Friday, January 15, 2010

Adobe Reader Team!

Сегодня вышло новое обновление Adobe Reader 8.2.0.
Как обычно, тихо и незаметно.
За все время сколько пользуюсь Reader'ом (с 2000 года, как только появился первый компьютер) ни разу не заглядывал в окошко Credits. Сегодня заглянул.

Оказывается в команде Adobe Reader'а почти 1000 человек! (971 если быть точным)

Может я никогда не уделял этому внимания, но по-моему это самая большая команда, про которую я слышал. Точнее я слышал про компании с несколькими десятками/сотнями разработчиков, но как-то в общем, без конкретики.

А тут в окошке Credits расписаны все команды и упомянут каждый член команды лично!



Решил ради интереса всех пересчитать, получилось целых 42 команды!

Между прочим, судя по (с) в окошке About, Reader'у уже 26-й год! (1984-2010)
Мы с ним почти ровесники :)

Желаю им и дальше расти и процветать!

p.s.




Team # of members
Team Engineering 141
Quality Engineering 113
Engineering Management 55
Release Engineering 5
Product Management 14
Marketing and Business Management 22
Acrobat Administration 5
Globalization 16
Prerelease Programs 5
User Interface 14
Additional Engineering 62
Additional Quality Engineering 40
Additional Engineering Management 57
Additional Product, Marketing, and Business Management 9
Core Tech Management 14
Core Tech Adobe Graphics Manager 7
Core Tech Adobe Graphics Manager Printing 7
Core Tech Adobe XML Engine 6
Core Tech Color Management 4
Core Type 8
Core Tech PDF Libraries 10
Core Tech Architecture 12
Core Tech Scripting 6
Core Tech AMT 50
Core Tech AMT Quality Engineering 18
Core Tech Metadata 4
Core Tech Sangam 4
Core Tech Quality Engineering 52
Core Tech Admins 8
Adobe Production Quality Engineering Team 20
Legal 7
Visual Design 6
Adobe Systems Japan 13
Adobe Systems China 4
Type 9
Technical and Customer Support 15
Developer Support 18
Client Services Support 26
Learning Resources 43
Information Technology 12
Packaging and Manufacturing 14
Adobe.com Web Team 16


Total 971

Wednesday, July 08, 2009

Повышение качества изображения при переводе из PDF в JPEG

Если использовать пример из предыдущего поста для перевода PDF в JPEG, можно заметить потерю качества изображения, особенно если оно сильно уменьшается в размерах, например, при создании thumbnails:





Слева результат работы Ghostscript (скачать файл Gordon_Moore_1965_Article.pdf, 820 КБ):

c:\Temp>"c:\Program Files\gs\gs8.64\bin\gswin32c.exe" -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r30 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192 -sOutputFile=page-%d.jpg Gordon_Moore_1965_Article.pdf

Справа - ImageMagick, набора программ для обработки изображений:

c:\Temp>"c:\Program Files\ImageMagick-6.5.4-Q16\convert.exe" -resize 255x330 Gordon_Moore_1965_Article.pdf output.jpg

Можно заметить, что ImageMagick справился с задачей лучше (на картинке сверху контуры изображения остались более четкими, а сетка на графике точно повторяет исходное расположение как в PDF).

Согласно документации, для перевода PDF файлов в графический формат, ImageMagick использует Ghostscript. Чтобы понять откуда разница в качестве посмотрим, с какими параметрами ImageMagick вызывает Ghostscript (я на время переименовал папку "c:\Program Files\gs", чтобы ImageMagick не смог найти Ghostscript):

c:\Temp>"c:\Program Files\ImageMagick-6.5.4-Q16\convert.exe" -resize 255x330 Gordon_Moore_1965_Article.pdf output.jpg
convert.exe: `%s': %s "C:/Program Files/gs/gs8.64/bin/gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dUseCIEColor "-sOutputFile=C:/Users/DMITRY~1/AppData/Local/Temp/magick-zgPdpP6n" "-fC:/Users/DMITRY~1/AppData/Local/Temp/magick-xyf_86Fy" "-fC:/Users/DMITRY~1/AppData/Local/Temp/magick-ETtA_r9y" @ utility.c/SystemCommand/1880.
convert.exe: Postscript delegate failed `Gordon_Moore_1965_Article.pdf': No such file or directory @ pdf.c/ReadPDFImage/611.
convert.exe: missing an image filename `output.jpg' @ convert.c/ConvertImageCommand/2772.


Помимо прочих параметров, основным отличием является использование специфического устройства вывода (-sDEVICE=bmpsep8). На основании входного файла ImageMagick определяет промежуточный формат, в который он должен перевести содержимое PDF без потери качества. Это может быть RAW-формат (например, pnmraw) или, как в примере, bmpsep8. Дальнейшие трансформации (например, изменение размера) ImageMagick производит на этом временном файле.

Известно, что RAW/BMP файлы имеют большой размер (пропорционально размеру канвы изображения), и даже если на выходе мы хотим получить файл размером 255x300, как в примере, промежуточный файл может быть гигантских размеров. Поэтому нужно быть осторожным при использовании такого метода конвертации, особенно если вы заведомо не знаете о содержимом ваших PDF-файлов.


Так, например, для PDF в 544 КБ (скачать можно здесь), размер промежуточного файла ImageMagick составляет 1,6 ГБ (!). На выходе получается JPEG на 8 КБ, при этом процедура конвертации занимает около 5 минут. Та же самая процедура с использованием Ghostscript + JPEG device занимает меньше секунды при размере выходного файла 4 КБ, но подбирать параметры масштабирования в данном случае приходится вручную. Результат представлен ниже (слева Ghostscript, справа - ImageMagick), о качестве судите сами.


GhostscriptImageMagick



При тестировании использовались Ghostscript 8.64 и ImageMagick 6.5.4-2-Q16.

P.S.
Список поддерживаемых Ghostscript devices можно найти здесь: http://www.gnu.org/software/ghostscript/devices.html.

В одном из следующих постов я расскажу как можно организовать пакетную печать PDF-документов в Windows, используя Ghostscript и устройство mswinpr2.

Wednesday, April 29, 2009

Использование Ghostscript для перевода PDF в JPEG

В одном из последних проектов я занимался пакетной обработкой pdf-документов: слияние (merge) документов и распознание 1D штрих-кодов (barcode recognition).

Хочу поделиться интересными, на мой взгляд, особенностями и ссылками на Open Source-проекты.

С первой задачей (merge документов) отлично справился PDFsharp - Open Source-проект со свободной лицензией и с достаточно простым и удобным API (.Net).

Со штрих-кодами оказалось немного сложнее. Дело в том, что основной формат документов для "читалок" - файлы изображений (jpeg, png, tiff и т.д.), а перевести PDF в картинку оказалось не так просто...

Мы решили эту задачу с помощью Ghostscript - Open Source (GPL License) интерпретатор языка PostScript и пакет для работы с PDF.

Вообще говоря, перевести PDF в картинку, используя Ghostscript, можно одной командой, примерно так:


c:\Temp>c:\dev\bin\gs\gs8.64\bin\gswin32c.exe -q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192 -sOutputFile=page-%d.jpg mydocument.pdf


На выходе должно быть несколько файлов (по одному на страницу): в данном случае page-1.jpg, page-2.jpg и т.д.

Проблемы начинаются, если PDF-документ содержит экзотические шрифты (например, IDAutomationHC39M.ttf - шрифт штрих-кода Code39), или если документ был создан при помощи MS Reporting Services или другой программы, которая по тем или иным причинам не включает используемые шрифты в выходной PDF-файл (PDF fonts embedding).

Наш PDF был именно такой:



В результате во время рендеринга у меня возникла такая ошибка:


Error: /undefined in findresource
Operand stack:
--nostringval-- --dict:7/16(L)-- F14 10.0 --dict:5/5(L)-- --dict:5/5(L)-- TimesNewRoman,Bold --dict:11/12(ro)(G)-- --nostringval-- CIDFontObject --dict:6/6(L)-- --dict:6/6(L)-- Adobe-Identity
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-- 3 1 2 --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-- --nostringval-- %loop_continue
Dictionary stack:
--dict:1156/1684(ro)(G)-- --dict:1/20(G)-- --dict:74/200(L)-- --dict:74/200(L)-- --dict:106/127(ro)(G)-- --dict:278/300(ro)(G)-- --dict:22/25(L)-- --dict:4/6(L)-- --dict:21/40(L)-- --dict:10/13(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.64: Unrecoverable error, exit code 1


Ошибка связана с тем, что у меня на компьютере нет шрифта TimesNewRoman,Bold.

В Интернете все упоминания о подобных ошибках связаны с использованием японского или корейского шрифтов, но у меня в документе находится обычный английский текст.

Обратите также внимание на кодировку шрифта: Identity-H. Из того, что мне удалось выяснить, эта кодировка говорит о том, что используемый шрифт, вообще говоря, не существует, и в документе используются только коды символов. Для отображения символов, соответствующих этим кодам Ghostscript'у нужно "подсунуть" шрифт с аналогичной таблицей символов. Как это сделать описано в документации Ghostscript (см. CID Font Substitution).

В кратце, в файл c:\dev\bin\gs\gs.8.64\lib\cidfmap (этот файл не будет создан, если при установке вы не отметили галочку "Use Windows TrueType fonts for Chinese, Japanese and Korean"; в этом случае создайте его сами) нужно добавить инструкцию, которая будет указывать, какой шрифт использовать на самом деле вместо того, который указан в PDF.

У меня заняло некоторое время, чтобы подобрать параметры для этой инструкции. Дело в том, что нельзя заменить шрифт на любой другой (например, я не могу заменить мой английский шрифт на японский или корейский). Кроме как в исходниках я нигде больше не смог найти, что нужно подставить на место /CSI Ordering. В итоге получилась такая строчка:


/TimesNewRoman,Bold << /FileType /TrueType /Path (timesbd.ttf) /SubfontID 0 /CSI [(Unicode) 0] >> ;


Файл timesbd.ttf я взял из папки C:\Windows\fonts. Есть некоторые особенности использования абсолютных и относительных путей файла с использованием опции -dSAFER. Если указана эта опция, то путь к имени файла шрифта должен быть относительным. Поэтому я скопировал его в папку c:\dev\bin\gs\fonts (в моем случае именно она используется для поиска шрифтов по умолчанию).

Чтобы посмотреть детальные логи работы Ghostscript, нужно убрать опцию -q, и вот что мы увидим:


GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Substituting font Helvetica for IDAutomationHC39M.
Loading NimbusSanL-Regu font from %rom%Resource/Font/NimbusSanL-Regu... 2875432 1123207 25112624 23807796 3 done.
Loading NimbusRomNo9L-Regu font from %rom%Resource/Font/NimbusRomNo9L-Regu... 2912216 1253685 25112624 23819376 3 done.
Loading NimbusRomNo9L-Medi font from %rom%Resource/Font/NimbusRomNo9L-Medi... 3069576 1402046 25132720 23832802 3 done.
Page 2
Substituting font Helvetica for IDAutomationHC39M.
Loading NimbusSanL-Bold font from %rom%Resource/Font/NimbusSanL-Bold... 3166648 1539642 25152816 23854836 3 done.
Loading a TT font from C:\dev\bin\gs\fonts/timesbd.ttf to emulate a CID font TimesNewRoman,Bold ... Done.


Ошибка пропала, но при рендеринге штрих-кода вместо "правильного" шрифта использовался Helvetica. Это связано с тем, что Ghostscript не может использовать системные шрифты по-умолчанию. Эту проблему я решил копированием файлов шрифтов (IDAutomationHC39M.ttf и IDAutomationHC39M_0.ttf) в папку C:\dev\bin\gs\fonts и указанием ключика -sFONTPATH="C:\dev\bin\gs\fonts".

В результате получаем:


c:\Temp>c:\dev\bin\gs\gs8.64\bin\gswin32c.exe -sFONTPATH="C:\dev\bin\gs\fonts" -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192 -sOutputFile=page-%d.jpg mydocument.pdf

GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Scanning c:\dev\bin\gs\fonts for fonts... 3 files, 3 scanned, 2 new fonts.
Loading IDAutomationHC39M font from c:\dev\bin\gs\fonts/IDAutomationHC39M.ttf... 2868992 1068452 25189416 23882410 3 done.

Loading NimbusRomNo9L-Regu font from %rom%Resource/Font/NimbusRomNo9L-Regu... 2885680 1201118 25209512 23896006 3 done.
Loading NimbusRomNo9L-Medi font from %rom%Resource/Font/NimbusRomNo9L-Medi... 3022944 1346357 25209512 23905928 3 done.
Loading NimbusSanL-Regu font from %rom%Resource/Font/NimbusSanL-Regu... 3120016 1438677 25531048 24170429 3 done.
Page 2
Loading IDAutomationHC39M font from c:\dev\bin\gs\fonts/IDAutomationHC39M.ttf... 3120016 1443415 25189416 23883485 3 done.
Loading NimbusSanL-Bold font from %rom%Resource/Font/NimbusSanL-Bold... 3217088 1539692 25229608 23926657 3 done.
Loading a TT font from C:\dev\bin\gs\fonts/timesbd.ttf to emulate a CID font TimesNewRoman,Bold ... Done.


Хочется отметить еще одну полезную опцию Ghostscript: -r150. Если этот параметр не указывать, то рендеринг будет происходить в мастшабе по умолчанию, в результате чего из-за маленьких размеров не распознавался штрих-код. Увеличение размера до 150 пикселей на дюйм (-r150) это исправило.

Аналогично можно также уменьшать размер картинки, например, чтобы сделать thumbnails (см. заметки по качеству перевода PDF в JPEG).