アイコン 株式会社トラスト・ソフトウェア・システム ロゴ

Pdftools SDK
Marge & Split PDF(PDFの合成と分割)機能

複数のPDFと画像からページを組み立て新たなPDFを作成します。
ニーズに合わせて構成できる複製オプションを提供することで生成するPDFを完全に制御できます。

この機能は「Pdftools SDK」ライブラリの一部です。

見積もり

PDFを合成 機能

Pdftools SDK の DocumentAssemblerクラス(C#C/C++)を使用して複数のPDFファイルと画像を出力PDFに結合します。
たとえば、顧客がアップロードしたドキュメントと画像などをさらに処理したり保存したりするのに適したPDFに変換します。

この処理ではフォントなどの重複したリソースが適切に結合され、結果PDFのサイズが大幅に削減されます。
DocumentAssemblerクラスはフォームなどの名前付き要素間の競合を自動的に解決します。

PDFを分割 機能

Pdftools SDK の DocumentAssemblerクラス(C#C/C++)を使用して、単一のPDFを複数のPDFと画像に分割します。
たとえば、各ページが異なる顧客の請求書を表すPDFを顧客ごとのPDFにまとめることができます。

この処理では各ページに必要なリソースだけがそのページを含む出力ドキュメントにコピーされるます。そのため、結果のPDFに冗長な情報や機密情報が含まれる可能性がなくなります。

PDFの結合と分割の組み合わせる

複数の入力PDFを多数の出力PDFに分割および再結合できますので、PDFを効率的に再構成できます。

サンプル

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

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

License Agreement(利用許諾契約書)が含まれていますので必ず確認してください。

PDF文書を合成

複数の PDF文書を一つの出力ドキュメントに結合します。


// 出力ストリームを生成
pOutStream = _tfopen(szOutPath, _T("wb+"));
GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutStream, _T("Failed to create output file \"%s\" for writing.\n"), szOutPath);
TPdfToolsSys_StreamDescriptor outDesc;
PdfToolsSysCreateFILEStreamDescriptor(&outDesc, pOutStream, 0);
pAssembler = PdfToolsDocumentAssembly_DocumentAssembler_New(&outDesc, NULL, NULL);

for (int i = 1; i < argc - 1; i++)
{
    szInPath = argv[i];
    // 入力PDFファイルを開く
    pInStream = _tfopen(szInPath, _T("rb"));
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pInStream, _T("Failed to open the input file \"%s\" for reading.\n"),
                                     szInPath);
    TPdfToolsSys_StreamDescriptor inDesc;
    PdfToolsSysCreateFILEStreamDescriptor(&inDesc, pInStream, 0);
    pInDoc = PdfToolsPdf_Document_Open(&inDesc, _T(""));
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(
        pInDoc, _T("Failed to create a document from the input file \"%s\". %s (ErrorCode: 0x%08x).\n"), szInPath,
        szErrorBuff, PdfTools_GetLastError());

    // 入力PDF文書の内容を出力文書に追加
    GOTO_CLEANUP_IF_FALSE_PRINT_ERROR(
        PdfToolsDocumentAssembly_DocumentAssembler_Append(pAssembler, pInDoc, NULL, NULL, NULL, NULL),
        _T("Failed to append a page. (ErrorCode: 0x%08x).\n"), PdfTools_GetLastError());

    PdfToolsPdf_Document_Close(pInDoc);
    fclose(pInStream);
    pInDoc    = NULL;
    pInStream = NULL;
}
// 入力文書を出力文書に結合
pOutDoc = PdfToolsDocumentAssembly_DocumentAssembler_Assemble(pAssembler);

GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutDoc, _T("The processing has failed. (ErrorCode: 0x%08x).\n"),
                                 PdfTools_GetLastError());
private static void Merge(IEnumerable inPaths, string outPath)
{
    // 出力ストリームを生成
    using var outStream = File.Create(outPath);
    using var docAssembler = new PdfTools.DocumentAssembly.DocumentAssembler(outStream);

    foreach (var inPath in inPaths)
    {
        using var inStream = File.OpenRead(inPath);
        using var inDoc = PdfTools.Pdf.Document.Open(inStream);
        // 入力PDF文書の内容を出力文書に追加
        docAssembler.Append(inDoc);
    }

    // 入力文書を出力文書に結合
    docAssembler.Assemble();
}			
サンプル・プロジェクト(C)をダウンロード ReadMeを開く
サンプルプロジェクト(C#)をダウンロード ReadMeを開く
サンプル・プロジェクトをダウンロード

PDF文書を分割

一つのPDF文書を複数のPDF文書に分割します。


// 入力PDFファイルを開く
pInStream = _tfopen(szInPath, _T("rb"));
GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pInStream, _T("Failed to open the input file \"%s\" for reading.\n"), szInPath);
TPdfToolsSys_StreamDescriptor inDesc;
PdfToolsSysCreateFILEStreamDescriptor(&inDesc, pInStream, 0);
pInDoc = PdfToolsPdf_Document_Open(&inDesc, _T(""));

GOTO_CLEANUP_IF_NULL_PRINT_ERROR(
    pInDoc, _T("Failed to create a document from the input file \"%s\". %s (ErrorCode: 0x%08x).\n"), szInPath,
    szErrorBuff, PdfTools_GetLastError());

// 入力PDF文書をページごとに分割し、それぞれを一つの出力文書PDFとして生成
int   nPageCount = PdfToolsPdf_Document_GetPageCount(pInDoc);
TCHAR szPageFileName[256];
for (int i = 1; i <= nPageCount; i++)
{
    CreateOutputFileName(szPageFileName, szOutPath, i);

    // 入力PDF文書の各ページを出力するストリームを作成
    pOutStream = _tfopen(szPageFileName, _T("wb+"));
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutStream, _T("Failed to open the input file \"%s\" for reading.\n"),
                                     szPageFileName);
    TPdfToolsSys_StreamDescriptor outDesc;
    PdfToolsSysCreateFILEStreamDescriptor(&outDesc, pOutStream, 0);

    // PDFをページに分割
    pAssembler = PdfToolsDocumentAssembly_DocumentAssembler_New(&outDesc, NULL, NULL);
    GOTO_CLEANUP_IF_FALSE_PRINT_ERROR(
        PdfToolsDocumentAssembly_DocumentAssembler_Append(pAssembler, pInDoc, &i, &i, NULL, NULL),
        _T("Failed to append a page. (ErrorCode: 0x%08x).\n"), PdfTools_GetLastError());
    pOutDoc = PdfToolsDocumentAssembly_DocumentAssembler_Assemble(pAssembler);
    PdfToolsDocumentAssembly_DocumentAssembler_Close(pAssembler);

    if (pOutDoc)
        PdfToolsPdf_Document_Close(pOutDoc);
    if (pOutStream)
        fclose(pOutStream);
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutDoc, _T("The processing has failed. (ErrorCode: 0x%08x).\n"),
                                     PdfTools_GetLastError());
}
			
private static void Split(string inPath, string outPathPrefix)
{
    // 入力PDFファイルを開く
    using var inStream = File.OpenRead(inPath);
    using var inDoc = PdfTools.Pdf.Document.Open(inStream);

    // 入力文書をページごとに分割
    for (int i = 1; i <= inDoc.PageCount; ++i)
    {
        using var outStream = File.Create(outPathPrefix + "_page_" + i + ".pdf");
        using var docAssembler = new PdfTools.DocumentAssembly.DocumentAssembler(outStream);
        docAssembler.Append(inDoc, i, i);
        docAssembler.Assemble();
    }
}			
サンプル・プロジェクト(C)をダウンロード ReadMeを開く
サンプル・プロジェクト(C#)をダウンロード ReadMeを開く
サンプル・プロジェクトをダウンロード

見積もり

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

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


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

> PDF Structure (PDF構成)

> PDF Imager-LP (画像化)

> PDF Stamper (電子印鑑)

- Pdftools SDK

> Pdftool SDK APIリファレンス