PDF to Image Converter(画像に変換) サンプル

PDF を画像に変換 概要

「PDF to Image Converter」は、PDF文書を単一(TIFF、JPEG他)または、複数ページの画像(TIFF)または、画像化されたPDFに変換する機能をアプリケーションに追加するライブラリ(API)です。

価格見積り

機能、特徴
  • 単一または複数の画像を生成
  • 画像フォーマット:
    TIFF、JPEG、PNG、GIF、BMP、EPS、JBIG2、JPEG2000、Extended JPEG2000、PBM
  • PDF文書作成:
    ラスタライズ(画像化)されたPDF
  • PDF文書の復号と暗号化可能
  • 画像フィルター(エイリアスやモアレを低減):
    スーパーサンプリング、バイキュービック、バイリニア
  • 色空間:
    グレースケール、RGB、CMYK、インデックス
  • 解像度、色数 設定
  • 圧縮画像:
    JPEG(非可逆圧縮)、JPEG2000、JBG2(ロスレス圧縮可能)
  • 画質やサイズ(非可逆圧縮)の最適化
  • ハーフトーン(ディザ)方式:
    Floyd Steinberg、Halftone Block、Halftone Continuous、Atkinson)
  • 微細なテキスト文字の線幅を太くする

無償評価版(リンク先は英語)
以下のダウンロード(無償)では完全なソースコードライブラリおよびライセンスキーを入手できます。
製品マニュアル: ライブラリコマンドライン

無償評価版のダウンロードとインストール


C#開発環境 C/C++開発環境 Python開発環境
ライブラリ(評価版API)は無償でダウンロードできます。
ファイルをダウンロードしてから適当なフォルダーに解凍してください。
以下のようなフォルダーができあがりますので、適宜ご利用ください。
binライブラリやライセンスマネージャーなど
doc使用説明書やjavadocなど
includeC/C++用のヘッダー(.h)ファイル
jar Pdf2ImgAPI.jar(Javaのラッパー)
libC/C++用のlibファイル
samples各種開発言語のサンプル
サンプルの実行前に参照設定などを行ってください。
無償評価版と共にダウンロードしたライセンスキーを bin/LicenseManager.exeを使って登録してください。
C#開発環境 C/C++開発環境 Python開発環境
1.Zipファイルをダウンロードする場合
ライブラリ(評価版API)は無償でダウンロードできます。
ファイルをダウンロードしてから適当なフォルダーに解凍してください。
以下のようなフォルダーができあがりますので、適宜ご利用ください。
binライブラリやライセンスマネージャーなど
doc使用説明書やjavadocなど
includeC/C++用のヘッダー(.h)ファイル
jar Pdf2ImgAPI.jar(Javaのラッパー)
libC/C++用のlibファイル
samples各種開発言語のサンプル
サンプルの実行前に参照設定などを行ってください。
無償評価版と共にダウンロードしたライセンスキーを bin/LicenseManager.exeを使って登録してください。
2.NuGetでインストールする場合
nuget.org から PdfTools.Pdf2ImageR2 をインストールします。

  NuGetでのインストール手順

この場合は参照設定などの必要はありません。
評価用ライセンスキーは 以下のソースコードまたは、こちら から取得してください。

サンプルと解説

C#開発環境 C/C++開発環境 Python開発環境

以下のC/C++サンプルで、各機能の実装を確認してください。
JPEG画像に変換するサンプルコード
PNG画像に変換するサンプルコード
複数ページTIFF画像に変換するサンプルコード
複数ページTIFF FAX画像に変換するサンプルコード
C#開発環境 C/C++開発環境 Python開発環境

以下のC#サンプルで、各機能の実装を確認してください。
JPEG画像に変換するサンプルコード
PNG画像に変換するサンプルコード
複数ページTIFF画像に変換するサンプルコード
複数ページTIFF FAX画像に変換するサンプルコード
C#開発環境 C/C++開発環境 Python開発環境

以下のPythonサンプルで、各機能の実装を確認してください。
JPEG画像に変換するサンプルコード
PNG画像に変換するサンプルコード
複数ページTIFF画像に変換するサンプルコード
複数ページTIFF FAX画像に変換するサンプルコード

PDF文書をJPEG画像ファイルに変換

PDF文書の各ページを単一のJPEG画像ファイルに変換するサンプルです。JPEG圧縮の品質を指定することができます。

C# C/C++ Python ダウンロード
// 初期化
pConverter = Pdf2ImgCreateObject();

// 入力ファイルをオープン
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
    _tprintf(_T("入力ファイル %s をオープンできません。 %s (エラーコード: 0x%08x).\n"),
        szOutputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

// 画像品質を指定
Pdf2ImgSetImageQuality(pConverter, iQuality);

// 入力PDFの全ページを繰り返し、その都度JPEG画像ファイルを作成
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
    // 出力ファイルの名前と拡張子
    _tcstok(szOutputPath, _T("."));
    _stprintf(szImagePath, _T("%s%d.jpg"), szOutputPath, iPage);

    // 出力のJPEG画像ファイルを生成
    if (!Pdf2ImgCreateImage(pConverter, szImagePath))
    {
        _tprintf(_T("出力画像ファイル %s を生成できません。 %s (エラーコード: 0x%08x).\n"),
            szInputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }

    // PDFのページを出力ファイルにJPEGレンダリング
    if (!Pdf2ImgRenderPage(pConverter, iPage))
    {
        _tprintf(_T("PDFファイル %s のページ %d をJPEGファイル %s にレンダリングできません。 %s (エラーコード: 0x%08x).\n"),
            szInputPath, iPage, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }

    // 出力ファイルをクローズ
    if (!Pdf2ImgCloseImage(pConverter))
    {
        _tprintf(_T("出力ファイル %s をクローズできません。 %s (エラーコード: 0x%08x).\n"),
            szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }
}
_tprintf(_T("終了\n"));

cleanup:
Pdf2ImgClose(pConverter);
Pdf2ImgDestroyObject(pConverter);
Pdf2ImgUnInitialize();

return iReturnValue;
Pdf2ImgCreateObject変換オブジェクト
Pdf2ImgOpenPDFファイルをオープン
 第一引数:変換オブジェクト
 第二引数:PDFファイルパス名
 第三引数:パスワード
Pdf2ImgSetImageQuality画像品質を指定
 第一引数:変換オブジェクト
 第二引数:画像品質[%]
Pdf2ImgRenderPage指定のページをレンダリング
 第一引数:変換オブジェクト
 第二引数:ページ番号
Pdf2ImgCloseImagePDFファイルをクローズ
 第一引数:変換オブジェクト
Pdf2ImgDestroyObject変換オブジェクトを削除
 第一引数:変換オブジェクト
Pdf2ImgUnInitialize終了

C# C/C++ Python ダウンロード
// 初期化
using (Converter converter = new Converter())
{
    // 入力ファイルをオープン
    if (!converter.Open(inputPath, ""))
        throw new Exception(String.Format("入力ファイル {0} をオープンできません。 " + 
            "{1} (エラーコード: 0x{2:x}).", inputPath, converter.ErrorMessage, converter.ErrorCode));

    // 画像品質を指定
    converter.ImageQuality = quality;

    // 入力PDFの全ページを繰り返し、その都度JPEG画像ファイルを作成
    for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
    {
        // 出力ファイルの名前と拡張子
        string imagePath = Path.ChangeExtension(outputPath, null) + pageNo.ToString() + ".jpg";

        // 出力のJPEG画像ファイルを生成
        if (!converter.CreateImage(imagePath))
            throw new Exception(String.Format("出力画像ファイル {0} を生成できません。 {1} " + 
                "(エラーコード: 0x{2:x}).", imagePath, converter.ErrorMessage,
                converter.ErrorCode));

        // PDFのページを出力ファイルにJPEGレンダリング
        if (!converter.RenderPage(pageNo))
            throw new Exception(String.Format("PDFファイル {1} のページ {0} をJPEGファイル {2} にレンダリングできません。" + 
                " {3} (エラーコード: 0x{4:x}).", pageNo, inputPath, imagePath, 
                converter.ErrorMessage, converter.ErrorCode));

        // 出力ファイルをクローズ
        if (!converter.CloseImage())
            throw new Exception(String.Format("出力ファイル {0} をクローズできません。 {1} " + 
                "(エラーコード: 0x{2:x}).", imagePath, converter.ErrorMessage, converter.ErrorCode));
    }
}
Converter変換オブジェクト
OpenPDFファイルをオープン
 第一引数:PDFファイルパス名
 第二引数:パスワード
ImageQuality画像品質[%]を設定
PageCount現在PDFのページ数
CreateImage出力ファイルを生成
 第一引数:出力画像ファイルパス名
RenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:ページ番号
CloseImage画像ファイルをクローズ

C# C/C++ Python ダウンロード
import PdfToImage
import re

try:
    p2i = PdfToImage.ConverterInterface("1-GF3E5-fRtrEEf-hP4tPAa-aqKTPAE")
except Exception as e:
    print(e)
    exit()

inputPath = "in.pdf";
outputPath = re.split('\.[Pp][Dd][Ff]$', inputPath)

# 入力ファイルをオープン
if not p2i.Open(inputPath):
    print('入力ファイル', inputPath, 'をオープンできません。')
else:
    # 画像品質を指定
    p2i.ImageQuality = 75

    # 入力PDFの全ページを繰り返し、その都度JPEG画像ファイルを作成
    for iPage in range(1, p2i.PageCount+1):
        # 出力ファイルの名前と拡張子
        imagePath = '{}{}.jpg'.format(outputPath[0],iPage)

        # 出力のJPEG画像ファイルを生成
        if not p2i.CreateImage(imagePath):
            print('出力画像ファイル', imagePath,'を生成できません。')
        else:
            # PDFのページを出力ファイルにJPEGレンダリング
            if not p2i.RenderPage(iPage):
                print('PDFファイル', inputPath,'のページ', iPage,'をJPEGファイル', imagePath,'にレンダリングできません。')

            # 出力ファイルをクローズ
            if not p2i.CloseImage():
                print('出力ファイル', imagePath,'をクローズできません')

print('終了')
ConverterInterface変換オブジェクト
 引数にライセンスキーを指定します。
OpenPDFファイルをオープン
 第一引数:PDFファイルパス名
 第二引数:パスワード
ImageQuality画像品質[%]を設定
PageCount現在PDFのページ数
CreateImage出力ファイルを生成
 第一引数:出力画像ファイルパス名
RenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:ページ番号
CloseImage画像ファイルをクローズ

PDF文書をPNG画像ファイルに変換

PDF文書の各ページを単一のPNG画像ファイルに変換するサンプルです。

C# C/C++ Python ダウンロード
// 初期化
pConverter = Pdf2ImgCreateObject();

// 入力ファイルをオープン
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
    _tprintf(_T("入力ファイル %s をオープンできません。 %s (エラーコード: 0x%08x).\n"),
        szOutputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

// 入力PDFの全ページを繰り返し、その都度PNG画像ファイルを作成
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
    // 出力ファイルの名前と拡張子
    _tcstok(szOutputPath, _T("."));
    _stprintf(szImagePath, _T("%s%d.png"), szOutputPath, iPage);

    // 出力のPNG画像ファイルを生成
    if (!Pdf2ImgCreateImage(pConverter, szImagePath))
    {
        _tprintf(_T("出力ファイル %s を生成できません。 %s (エラーコード: 0x%08x).\n"),
            szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }

    // PDFのページを出力ファイルにPNGレンダリング
    if (!Pdf2ImgRenderPage(pConverter, iPage))
    {
        _tprintf(_T("PDFファイル %s のページ %d をJPEGファイル %s にレンダリングできません。 %s (エラーコード: 0x%08x).\n"),
            szInputPath, iPage, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }

    // 出力ファイルをクローズ
    if (!Pdf2ImgCloseImage(pConverter))
    {
        _tprintf(_T("出力ファイル %s をクローズできません。 %s (エラーコード: 0x%08x).\n"),
            szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }
}
_tprintf(_T("終了\n"));

cleanup:
Pdf2ImgClose(pConverter);
Pdf2ImgDestroyObject(pConverter);
Pdf2ImgUnInitialize();

return iReturnValue;
}
Pdf2ImgCreateObject変換オブジェクト
Pdf2ImgOpenPDFファイルをオープン
 第一引数:変換オブジェクト
 第二引数:PDFファイルパス名
 第三引数:パスワード
Pdf2ImgGetPageCount現在PDFのページ数を取得
 第一引数:変換オブジェクト
Pdf2ImgCreateImage出力ファイルを生成
 第一引数:変換オブジェクト
 第二引数:出力画像ファイルパス名
Pdf2ImgRenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:変換オブジェクト
 第二引数:ページ番号
Pdf2ImgCloseImage画像ファイルをクローズ
 第一引数:変換オブジェクト
Pdf2ImgClosePDFファイルをクローズ
 第一引数:変換オブジェクト
Pdf2ImgDestroyObject変換オブジェクトを削除
 第一引数:変換オブジェクト
Pdf2ImgUnInitialize終了

C# C/C++ Python ダウンロード
// 初期化
using (Converter converter = new Converter())
{
    // 入力ファイルをオープン
    if (!converter.Open(inputPath, ""))
        throw new Exception(String.Format("入力ファイル {0} をオープンできません。 " + 
            "{1} (エラーコード: 0x{2:x}).", inputPath, converter.ErrorMessage, converter.ErrorCode));

    // 入力PDFの全ページを繰り返し、その都度PNG画像ファイルを作成
    for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
    {
        // 出力ファイルの名前と拡張子
        string imagePath = Path.ChangeExtension(outputPath, null) + pageNo.ToString() + ".png";

        // 出力のPG画像ファイルを生成
        if (!converter.CreateImage(imagePath))
            throw new Exception(String.Format("出力画像ファイル {0} を生成できません。 {1} " + 
                "(エラーコード: 0x{2:x}).", imagePath, converter.ErrorMessage, converter.ErrorCode));

        // PDFのページを出力ファイルにPNGレンダリング
        if (!converter.RenderPage(pageNo))
            throw new Exception(String.Format("PDFファイル {1} のページ {0} をJPEGファイル {2} にレンダリングできません。 " + 
                " {3} (エラーコード: 0x{4:x}).", pageNo, inputPath, imagePath,
                converter.ErrorMessage, converter.ErrorCode));

        // 出力ファイルをクローズ
        if (!converter.CloseImage())
            throw new Exception(String.Format("出力ファイル {0} をクローズできません。 {1} " + 
                "(エラーコード: 0x{2:x}).", imagePath, converter.ErrorMessage, converter.ErrorCode));
    }
}
Converter変換オブジェクト
OpenPDFファイルをオープン
 第一引数:PDFファイルパス名
 第二引数:パスワード
PageCount現在PDFのページ数
CreateImage出力ファイルを生成
 第一引数:出力画像ファイルパス名
RenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:ページ番号
CloseImage画像ファイルをクローズ

C# C/C++ Python ダウンロード
import re
import PdfToImage

try:
    p2i = PdfToImage.ConverterInterface("1-GF3E5-fRtrEEf-hP4tPAa-aqKTPAE")
except Exception as e:
    print(e)
    exit()

inputPath = "in.pdf";
outputPath = re.split('\.[Pp][Dd][Ff]$', inputPath)

# 入力ファイルをオープン
if not p2i.Open(inputPath):
    print('入力ファイル', inputPath, 'をオープンできません。')
else:

    # 入力PDFの全ページを繰り返し、その都度PNG画像ファイルを作成
    for iPage in range(1, p2i.PageCount+1):
        # 出力ファイルの名前と拡張子
        imagePath = '{}{}.png'.format(outputPath[0],iPage)

        # 出力のPNG画像ファイルを生成
        if not p2i.CreateImage(imagePath):
            print('出力画像ファイル', imagePath,'を生成できません。')
        else:
            # PDFのページを出力ファイルにPNGレンダリング
            if not p2i.RenderPage(iPage):
                print('PDFファイル', inputPath,'のページ', iPage,'をPNGファイル', imagePath,'にレンダリングできません。')

print('終了')
ConverterInterface変換オブジェクト
 引数にライセンスキーを指定します。
OpenPDFファイルをオープン
 第一引数:PDFファイルパス名
 第二引数:パスワード
PageCount現在PDFのページ数
CreateImage出力ファイルを生成
 第一引数:出力画像ファイルパス名
RenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:ページ番号
CloseImage画像ファイルをクローズ

PDF文書を複数ページTIFF画像ファイルに変換

PDF文書の全ページを複数ページTIFF画像ファイルに変換します。
TIFF画像には圧縮アルゴリズムを指定でき、JPEG圧縮を指定した場合は画像品質を指定できます。

C# C/C++ Python ダウンロード
// 初期化
pConverter = Pdf2ImgCreateObject();

// 入力ファイルをオープン
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
    _tprintf(_T("入力ファイル %s をオープンできません。 %s (エラーコード: 0x%08x).\n"),
        szInputPath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

// 出力ファイルの名前と拡張子
_tcstok(szOutputPath, _T("."));
_stprintf(szImagePath, _T("%s.tif"), szOutputPath);

// 圧縮アルゴリズムと画像品質を指定
Pdf2ImgSetCompression(pConverter, eCompression);
Pdf2ImgSetQuality(pConverter, iQuality);

// 出力のTIFF画像ファイルを生成
if (!Pdf2ImgCreateImage(pConverter, szImagePath))
{
    _tprintf(_T("出力ファイル %s を生成できません。 %s (エラーコード: 0x%08x).\n"),
        szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

// PDFの全ページを複数ページTIFF画像ファイルに変換
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
    // ページをTIFF画像にレンダリング
    if (!Pdf2ImgRenderPage(pConverter, iPage))
    {
        _tprintf(_T("PDFファイル %s のページ %d をTIFFファイル %s に出力できません。 %s (エラーコード: 0x%08x).\n"),
            szInputPath, iPage, szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }
}
// 出力ファイルをクローズ
if (!Pdf2ImgCloseImage(pConverter))
{
    _tprintf(_T("出力ファイル %s をクローズできません。 %s (エラーコード: 0x%08x).\n"),
        szImagePath, Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}
Pdf2ImgCreateObject変換オブジェクト
Pdf2ImgOpenPDFファイルをオープン
 第一引数:変換オブジェクト
 第二引数:PDFファイルパス名
 第三引数:パスワード
Pdf2ImgSetCompression画像の圧縮アルゴリズムを設定
 第一引数:変換オブジェクト
 第二引数:圧縮アルゴリズム
Pdf2ImgSetQuality画像の品質を設定
 第一引数:変換オブジェクト
 第二引数:画像品質[%]
Pdf2ImgCreateImage出力ファイルを生成
 第一引数:変換オブジェクト
 第二引数:出力画像ファイルパス名
Pdf2ImgGetPageCount現在PDFのページ数を取得
 第一引数:変換オブジェクト
Pdf2ImgRenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:変換オブジェクト
 第二引数:ページ番号
Pdf2ImgCloseImage画像ファイルをクローズ
 第一引数:変換オブジェクト

C# C/C++ Python ダウンロード
// 初期化
using (Converter converter = new Converter())
{
    // 入力ファイルをオープン
    if (!converter.Open(inputPath, ""))
        throw new Exception(String.Format("入力ファイル {0} をオープンできません。 {1} (エラーコード: {2}).",
            inputPath, converter.ErrorMessage, converter.ErrorCode));

    // 圧縮アルゴリズムと画像品質を指定
    converter.Compression = compression;
    converter.ImageQuality = quality;

    // 出力のTIFF画像ファイルを生成
    if (!converter.CreateImage(outputPath))
        throw new Exception(String.Format("出力ファイル  {0} を生成できません。 " +
            "{1} (エラーコード: {2}).", outputPath, converter.ErrorMessage, converter.ErrorCode));

    // PDFの全ページを複数ページTIFF画像ファイルに変換
    for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
    {
        // ページをTIFF画像にレンダリング
        if (!converter.RenderPage(pageNo))
            throw new Exception(String.Format("PDFファイル {1} のページ {0} をTIFFファイル {2} に出力できません。 " +
                " {3} (エラーコード: {4}).", pageNo, inputPath, outputPath,
                converter.ErrorMessage, converter.ErrorCode));
    }
    // 出力ファイルをクローズ
    if (!converter.CloseImage())
        throw new Exception(String.Format("出力ファイル {0} をクローズできません。 " +
            "{1} (エラーコード: {2}).", outputPath, converter.ErrorMessage, converter.ErrorCode));
}
Converter変換オブジェクト
OpenPDFファイルをオープン
 第一引数:PDFファイルパス名
 第二引数:パスワード
Compression画像の圧縮アルゴリズムを設定
 第一引数:変換オブジェクト
 第二引数:圧縮アルゴリズム
ImageQuality画像の品質を設定
 第一引数:変換オブジェクト
 第二引数:画像品質[%]
CreateImage出力ファイルを生成
 第一引数:出力画像ファイルパス名
PageCount現在PDFのページ数
RenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:ページ番号
CloseImage画像ファイルをクローズ

C# C/C++ Python ダウンロード
import PdfToImage

try:
    p2i = PdfToImage.ConverterInterface("1-GF3E5-fRtrEEf-hP4tPAa-aqKTPAE")
except Exception as e:
    print(e)
    exit()

# 入力ファイルをオープン
if not p2i.Open(inputPath):
    print('入力ファイル', inputPath, 'をオープンできません。')
else:

    # 圧縮アルゴリズムと画像品質を指定
    p2i.Compression = PdfToImage.Compression.eComprJPEG;
    p2i.ImageQuality = 90

    # 出力のTIFF画像ファイルを生成
    p2i.CreateImage('out.tiff')

    # PDFの全ページを複数ページTIFF画像ファイルに変換
    for pageNo in range(1, p2i.PageCount+1):
        p2i.RenderPage(pageNo)

    p2i.CloseImage()

print('終了')
ConverterInterface変換オブジェクト
 引数にライセンスキーを指定します。
OpenPDFファイルをオープン
 第一引数:PDFファイルパス名
 第二引数:パスワード
Compression画像の圧縮アルゴリズムを設定
 第一引数:変換オブジェクト
 第二引数:圧縮アルゴリズム
ImageQuality画像の品質を設定
 第一引数:変換オブジェクト
 第二引数:画像品質[%]
CreateImage出力ファイルを生成
 第一引数:出力画像ファイルパス名
PageCount現在PDFのページ数
RenderPage指定のページをレンダリングし、結果を出力ファイルに格納
 第一引数:ページ番号
CloseImage画像ファイルをクローズ

PDF文書をFAX画像ファイルに変換

PDF文書の全ページを2値(2色)の複数ページTIFF画像ファイルに変換するサンプルです。
2値化にあたってはFloyd-Steinberg手法でのディザ処理し、Faxの TIFF Class F を設定します。

C# C/C++ Python ダウンロード
// 初期化
pConverter = Pdf2ImgCreateObject();

// 入力ファイルをオープン
if (!Pdf2ImgOpen(pConverter, szInputPath, _T("")))
{
    _tprintf(_T("入力ファイル %s をオープンできません。 %s (エラーコード: 0x%08x).\n"), szInputPath,
        Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

// ディザ指定
Pdf2ImgSetDithering(pConverter, eDithering);
Pdf2ImgSetBitsPerPixel(pConverter, 1);

Pdf2ImgSetFitPage(pConverter, 1);
Pdf2ImgSetCenter(pConverter, 1);
TPDFRendererOption2 renderOptions = Pdf2ImgGetOptions2(pConverter);
renderOptions |= eOptionNoAntialiasing | eOptionUseBoxFilter | eOptionFitPaths;
Pdf2ImgSetOptions2(pConverter, renderOptions);
Pdf2ImgSetRotateMode(pConverter, eRotatePortrait);

// TIFF Class F (Fax) 指定
Pdf2ImgFaxHSetting(pConverter);

// 出力画像ファイル生成
if (!Pdf2ImgCreateImage(pConverter, szOutputPath))
{
    _tprintf(_T("出力画像ファイル %s を生成できません。 %s (エラーコード: 0x%08x).\n"), szOutputPath,
        Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

// PDFの全ページを複数ページTIFF画像ファイルに変換
for (int iPage = 1; iPage <= Pdf2ImgGetPageCount(pConverter); iPage++)
{
    // PDFのページを出力ファイルにレンダリング
    if (!Pdf2ImgRenderPage(pConverter, iPage))
    {
        _tprintf(_T("PDFファイル %s のページ %d をTIFFファイル %s に出力できません。 %s (エラーコード: 0x%08x).\n"),
            szInputPath, iPage, szOutputPath, Pdf2ImgGetErrorMessage(pConverter),
            Pdf2ImgGetErrorCode(pConverter));
        iReturnValue = 1;
        goto cleanup;
    }
}

// 出力ファイルをクローズ
if (!Pdf2ImgCloseImage(pConverter))
{
    _tprintf(_T("出力ファイル %s をクローズできません。 %s (エラーコード: 0x%08x).\n"), szOutputPath,
        Pdf2ImgGetErrorMessage(pConverter), Pdf2ImgGetErrorCode(pConverter));
    iReturnValue = 1;
    goto cleanup;
}

C# C/C++ Python ダウンロード
// 初期化
using (Converter converter = new Converter())
{
    // 入力ファイルをオープン
    if (!converter.Open(inputPath, ""))
        throw new Exception(String.Format("入力ファイル {0} をオープンできません。 " +
            "{1} (エラーコード: 0x{2:x}).", inputPath, converter.ErrorMessage, converter.ErrorCode));

    // ディザ指定
    converter.Dithering = dithering;
    converter.BitsPerPixel = 1;

    converter.FitPage = true;
    converter.Center = true;
    PDFRendererOption2 rendererOptions = converter.Options2;
    rendererOptions |= PDFRendererOption2.eOptionNoAntialiasing |
        PDFRendererOption2.eOptionUseBoxFilter | PDFRendererOption2.eOptionFitPaths;
    converter.Options2 = rendererOptions;
    converter.RotateMode = PDFRotateMode.eRotatePortrait;

    // TIFF Class F (Fax) 指定
    converter.FaxHSetting();

    // 出力画像ファイル生成
    if (!converter.CreateImage(outputPath))
        throw new Exception(String.Format("出力画像ファイル {0} を生成できません。 {1} " +
            "(エラーコード: 0x{2:x}).", outputPath, converter.ErrorMessage, converter.ErrorCode));

    // PDFの全ページを複数ページTIFF画像ファイルに変換
    for (int pageNo = 1; pageNo <= converter.PageCount; pageNo++)
    {
        // PDFのページを出力ファイルにレンダリング
        if (!converter.RenderPage(pageNo))
            throw new Exception(String.Format("PDFファイル {1} のページ {0} をTIFFファイル {2} に出力できません。" +
                " {3} (エラーコード: 0x{4:x}).", pageNo, inputPath, outputPath,
                converter.ErrorMessage, converter.ErrorCode));
    }

    // 出力ファイルをクローズ
    if (!converter.CloseImage())
        throw new Exception(String.Format("出力ファイル {0} をクローズできません。 {1} " +
            "(エラーコード: 0x{2:x}).", outputPath, converter.ErrorMessage, converter.ErrorCode));
}

C# C/C++ Python ダウンロード
import PdfToImage

try:
    p2i = PdfToImage.ConverterInterface("1-GF3E5-fRtrEEf-hP4tPAa-aqKTPAE")
except Exception as e:
    print(e)
    exit()

# 入力ファイルをオープン
if not p2i.Open(inputPath):
    print('入力ファイル', inputPath, 'をオープンできません。')
else:
    # ディザ指定他
    p2i.Dither = PdfToImage.Dithering.eDitheringFloydSteinberg
    p2i.BitsPerPixel = 1

    p2i.FitPage = True
    p2i.Center = True
    renderOptions = p2i.Options2
    renderOptions |= PdfToImage.RendererOption2.eOptionNoAntialiasing | PdfToImage.RendererOption2.eOptionUseBoxFilter | PdfToImage.RendererOption2.eOptionFitPaths
    p2i.Options2 = renderOptions
    p2i.RotateMode = PdfToImage.RotateMode.eRotatePortrait

    # TIFF Class F (Fax) 指定
    p2i.FaxHSetting()

    # 出力画像ファイル生成
    if not p2i.CreateImage("out.tif"):
        print('画像ファイル "out.tif" を生成できません')
    else:
        # PDFの全ページを複数ページTIFF画像ファイルに変換
        for iPage in range(1, p2i.PageCount+1):
            # PDFのページを出力ファイルにレンダリング
            if not p2i.RenderPage(iPage):
                print('PDFファイル ', inputPath, ' のページ ', iPage, ' をTIFFファイル out.tif に出力できません。')
        # 出力ファイルをクローズ
        if not p2i.CloseImage():
            printf('出力ファイル out.tif をクローズできません。')

print('終了')

ご質問、お問い合わせ

メールで support@TrustSS.co.jp 宛てにお送りください。
または、質問のページからお送りいただくようお願いします。ご要望も承っております。

PDF Toolsとは

PDF/Aとは