アイコン 株式会社トラスト・ソフトウェア・システム ロゴ
電話:03-5316-3375info@trustss.co.jp
電話:03-5316-3375info@trustss.co.jp

開発者向けPDF印刷ライブラリ - PDF Printer

 コマンドライン印刷アプリケーションを含む

PDF Printer は、PostScriptやPCL(Printer Command Language)を含むすべてのWindowsプリンタそして仮想プリンタでPDF文書をバックグラウンドで印刷するための効率的で実用的なソリューションを提供します。 プリンタ制御のために多くのオプションを用意しています。このツールは、まず第一に高いパフォーマンスと、特定の要件への優れた適応性を備えています。
コマンドラインツールの用意もありますので、プログラミングなしでPDFの印刷ができます。

PDF印刷機能

PDF Printer は、PDF、PDF/A、TIFF、JPEG を PostScript や PCL などのプリンタードライバー言語に変換します。 PDF文書は物理プリンター(ローカル、リモート、またはインターネット経由)で印刷するか、ファイルとして出力できます。
PDF Printerは用紙トレイ、用紙サイズ、両面印刷、ホチキス止め、複数ページをひとつの印刷ジョブにまとめることや、テキストや画像の透かし追加など、さまざまなプリンター制御オプションを用意しています。 また、対象プリンターのプロパティ(印刷余白、解像度など)を照会し、それに応じて印刷を最適化することもできます。 このツールは、最新のすべてのプリンターモデルに加えて、エミュレーションを介して古いプリンターもサポートします。
プリンターは Citrix 仮想プリンタードライバーをサポートします。

価格見積もり

 NOTE:
この機能は「Pdftools SDK」ライセンスで利用できます。
PDF Printerの全機能は無償で試用できます。

ユーザーマニュアル

PDF印刷機能

利用できる入出力の規格:
入力ファイルの規格
PDF 1.x(PDF 1.0,...,PDF 1.7),PDF 2.0
PDF/A-1, PDF/A-2, PDF/A-3
BMP,GIF,JBIG2,JPEG,JPEG2000,JPEG-LS,PBM,PNG,TIFF
出力ファイルの規格
PostScript, PCL5, PCL6, AFPのPrint spool formats

入力PDFへの処理

サンプルコード

PDF Printerを使えうと複数のドキュメントを1つのジョブでプリンターに送信したり、複数のジョブでそれぞれのプリンターに送信したり、印刷設定をカスタマイズしたりできます。
ここでは、開発環境にコードを統合する方法の例をいくつか示します。

C#のサンプルプロジェクトではPDF Printerライブラリ(DLL)をNuGetから自動でダウンロードします。
CのサンプルプロジェクトにはPDF Printerライブラリ(DLL)が含まれています。

試用版ライセンスキーが含まれていますので、そのまま無償で試用できます。ただし、結果に「透かし」が入ります。
「透かし」の削除をご希望の場合は問い合わせページまたはメールでお問い合わせください。

License Agreement(利用許諾契約書)を必ず確認してください。


1つの印刷ジョブで複数の文書を印刷

異なるドキュメント(PDF、TIFF)の全ページを単一の印刷ジョブで指定したプリンターで印刷します。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

// 目的のプリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
{
    _tprintf(_T("Printer %s could not be opned. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 印刷ジョブ開始
if (!PDFPrnBeginDocument(pPrinter, _T("My print job.")))
{
    _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 全ての入力ファイルをループ
for (int i = 0; i < nInputPaths; i++)
{
    // 入力ファイルをオープン
    if (!PDFPrnOpen(pPrinter, szInputPaths[i], _T("")))
    {
        _tprintf(_T("Input file %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szInputPaths[i], PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        goto cleanup;
    }

    // 選択されたファイルの全ページをループ
    for (int iPage = 1; iPage <= PDFPrnGetPageCount(pPrinter); iPage++)
    {
        // 入力ファイルの指定されたページを印刷
        if (!PDFPrnPrintPage(pPrinter, iPage))
        {
            _tprintf(_T("Page %d could not be printed successfully on printer %s. %s (ErrorCode: 0x%08x).\n"), iPage, szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
            iReturnValue = 1;
            goto cleanup;
        }
    }

    // 入力ファイルをクローズ
    PDFPrnClose(pPrinter);
}

// 印刷ジョブを終了
if (!PDFPrnEndDocument(pPrinter))
{
    _tprintf(_T("The print job could not be completed or the connection could not be closed. %s (ErrorCode: 0x%08x)."), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    // 目的のプリンターを開く
    if (!printer.OpenPrinter(printerName))
        throw new Exception(String.Format("Printer {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

    // 印刷ジョブ開始
    if (!printer.BeginDocument("My print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " + 
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 全ての入力ファイルをループ
    foreach (string path in inputPaths)
    {
        // 入力ファイルをオープン
        if (!printer.Open(path, ""))
            throw new Exception(String.Format("Input file {0} could not be opened. {1} " + 
                "(ErrorCode: 0x{2:x}).", path, printer.ErrorMessage, printer.ErrorCode));

        // 選択されたファイルの全ページをループ
        for (int pageNo = 1; pageNo <= printer.PageCount; pageNo++)
        {
            // 入力ファイルの指定されたページを印刷
            if (!printer.PrintPage(pageNo))
                throw new Exception(String.Format("Page {0} could not be printed successfully on " +
                    "printer {1}. {2} (ErrorCode: 0x{3:x}).", pageNo, printerName, 
                    printer.ErrorMessage, printer.ErrorCode));
        }

        // 入力ファイルをクローズ
        printer.Close();
    }

    // 印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the " + 
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, 
            printer.ErrorCode));
}			

同じプリンターで複数のジョブを印刷

大きなPDFまたはTIFFドキュメントを個別の印刷ジョブに分割します。
印刷ジョブをリンクして印刷順序を定義します。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

// 目的のプリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
{
    _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// リンクされた印刷ジョブのチェーンを開始
if (!PDFPrnBeginGroup(pPrinter))
{
    _tprintf(_T("Starting chain of linked print jobs failed. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 最初の印刷ジョブで印刷開始
printDocument(pPrinter, szFirstInputPath, szPrinterName);

// 二番目の印刷ジョブで印刷開始
printDocument(pPrinter, szSecondInputPath, szPrinterName);

// リンクされた印刷ジョブのチェーン終了を定義
if (!PDFPrnEndGroup(pPrinter))
{
    _tprintf(_T("End of print job chain was not set successfully. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// プリンターを閉じる
PDFPrnClosePrinter(pPrinter);
			
void printDocument(TPdfPrinter* pPrinter, TCHAR* szInputPath, TCHAR* szPrinterName)
{
    // 印刷ジョブ開始
    if (!PDFPrnBeginDocument(pPrinter, _T("My print job.")))
    {
        _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        return;
    }

    // 入力ファイルをオープン
    if (!PDFPrnOpen(pPrinter, szInputPath, _T("")))
    {
        _tprintf(_T("Input file %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        goto cleanup;
    }

    // 入力ファイルの全ページをループ
    for (int iPage = 1; iPage <= PDFPrnGetPageCount(pPrinter); iPage++)
    {
        // 入力ファイルの指定されたページを印刷
        if (!PDFPrnPrintPage(pPrinter, iPage))
        {
            _tprintf(_T("Page %d of input file %s could not be printed successfully on printer %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
            iReturnValue = 1;
            goto cleanup;
        }
    }

    // 入力ファイルをクローズ
    PDFPrnClose(pPrinter);

    // 印刷ジョブを終了
    if (!PDFPrnEndDocument(pPrinter))
    {
        _tprintf(_T("The print job could not be completed or the connection could not be closed. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
    }

    return;

cleanup:
    PDFPrnEndDocument(pPrinter);
}			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    // 目的のプリンターを開く
    if (!printer.OpenPrinter(printerName))
        throw new Exception(String.Format("Printer {0} could not be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

    // リンクされた印刷ジョブのチェーンを開始
    if (!printer.BeginGroup())
        throw new Exception(String.Format("Starting chain of linked print jobs failed. " +
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 最初の印刷ジョブで印刷開始
    PrintDocument(printer, firstInputPath, printerName);

    // 二番目の印刷ジョブで印刷開始
    PrintDocument(printer, secondInputPath, printerName);

    // リンクされた印刷ジョブのチェーン終了を定義
    if (!printer.EndGroup())
        throw new Exception(String.Format("End of print jobs chain was not set successfully. " +
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // プリンターを閉じる
    printer.ClosePrinter();
}			
private static void PrintDocument(Printer printer, string inputPath, string printerName)
{
    // 印刷ジョブ開始
    if (!printer.BeginDocument("My print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " +
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 入力ファイルをオープン
    if (!printer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} could not be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));

    // 入力ファイルの全ページをループ
    for (int pageNo = 1; pageNo <= printer.PageCount; pageNo++)
    {
        // 入力ファイルの指定されたページを印刷
        if (!printer.PrintPage(pageNo))
             throw new Exception(String.Format("Page {0} of input file {1} could not be printed " +
                 "successfully on printer {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath,
                 printerName, printer.ErrorMessage, printer.ErrorCode));
    }

    // 入力ファイルをクローズ
    printer.Close();

    // 印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the " +
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage,
            printer.ErrorCode));
}			

同じ文書を複数のプリンターで印刷

同じPDF文書を複数のプリンタで印刷します。
オプションで1つのプリンタで印刷するページを指定します。指定しない場合は最初のページが1つのプリンタで印刷され、残りのページは別のプリンタで印刷されます。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// 印刷オブジェクト生成
pPrinter = PDFPrnCreateObject();

// 入力ファイルオープン
if (!PDFPrnOpen(pPrinter, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
}

// 最初のプリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szFirstPrinterName))
{
    _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szFirstPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 最初の印刷ジョブを開始
if (!PDFPrnBeginDocument(pPrinter, _T("My first print job.\n")))
{
    _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 入力ファイルの指定されたページを印刷
if (!PDFPrnPrintPage(pPrinter, iPageNumber))
{
    _tprintf(_T("Page %d of %s could not be printed succesfully on printer %s. %s (ErrorCode: 0x%08x).\n"), iPageNumber, szInputPath, szFirstPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 最初の印刷ジョブを終了
if (!PDFPrnEndDocument(pPrinter))
{
    _tprintf(_T("The print job could not be printed successfully on printer %s. %s (ErrorCode: 0x%08x).\n"), szFirstPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 最初のプリンターを閉じる
PDFPrnClosePrinter(pPrinter);


// 二番目のプリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szSecondPrinterName))
{
    _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szSecondPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 二番目の印刷ジョブを開始
if (!PDFPrnBeginDocument(pPrinter, _T("My second print job.")))
{
    _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 二番目のページ(存在すれば)から最後のページまでをループ
for (int iPage = 2; iPage < PDFPrnGetPageCount(pPrinter); iPage++)
{
    // 入力ファイルの残りのページを印刷
    if (!PDFPrnPrintPage(pPrinter, iPage))
    {
        _tprintf(_T("Page %d could not be printed successfull on printer %s. %s (ErrorCode: 0x%08x).\n"), iPage, szSecondPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        goto cleanup;
    }
}

// 二番目の印刷ジョブを終了
if (!PDFPrnEndDocument(pPrinter))
{
    _tprintf(_T("The print job could not be completed or the connection could not be closed. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 二番目のプリンターを閉じる
PDFPrnClosePrinter(pPrinter);

// 入力ファイルをクローズ
PDFPrnClose(pPrinter);
			
// 印刷オブジェクト生成
using (Printer printer = new Printer())
{
    // 入力ファイルオープン
    if (!printer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));

    // 最初のプリンターを開く
    if (!printer.OpenPrinter(firstPrinterName))
        throw new Exception(String.Format("Printer {0} could not be opened. {1} " + 
            "(ErrorCode: 0x{2:x}).", firstPrinterName, printer.ErrorMessage, printer.ErrorCode));

    // 最初の印刷ジョブを開始
    if (!printer.BeginDocument("My first print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " +
                "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 入力ファイルの指定されたページを印刷
    if (!printer.PrintPage(pageNumber))
        throw new Exception(String.Format("Page {0} of {1} could not be printed successfully on " + 
            "printer {2}. {3} (ErrorCode: 0x{4:x}).", pageNumber, inputPath, firstPrinterName, 
            printer.ErrorMessage, printer.ErrorCode));

    // 最初の印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the " + 
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, 
            printer.ErrorCode));

    // 最初のプリンターを閉じる
    printer.ClosePrinter();

    // 二番目のプリンターを開く
    if (!printer.OpenPrinter(secondPrinterName))
        throw new Exception(String.Format("Printer {0} could not be opened. {1} " + 
            "(ErrorCode: 0x{2:x}).", secondPrinterName, printer.ErrorMessage, printer.ErrorCode));

    // 二番目の印刷ジョブを開始
    if (!printer.BeginDocument("My second print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " + 
            "{0} (ErrorCode: 0x{2:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 二番目のページ(存在すれば)から最後のページまでをループ
    for (int pageNo = 2; pageNo < printer.PageCount; pageNo++)
    {
        // 入力ファイルの残りのページを印刷
        if (!printer.PrintPage(pageNo))
            throw new Exception(String.Format("Page {0} could not be printed successfully " + 
                "on printer {1}. {2} (ErrorCode: 0x{3:x}).", pageNo, secondPrinterName, 
                printer.ErrorMessage, printer.ErrorCode));
    }

    // 二番目の印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the " + 
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, 
            printer.ErrorCode));

    // 二番目のプリンターを閉じる
    printer.ClosePrinter();

    // 入力ファイルをクローズ
    printer.Close();
}			

PDF文書を印刷

PDF文書またはTIFF画像の全て(または選択したページ)を指定されたプリンターにで印刷します。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

// 入力ファイルの全ページを指定された単一のプリンタで印刷
if (!PDFPrnPrintFile(pPrinter, szInputPath, szPrinterName, _T(""), iFirstPage, iLastPage))
{
    _tprintf(_T("Printing input file %s failed. %s (ErrorCode: 0x%08x).\n"), szInputPath, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
}			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    // 入力ファイルの全ページを指定された単一のプリンタで印刷
    if (!printer.PrintFile(inputPath, printerName, "", firstPage, lastPage))
        throw new Exception(String.Format("Printing input file {0} failed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));
}			

ファイルに印刷

スプールファイルをプリンタに送信する代わりにファイルに保存します。
使用するプリンタドライバに応じて、PostScript、PCL、またはその他のファイルを生成します。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

// プリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
{
    _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 印刷結果を格納するファイル名を設定
PDFPrnSetOutput(pPrinter, szOutputPath);

// 印刷ジョブを開始
if (!PDFPrnBeginDocument(pPrinter, _T("My print job.")))
{
    _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 入力ファイルをオープン
if (!PDFPrnOpen(pPrinter, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 選択したファイルのすべてのページをループ
for (int iPage = 1; iPage <= PDFPrnGetPageCount(pPrinter); iPage++)
{
    // 入力ファイルのページを印刷
    if (!PDFPrnPrintPage(pPrinter, iPage))
    {
        _tprintf(_T("Page %d could not be printed successfully on printer %s. %s (ErrorCode: 0x%08x).\n"), iPage, szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        goto cleanup;
    }
}

// 入力ファイルをクローズ
PDFPrnClose(pPrinter);

// 印刷ジョブを終了
if (!PDFPrnEndDocument(pPrinter))
{
    _tprintf(_T("The print job could not be completed or the connection could not be closed. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    // プリンターを開く
    if (!printer.OpenPrinter(printerName))
        throw new Exception(String.Format("Printer {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

    // 印刷結果を格納するファイル名を設定
    printer.Output = outputPath;

    // 印刷ジョブを開始
    if (!printer.BeginDocument("My print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " + 
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 入力ファイルをオープン
    if (!printer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));

    // 選択したファイルのすべてのページをループ
    for (int pageNo = 1; pageNo <= printer.PageCount; pageNo++)
    {
        // 入力ファイルのページを印刷
        if (!printer.PrintPage(pageNo))
            throw new Exception(String.Format("Page {0} could not be printed successfully on " + 
                "printer {1}. {2} (ErrorCode: 0x{3:x}).", pageNo, printerName, printer.ErrorMessage, 
                printer.ErrorCode));
    }

    // 入力ファイルをクローズ
    printer.Close();

    // 印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the " + 
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, 
            printer.ErrorCode));
}			

プリンタとそのプロパティを一覧表示

ローカルホストから利用できる全てのプリンタの一覧をテキストファイルに書き込みます。
一覧されたプリンタについて利用できるな両面印刷モード、トレー数、用紙サイズの数、プリンタでサポートされているメディアタイプの数などの情報を取得します。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

// ローカルホストで利用可能なすべてのプリンタのリストを含む出力テキストファイルを作成します
pTxtFile = _tfopen(szTextFilePath, _T("w"));
_ftprintf(pTxtFile, _T("List of available printers in localhost:\n"));
_ftprintf(pTxtFile, _T("----------------------------------------\n"));

// ローカルホスト内のすべてのプリンタをループ
for (int iPrinter = 0, nPrinters = PDFPrnGetPrinterCount(pPrinter, ""); iPrinter < nPrinters; iPrinter++)
{
    TCHAR szPrinterName[256];
   _tcscpy(szPrinterName, PDFPrnGetPrinter(pPrinter, iPrinter));
   _ftprintf(pTxtFile, _T("Printer %d: %s\n"), iPrinter + 1, szPrinterName);

   // プリンターを開く
   if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
   {
       _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
       continue;
   }

    // 選択したプリンタの両面印刷モードを一覧表示
    _ftprintf(pTxtFile, _T("  Duplex Modes:\n"));
    for (int j = 0, n = PDFPrnGetDuplexModeCount(pPrinter, szPrinterName); j < n; j++)
        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetDuplexMode(pPrinter, j));

    // 選択したプリンタのトレーを一覧表示
    _ftprintf(pTxtFile, _T("  Bins:\n"));
    for (int j = 0, n = PDFPrnGetBinCount(pPrinter, szPrinterName); j < n; j++)
        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetBin(pPrinter, j));

    // 選択したプリンタの用紙サイズを一覧表示
    _ftprintf(pTxtFile, _T("  Paper:\n"));
    for (int j = 0, n = PDFPrnGetPaperCount(pPrinter, szPrinterName); j < n; j++)
        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetPaper(pPrinter, j));

    // 選択したプリンタのメディアタイプを一覧表示
    _ftprintf(pTxtFile, _T("  Media Types:\n"));
    for (int j = 0, n = PDFPrnGetMediaTypeCount(pPrinter, szPrinterName); j < ; j++)
        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetMediaTypeName(pPrinter, j));

    // プリンターを閉じる
    PDFPrnClosePrinter(pPrinter);

    _ftprintf(pTxtFile, _T("----------------------------------------\n"));
}			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    // ローカルホストで利用可能なすべてのプリンタのリストを含む出力テキストファイルを作成します
    using (StreamWriter writer = new StreamWriter(txtFilePath))
    {
        writer.WriteLine("List of available printers in localhost:");
        writer.WriteLine("----------------------------------------");

        // ローカルホスト内のすべてのプリンタをループ
        for (int printerNo = 0, printerCount = printer.GetPrinterCount(""); printerNo < printerCount; printerNo++)
        {
            string printerName = printer.GetPrinter(printerNo);
            writer.WriteLine("Printer {0}: {1}", printerNo + 1, printerName);

            // プリンターを開く
            if (!printer.OpenPrinter(printerName))
                throw new Exception(String.Format("Printer {0} could not be opened. " + 
                "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

            // 選択したプリンタの両面印刷モードを一覧表示
            writer.WriteLine("  Duplex Modes:");
            for (int i = 0, n = printer.GetDuplexModeCount(printerName); i < n; i++)
                writer.WriteLine("    - {0}", printer.GetDuplexMode(i));

            // 選択したプリンタのトレーを一覧表示
            writer.WriteLine("  Bins:");
            for (int i = 0, n = printer.GetBinCount(printerName); i < n; i++)
                writer.WriteLine("    - {0}", printer.GetBin(i));

            // 選択したプリンタの用紙サイズを一覧表示
            writer.WriteLine("  Paper:");
            for (int i = 0, n = printer.GetPaperCount(printerName); i < n; i++)
                writer.WriteLine("    - {0}", printer.GetPaper(i));

            // 選択したプリンタのメディアタイプを一覧表示
            writer.WriteLine("  Media Types:");
            for (int i = 0, n = printer.GetMediaTypeCount(printerName); i < n; i++)
                writer.WriteLine("    - {0}", printer.GetMediaTypeName(i));

            // プリンターを閉じる
            printer.ClosePrinter();

            writer.WriteLine("----------------------------------------");
        }
    }
}			

指定された両面印刷モードで文書を印刷

PDF文書を任意に選択された片面、縦、横の両面印刷モードで印刷します。
選択がない場合はプリンタ既定の両面印刷モードで印刷されます。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

// 入力ファイルをオープン
if (!PDFPrnOpen(pPrinter, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// プリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
{
    _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 両面印刷モードを設定(既定の両面印刷モードを使用しない場合)
if (iDuplexMode != -1)
    PDFPrnSetDuplex(pPrinter, iDuplexMode);

// 印刷ジョブを開始
if (!PDFPrnBeginDocument(pPrinter, _T("My print job.")))
{
    _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 入力ファイルのページを印刷
for (int iPage = 1; iPage <= PDFPrnGetPageCount(pPrinter); iPage++)
{
    if (!PDFPrnPrintPage(pPrinter, iPage))
    {
        _tprintf(_T("Page %d of %s could not be printed successfully on printer %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        goto cleanup;
    }
}

// 印刷ジョブを終了
if (!PDFPrnEndDocument(pPrinter))
{
    _tprintf(_T("The print job could not be completed or connection could not be closed. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 入力ファイルをクローズ
PDFPrnClose(pPrinter);
			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    // 入力ファイルをオープン
    if (!printer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));

    // プリンターを開く
    if (!printer.OpenPrinter(printerName))
        throw new Exception(String.Format("Printer {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

    // 両面印刷モードを設定(既定の両面印刷モードを使用しない場合)
    if (setDuplexMode)
        printer.Duplex = duplexMode;

    // 印刷ジョブを開始
    if (!printer.BeginDocument("My print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " + 
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    // 入力ファイルのページを印刷
    for (int pageNo = 1; pageNo <= printer.PageCount; pageNo++)
    {
        if (!printer.PrintPage(pageNo))
            throw new Exception(String.Format("Page {0} of {1} could not be printed successfully" +
                "on printer {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath, printerName, 
                printer.ErrorMessage, printer.ErrorCode));
    }

    // 印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the ´" + 
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, 
            printer.ErrorCode));

    // プリンターを閉じる
    if (!printer.ClosePrinter())
        throw new Exception(String.Format("Printer {0} could not be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

    // 入力ファイルをクローズ
    if (!printer.Close())
        throw new Exception(String.Format("Input file {0} could not be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));
}			

透かしを入れて印刷

PDFまたはTIFF文書の印刷ジョブの1ページおきに透かしを追加します。
カスタム透かしテキストをデザインし、位置、形式、外観を変更します。


サンプル・プロジェクト(C)をダウンロード
サンプル・プロジェクト(C#)をダウンロード
サンプル・プロジェクトをダウンロード
// Printerオブジェクト生成
pPrinter = PDFPrnCreateObject();

szPrinterName = PDFPrnGetDefaultPrinter(pPrinter);
if (szPrinterName == NULL || (_tcscmp(szPrinterName, "") == 0))
{
    _tprintf(_T("No default printer available."));
    iReturnValue = 1;
    goto cleanup;
}

// 入力ファイルをオープン
if (!PDFPrnOpen(pPrinter, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// プリンターを開く
if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
{
    _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

// 印刷ジョブを開始
if (!PDFPrnBeginDocument(pPrinter, _T("Watermark print job.")))
{
    _tprintf(_T("Could not connect to the printer device. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}

PDFPrnSetCenter(pPrinter, 1);
PDFPrnSetPaperSize(pPrinter, -2);

// 入力ファイルの全ページを印刷
for (int iPage = 1; iPage <= PDFPrnGetPageCount(pPrinter); iPage++)
{
    // 最初のページから始めて、2ページごとに透かしを追加
    if (iPage % 2 == 1)
    {
        PDFPrnSetPageNo(pPrinter, iPage);
        fWidth = PDFPrnGetPageWidth(pPrinter);
        fHeight = PDFPrnGetPageHeight(pPrinter);
        fFontSize = (float)sqrt(fWidth * fWidth + fHeight * fHeight) / _tcslen(szWatermarkText);

        PDFPrnSetWatermarkBold(pPrinter, 1);
        PDFPrnSetWatermarkOutline(pPrinter, 1);
        PDFPrnSetWatermarkFontName(pPrinter, _T("Courier"));
        PDFPrnSetWatermarkFontSize(pPrinter, fFontSize);
        PDFPrnSetWatermarkColor(pPrinter, 0xCCCCCC);
        PDFPrnSetWatermarkXPos(pPrinter, fWidth / 5);
        PDFPrnSetWatermarkYPos(pPrinter, (fHeight - fHeight / 5 + fFontSize / 2));
        PDFPrnSetWatermarkAngle(pPrinter, (float)atan((double)fHeight / fWidth));
        PDFPrnAddWatermarkText(pPrinter, szWatermarkText);
    }
    else
    {
        // 透かしを削除
        PDFPrnDeleteWatermarks(pPrinter);
    }

    // ページを印刷
    if (!PDFPrnPrintPage(pPrinter, iPage))
    {
        _tprintf(_T("Page %d of %s could not be printed successfully on printer %s. %s (ErrorCode: 0x%08x).\n"), iPage, szInputPath, szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
        iReturnValue = 1;
        goto cleanup;
    }
}

// 入力ファイルをクローズ
PDFPrnClose(pPrinter);

// 印刷ジョブを終了
if (!PDFPrnEndDocument(pPrinter))
{
    _tprintf(_T("The print job could not be completed or the connection could not be closed. %s (ErrorCode: 0x%08x).\n"), PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
    iReturnValue = 1;
    goto cleanup;
}			
// Printerオブジェクト生成
using (Printer printer = new Printer())
{
    string printerName = printer.DefaultPrinter;
    if (String.IsNullOrEmpty(printerName))
        throw new Exception(String.Format("No default printer available."));

    // 入力ファイルをオープン
    if (!printer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, printer.ErrorMessage, printer.ErrorCode));

    // プリンターを開く
    if (!printer.OpenPrinter(printerName))
        throw new Exception(String.Format("Printer {0} could not be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));

    // 印刷ジョブを開始
    if (!printer.BeginDocument("Watermark print job."))
        throw new Exception(String.Format("Could not connect to the printer device. " + 
            "{0} (ErrorCode: 0x{1:x}).", printer.ErrorMessage, printer.ErrorCode));

    printer.Center = true;
    printer.PaperSize = -2;

    // 入力ファイルの全ページを印刷
    for (int pageNo = 1; pageNo <= printer.PageCount; pageNo++)
    {
        // 最初のページから始めて、2ページごとに透かしを追加
        if (pageNo % 2 == 1)
        {
            printer.PageNo = pageNo;
            float width = printer.PageWidth;
            float height = printer.PageHeight;
            float fontSize = (float)Math.Sqrt(width * width + height * height) / 
                             watermarkText.Length;
            printer.WatermarkBold = true;
            printer.WatermarkOutline = true;
            printer.WatermarkFontName = "Courier";
            printer.WatermarkFontSize = fontSize;
            printer.WatermarkColor = 0xCCCCCC;
            printer.WatermarkXPos = width / 5;
            printer.WatermarkYPos = (height - height / 5 + fontSize / 2);
            printer.WatermarkAngle = (float)Math.Atan((double)height / width);
            printer.AddWatermarkText(watermarkText);
        }
        else
        {
            // 透かしを削除
            printer.DeleteWatermarks();
        }

        // ページを印刷
        if (!printer.PrintPage(pageNo))
            throw new Exception(String.Format("Page {0} of {1} could not be printed successfully " +
                    "on printer {2}. {3} (ErrorCode: 0x{4:x}).", pageNo, inputPath, printerName, 
                    printer.ErrorMessage, printer.ErrorCode));
    }

    // 入力ファイルをクローズ
    printer.Close();

    // 印刷ジョブを終了
    if (!printer.EndDocument())
        throw new Exception(String.Format("The print job could not be completed or the " +
            "connection could not be closed. {0} (ErrorCode: 0x{1:x}).", 
            printer.ErrorMessage, printer.ErrorCode));
}			

お問い合わせ、ご質問、技術サポート

質問のページからお送りいただくようお願いします。
または、メールでsupport@trustss.co.jpあてにお送りください。


ご購入前の技術的質問も無償で対応します。サポート受付ページからお願いします。

> PDF Structure (PDF構成)

> PDF Imager-LP (画像化)

> PDF Stamper (電子印鑑)

> Pdftools SDK

- Pdftools SDKサンプルの利用手順
- Toolbox Add-on
- Toolbox Add-onサンプルの利用手順
> Pdftools SDK APIリファレンス
- その他のAPI及びコマンドラインツール