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

Pdftools SDK
PDF to PDF/A Convert (PDFをPDF/Aに変換)機能

PDFデータをPDF/Aに変換します。
暗号化されたPDFを読み込んだり、不正なデータを修正したりします。
PDFの内容や添付されたファイルなどを削除できます。

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

見積もり

APIリファレンス

APIリファレンス(英文)はこちらです。

PDFをPDF/Aに変換機能

利用できるPDF規格:
入力ファイルの規格出力ファイルの規格
PDF 1.x, PDF 2.0PDF/A-1b, PDF/A-1a, PDF/A-2b, PDF/A-2a, PDF/A-2u, PDF/A-3b, PDF/A-3a, PDF/A-3u

入力PDFへの処理

カラー・プロファイル及びフォント

変換処理

サンプルコード

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

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

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

必要に応じてPDF文書をPDF/A-2bに変換する

入力されたPDF文書を分析します。PDF/A-2bに準拠していない場合は、PDF/A-2bに変換します。


void EventListener(void* pContext, const char* szDataPart, const char* szMessage,
                   TPdfToolsPdfAConversion_EventSeverity iSeverity, TPdfToolsPdfAConversion_EventCategory iCategory,
                   TPdfToolsPdfAConversion_EventCode iCode, const char* szContext, int iPageNo)
{
    // iSeverityはイベントの推奨される重要度です
    // オプション: 提案された重大度は、変換プロセスの要件、たとえばイベントのカテゴリ (カテゴリなど) 
    // に応じて変更できます。
    if (iSeverity > iEventsSeverity)
        iEventsSeverity = iSeverity;

    // 変換状態をレポート
    TCHAR cSeverity = iSeverity == ePdfToolsPdfAConversion_EventSeverity_Information ? 'I'
                      : ePdfToolsPdfAConversion_EventSeverity_Warning                ? 'W'
                                                                                     : 'E';
    if (iPageNo > 0)
        _tprintf(_T("- %c %d: %s (%s on page %d)\n"), cSeverity, iCategory, szMessage, szContext, iPageNo);
    else
        _tprintf(_T("- %c %d: %s (%s)\n"), cSeverity, iCategory, szMessage, szContext);
}
			
void ConvertIfNotConforming(const TCHAR* szInPath, const TCHAR* szOutPath, TPdfToolsPdf_Conformance iConf)
{
    TPdfToolsPdfAValidation_AnalysisOptions*   pAOpt      = NULL;
    TPdfToolsPdfAValidation_Validator*         pValidator = NULL;
    TPdfToolsPdfAValidation_AnalysisResult*    pARes      = NULL;
    TPdfToolsPdfAConversion_ConversionOptions* pConvOpt   = NULL;
    TPdfToolsPdfAConversion_Converter*         pConv      = NULL;
    TPdfToolsPdf_Document*                     pOutDoc    = NULL;
    TPdfToolsPdf_Document*                     pInDoc     = NULL;
    FILE*                                      pInStream  = NULL;
    FILE*                                      pOutStream = NULL;

    // 入力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 open document \"%s\". %s (ErrorCode: 0x%08x).\n"), szInPath,
                                     szErrBuf, PdfTools_GetLastError());

    // 入力文書のPDF/A標準準拠を分析する検証ツールを生成
    pAOpt = PdfToolsPdfAValidation_AnalysisOptions_New();
    PdfToolsPdfAValidation_AnalysisOptions_SetConformance(pAOpt, iConf);
    pValidator = PdfToolsPdfAValidation_Validator_New();
    pARes      = PdfToolsPdfAValidation_Validator_Analyze(pValidator, pInDoc, pAOpt);
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pARes, _T("Failed to analyze document. %s (ErrorCode: 0x%08x).\n"), szErrBuf,
                                     PdfTools_GetLastError());

    // PDF/Aへの変換が必要かを確認する
    if (PdfToolsPdfAValidation_AnalysisResult_IsConforming(pARes))
    {
        printf("Document conforms to %s already.\n", PdfToolsPdf_Conformance_ToStringA(iConf));
        goto cleanup;
    }

    // 書き込み用の出力ストリームを作成
    pOutStream = _tfopen(szOutPath, _T("wb+"));
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutStream, _T("Failed to create the output file \"%s\".\n"), szOutPath);
    TPdfToolsSys_StreamDescriptor outDesc;
    PdfToolsSysCreateFILEStreamDescriptor(&outDesc, pOutStream, 0);

    // コンバーターオブジェクトを使用して入力ドキュメントをPDF/Aに変換
    // および、その変換イベントハンドラ生成
    pConvOpt = PdfToolsPdfAConversion_ConversionOptions_New();
    pConv    = PdfToolsPdfAConversion_Converter_New();
    PdfToolsPdfAConversion_Converter_AddConversionEventHandlerA(
        pConv, NULL, (TPdfToolsPdfAConversion_Converter_ConversionEventA)EventListener);
    pOutDoc = PdfToolsPdfAConversion_Converter_Convert(pConv, pARes, pInDoc, &outDesc, pConvOpt, NULL);
    GOTO_CLEANUP_IF_NULL_PRINT_ERROR(pOutDoc, _T("Failed to convert document. %s (ErrorCode: 0x%08x).\n"), szErrBuf,
                                     PdfTools_GetLastError());

    // 重要なコンバージョンイベントが発生したかどうかを確認
    switch (iEventsSeverity)
    {
    case ePdfToolsPdfAConversion_EventSeverity_Information:
    {
        TPdfToolsPdf_Conformance iOutConf;
        PdfToolsPdf_Document_GetConformance(pOutDoc, &iOutConf);
        printf("Successfully converted document to %s.\n", PdfToolsPdf_Conformance_ToStringA(iOutConf));
        break;
    }

    case ePdfToolsPdfAConversion_EventSeverity_Warning:
    {
        TPdfToolsPdf_Conformance iOutConf;
        PdfToolsPdf_Document_GetConformance(pOutDoc, &iOutConf);
        printf("Warnings occurred during the conversion of document to %s.\n",
               PdfToolsPdf_Conformance_ToStringA(iOutConf));
        printf("Check the output file to decide if the result is acceptable.\n");
        break;
    }

    case ePdfToolsPdfAConversion_EventSeverity_Error:
    {
        printf("Unable to convert document to %s because of critical conversion events.\n",
               PdfToolsPdf_Conformance_ToStringA(iConf));
        break;
    }

cleanup:
    PdfToolsPdf_Document_Close(pOutDoc);
    PdfTools_Release(pConv);
    PdfTools_Release(pConvOpt);
    PdfTools_Release(pARes);
    PdfTools_Release(pValidator);
    PdfTools_Release(pAOpt);
    PdfToolsPdf_Document_Close(pInDoc);
    if (pInStream)
        fclose(pInStream);
    if (pOutStream)
        fclose(pOutStream);
}
			
static void ConvertIfNotConforming(string inPath, string outPath, Conformance conformance)
{
    // 入力ファイルを開く
    using var inStr = File.OpenRead(inPath);
    using var inDoc = Document.Open(inStr);

    // Validatorオブジェクトを生成し、Conformanceオブジェクトを使用して、
    // Validatorの動作を制御するAnalysisOptionsオブジェクトを生成
    var validator = new Validator();
    var analysisOptions = new AnalysisOptions() { Conformance = conformance };

    // 分析を実行し、結果を確認
    // PDF文書が準拠していない場合にのみ続行
    var analysisResult = validator.Analyze(inDoc, analysisOptions);
    if (analysisResult.IsConforming)
    {
        Console.WriteLine($"Document conforms to {inDoc.Conformance} already.");
        return;
    }

    // Converterオブジェクトを生成
    var converter = new Converter();

    // 変換イベントのハンドラーを追加
    var eventsSeverity = EventSeverity.Information;
    converter.ConversionEvent += (s, e) =>
    {
        // イベントの推奨される重要度を取得
        var severity = e.Severity;

        // オプション: 提案された重要度は変換プロセスの要件(イベントのカテゴリなど)に応じて変更できます。

        if (severity > eventsSeverity)
            eventsSeverity = severity;

        // 変換イベントを報告
        Console.WriteLine("- {0} {1}: {2} ({3}{4})",
            severity.ToString()[0], e.Category, e.Message, e.Context, e.PageNo > 0 ? " page " + e.PageNo : ""
        );
    };

    // 出力ファイルのストリームを生成
    using var outStr = File.Create(outPath);

    // 変換オブジェクトとその変換イベントハンドラーを使用して入力ドキュメントをPDF/Aに変換
    using var outDoc = converter.Convert(analysisResult, inDoc, outStr);

    // 重要な変換イベントが発生したかを確認
    switch (eventsSeverity)
    {
        case EventSeverity.Information:
            Console.WriteLine($"Successfully converted document to {outDoc.Conformance}.");
            break;

        case EventSeverity.Warning:
            Console.WriteLine($"Warnings occurred during the conversion of document to {outDoc.Conformance}.");
            Console.WriteLine($"Check the output file to decide if the result is acceptable.");
            break;

        case EventSeverity.Error:
            throw new Exception($"Unable to convert document to {conformance} because of critical conversion events.");
    }
}
			
サンプル・プロジェクト(C)をダウンロード ReadMeを開く
サンプル・プロジェクト(C#)をダウンロード ReadMeを開く
サンプル・プロジェクトをダウンロード

見積もり

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

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


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

> PDF Structure (PDF構成)

> PDF Imager-LP (画像化)

> PDF Stamper (電子印鑑)

- Pdftools SDK

> Pdftool SDK APIリファレンス