OEM販売のご相談
ご相談ください!

PDF Tool APIサンプルコード:PDF/A変換:PDFA/-3b、PDF/A-1a、PDF/A-2a、PDFA-3aへの変換

機能イメージ

入力PDFをPDF/Aへ変換します

概要

サンプルコードの概要

指定したPDFを指定したバージョンのPDF/Aへ変換します。

  • PtlPDFFixUp: PDF/A準拠のチェック変換を表現したクラス
  • PtlPDFFixUp.setSaveOption(): 保存時のオプションを設定
  • PtlPDFFixUp.setICCProfileCMYK(): 出力インテントのプロファイル(CMYK用)
  • PtlPDFFixUp.setICCProfileRGB(): 出力インテントのプロファイル(RGB用)
  • PtlPDFFixUp.fixUpPDFA(): PDF/Aへの変換
  • PtlPDFFixUp.save(): PDF文書を保存

サンプルコード

/*
	Antenna House PDF Tool API V8.0
	C++ Interface sample program

	概要:PDF/A,PDF/E-1への変換

	Copyright 2021-2025 Antenna House,Inc.
*/
#include 

using namespace std;
using namespace PdfTk;

int main(int argc, char* argv[])
{
	if (argc < 4)
	{
		printf("usage: FixUpPDFA.exe in-pdf-file out-pdf-file 規格\n");
		printf("規格\n1 : PDF/A-1b  2 : PDF/A-2b  3 : PDF/A-3b  4 : PDF/A-1a  5 : PDF/A-2a  6 : PDF/A-3a  7 : PDF/A-4  8 : PDF/E-1\n");
		return 1;
	}
	try {
		PtlPDFFixUp::PDFA_TYPE type;
		std::string desc;
		bool pdfe1 = false;

		const char* kind = argv[3];
		switch (kind[0]) {
		case '1':
			type = PtlPDFFixUp::PDFA_1B;
			desc = "PDF/A-1b";
			break;
		case '2':
			type = PtlPDFFixUp::PDFA_2B;
			desc = "PDF/A-2b";
			break;
		case '3':
			type = PtlPDFFixUp::PDFA_3B;
			desc = "PDF/A-3b";
			break;
		case '4':
			type = PtlPDFFixUp::PDFA_1A;
			desc = "PDF/A-1a";
			break;

		case '5':
			type = PtlPDFFixUp::PDFA_2A;
			desc = "PDF/A-2a";
			break;
		case '6':
			type = PtlPDFFixUp::PDFA_3A;
			desc = "PDF/A-3a";
			break;

		case '7':
			type = PtlPDFFixUp::PDFA_4;
			desc = "PDF/A-4";
			break;
		case '8':
			pdfe1 = true;
			desc = "PDF/E-1";
			break;

		default:
			printf("usage: FixUpPDFA.exe in-pdf-file out-pdf-file 規格\n");
			printf("規格\n1 : PDF/A-1b  2 : PDF/A-2b  3 : PDF/A-3b  4 : PDF/A-1a  5 : PDF/A-2a  6 : PDF/A-3a  7 : PDF/A-4  8 : PDF/E-1\n");
			return 1;
		}

		PtlParamInput input(argv[1]);
		PtlParamOutput output(argv[2]);
		PtlPDFFixUp fix;
		PtlParamInput iccpcmyk("JapanColor2001Coated.icc");
		PtlParamInput iccprgb("sRGB2014.icc");

		fix.setSaveOption(PtlPDFFixUp::SAVE_OPTION::SAVE_RECONSTRUCT);	//保存時のオプションを設定
		fix.setICCProfileCMYK(iccpcmyk);		//出力インテントのプロファイル(CMYK用)
		fix.setICCProfileRGB(iccprgb);			//出力インテントのプロファイル(RGB用)

		bool bl;
		//
		if (pdfe1)
		{
			bl = fix.fixUpPDFE(input);
		}
		else
		{
			// PDF/Aへの変換
			bl = fix.fixUpPDFA(type, input);
		}
		if (bl)
		{
			printf("%s への変換に成功しました。\n", desc.c_str());
		}
		else
		{
			printf("%s への変換に失敗しました。\n", desc.c_str());

			//変換エラーの内容を取得する
			PtlPDFFixUpErrors fxuperrs = fix.getErrors();
			int count = fxuperrs.getCount();
			printf("エラー数 : %d\n",  count);
			for (int i = 0; i < count; i++)
			{
				PtlPDFFixUpError fxuperr = fxuperrs.get(i);
				fprintf(stderr, "%d\n : %s\n", fxuperr.getErrorCode(), fxuperr.getErrorMessageJP().c_str());
			}
		}

		// PDF文書を保存
		fix.save(output);

		printf("-- 完了 --\n");
	}
	catch (PtlException e)
	{
		fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());
		return 1;
	}
	return 0;
}

            
/*
	Antenna House PDF Tool API V8.0
	Java Interface sample program

	概要:PDF/A,PDF/E-1への変換

	Copyright 2021-2025 Antenna House,Inc.
*/

package Sample;

import jp.co.antenna.ptl.*;

public class FixUpPDFA {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length < 3)
        {
            System.out.println("usage: java FixUpPDFA in-pdf-file out-pdf-file");
            System.out.println("規格\n1 : PDF/A-1b  2 : PDF/A-2b  3 : PDF/A-3b  4 : PDF/A-1a  5 : PDF/A-2a  6 : PDF/A-3a  7 : PDF/A-4  8 : PDF/A-4f  9 : PDF/A-4e  10 : PDF/E-1");
            return;
        }

        PtlPDFFixUp.PDFA_TYPE type = PtlPDFFixUp.PDFA_TYPE.PDFA_2B;
        String desc = args[2];
        boolean pdfe1 = false; 
        switch (args[2])
        {
        case "1":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_1B;
            desc = "PDF/A-1b";
            break;
        case "2":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_2B;
            desc = "PDF/A-2b";
            break;
        case "3":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_3B;
            desc = "PDF/A-3b";
            break;
        case "4":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_1A;
            desc = "PDF/A-1a";
            break;
        case "5":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_2A;
            desc = "PDF/A-2a";
            break;
        case "6":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_3A;
            desc = "PDF/A-3a";
            break;
        case "7":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_4;
            desc = "PDF/A-4";
            break;
        case "8":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_4F;
            desc = "PDF/A-4f";
            break;
        case "9":
            type = PtlPDFFixUp.PDFA_TYPE.PDFA_4E;
            desc = "PDF/A-4e";
            break;
        case "10":
            pdfe1 = true;
            desc = "PDF/E-1";
            break;
        default:
            System.out.println("usage: FixUpPDFA.exe in-pdf-file out-pdf-file");
            System.out.println("規格\n1 : PDF/A-1b  2 : PDF/A-2b  3 : PDF/A-3b  4 : PDF/A-1a  5 : PDF/A-2a  6 : PDF/A-3a  7 : PDF/A-4  8 : PDF/A-4f  9 : PDF/A-4e  10 : PDF/E-1");
            return;
        }

        try (PtlParamInput inputFile = new PtlParamInput(args[0]);
             PtlParamOutput outputFile = new PtlParamOutput(args[1]);
             PtlPDFFixUp fix = new PtlPDFFixUp();
             PtlParamInput iccpcmyk = new PtlParamInput("JapanColor2001Coated.icc");
             PtlParamInput iccprgb = new PtlParamInput("sRGB2014.icc"))
             //PtlParamInput iccpcmyk = new PtlParamInput("EuroscaleCoated.icc");
             //PtlParamInput iccprgb = new PtlParamInput("AdobeRGB1998.icc"))
        {
            fix.setSaveOption(PtlPDFFixUp.SAVE_OPTION.SAVE_RECONSTRUCT);    //保存時のオプションを設定
            fix.setICCProfileCMYK(iccpcmyk);        //出力インテントのプロファイル(CMYK用)
            fix.setICCProfileRGB(iccprgb);          //出力インテントのプロファイル(RGB用)
            
            boolean bl;
            if(pdfe1)
            {
                // PDF/E-1への変換
                bl = fix.fixUpPDFE(inputFile);
            }
            else
            {
                // PDF/Aへの変換
                bl = fix.fixUpPDFA(type, inputFile);
            }
                
            if (bl)
            {
                System.out.println(desc + " への変換に成功しました。");
            }
            else
            {
                System.out.println(desc + " への変換に失敗しました。");

                //変換エラーの内容を取得する
                try (PtlPDFFixUpErrors fxuperrs = fix.getErrors())
                {
	                int count = fxuperrs.getCount();
	                System.out.println("エラー数 : " + count);
	                for (int i = 0; i < count; i++)
	                {
	                    try (PtlPDFFixUpError fxuperr = fxuperrs.get(i))
	                    {
	                    	System.out.println(fxuperr.getErrorCode() + " : " + fxuperr.getErrorMessageJP());
	                    }
	                }
	            }
            }

            // PDF文書を保存
            fix.save(outputFile);
        }
        catch (PtlException pex) {
            System.out.println("PtlException : ErrorCode = " + pex.getErrorCode() + "\n  " + pex.getErrorMessage());
        }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        catch (Error ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        finally {
            System.out.println("-- 完了 --");
        }
    }
}

            
/*
	Antenna House PDF Tool API V8.0
	.NET Interface sample program

	概要:PDF/A,PDF/E-1への変換

	Copyright 2021-2025 Antenna House,Inc.
*/

using System;

using PdfTkNet;

if (args.Length < 3)
{
	Console.WriteLine("usage: FixUpPDFA.exe in-pdf-file out-pdf-file");
	Console.WriteLine("規格\n1 : PDF/A-1b  2 : PDF/A-2b  3 : PDF/A-3b  4 : PDF/A-1a  5 : PDF/A-2a  6 : PDF/A-3a  7 : PDF/A-4  8 : PDF/E-1");
	return;
}


try
{
	using (PtlParamInput inputFile = new PtlParamInput(args[0]))
	using (PtlParamOutput outputFile = new PtlParamOutput(args[1]))
	using (PtlPDFFixUp fix = new PtlPDFFixUp())
	using (PtlParamInput iccpcmyk = new PtlParamInput(@"JapanColor2001Coated.icc"))
	using (PtlParamInput iccprgb = new PtlParamInput(@"sRGB2014.icc"))
	{

		PtlPDFFixUp.PDFA_TYPE type = PtlPDFFixUp.PDFA_TYPE.PDFA_2B;
		string desc;
		bool pdfe1 = false;
		switch (args[2])
		{
			case "1":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_1B;
				desc = "PDF/A-1b";
				break;
			case "2":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_2B;
				desc = "PDF/A-2b";
				break;
			case "3":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_3B;
				desc = "PDF/A-3b";
				break;
			case "4":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_1A;
				desc = "PDF/A-1a";
				break;
			case "5":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_2A;
				desc = "PDF/A-2a";
				break;
			case "6":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_3A;
				desc = "PDF/A-3a";
				break;
			case "7":
				type = PtlPDFFixUp.PDFA_TYPE.PDFA_4;
				desc = "PDF/A-4";
				break;
			case "8":
				pdfe1 = true;
				desc = "PDF/E-1";
				break;

			default:
				Console.WriteLine("usage: FixUpPDFA.exe in-pdf-file out-pdf-file");
				Console.WriteLine("規格\n1 : PDF/A-1b  2 : PDF/A-2b  3 : PDF/A-3b  4 : PDF/A-1a  5 : PDF/A-2a  6 : PDF/A-3a  7 : PDF/A-4  8 : PDF/E-1");
				return;
		}

		fix.setSaveOption(PtlPDFFixUp.SAVE_OPTION.SAVE_RECONSTRUCT);    //保存時のオプションを設定
		fix.setICCProfileCMYK(iccpcmyk);        //出力インテントのプロファイル(CMYK用)
		fix.setICCProfileRGB(iccprgb);          //出力インテントのプロファイル(RGB用)

		bool bl;

		if (pdfe1)
		{
			// PDF/E-1への変換
			bl = fix.fixUpPDFE(inputFile);
		}
		else
		{
			// PDF/Aへの変換
			bl = fix.fixUpPDFA(type, inputFile);
		}

		if (bl)
		{
			Console.WriteLine(desc + "への変換に成功しました。");
		}
		else
		{
			Console.WriteLine(desc + "への変換に失敗しました。");

			//変換エラーの内容を取得する
			using (PtlPDFFixUpErrors fxuperrs = fix.getErrors())
			{
				int count = fxuperrs.getCount();
				Console.WriteLine("エラー数 : " + count);
				for (int i = 0; i < count; i++)
				{
					using (PtlPDFFixUpError fxuperr = fxuperrs.get(i))
					{
						Console.WriteLine(fxuperr.getErrorCode() + " : " + fxuperr.getErrorMessageJP());
					}
				}
			}
		}
		// PDF文書を保存
		fix.save(outputFile);
	}
	Console.WriteLine("-- 完了 --");
}
catch (PtlException pex)
{
	Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP());
	pex.Dispose();
}
catch (Exception ex)
{
	Console.WriteLine(ex.Message);
}

            
AHPDFToolCmd80 -fixedUpPDFA -type 1a -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-1a.pdf

AHPDFToolCmd80 -fixedUpPDFA -type 1b -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-1b.pdf

AHPDFToolCmd80 -fixedUpPDFA -type 2a -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-2a.pdf

AHPDFToolCmd80 -fixedUpPDFA -type 2b -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-2b.pdf

AHPDFToolCmd80 -fixedUpPDFA -type 3a -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-3a.pdf

AHPDFToolCmd80 -fixedUpPDFA -type 3b -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-3b.pdf


            

サンプルコードのダウンロードはこちら

実行例

コマンドラインでの実行例

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-1b.pdf 1
PDF/A-1b への変換に成功しました。
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-2b.pdf 2
PDF/A-2b への変換に成功しました。
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-3b.pdf 3
PDF/A-3b への変換に成功しました。
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-1a.pdf 4
PDF/A-1a への変換に失敗しました。
エラー数 : 1
276
 : テキストをユニコードにマッピングできない
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-2a.pdf 5
PDF/A-2a への変換に失敗しました。
エラー数 : 3
276
 : テキストをユニコードにマッピングできない
700
 : MarkInfoがない
702
 : 構造ツリーのルートエントリがない
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-3a.pdf 6
PDF/A-3a への変換に失敗しました。
エラー数 : 3
276
 : テキストをユニコードにマッピングできない
700
 : MarkInfoがない
702
 : 構造ツリーのルートエントリがない
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-4.pdf 7
PDF/A-4 への変換に失敗しました。
エラー数 : 1
100
 : サポート外のPDFバージョン
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFE-1.pdf 8
PDF/E-1 への変換に失敗しました。
エラー数 : 1
276
 : テキストをユニコードにマッピングできない
-- 完了 --
        
java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-1b.pdf 1
PDF/A-1b への変換に成功しました。
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-2b.pdf 2
PDF/A-2b への変換に成功しました。
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-3b.pdf 3
PDF/A-3b への変換に成功しました。
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-1a.pdf 4
PDF/A-1a への変換に失敗しました。
エラー数 : 1
276 : テキストをユニコードにマッピングできない
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-2a.pdf 5
PDF/A-2a への変換に失敗しました。
エラー数 : 3
276 : テキストをユニコードにマッピングできない
700 : MarkInfoがない
702 : 構造ツリーのルートエントリがない
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-3a.pdf 6
PDF/A-3a への変換に失敗しました。
エラー数 : 3
276 : テキストをユニコードにマッピングできない
700 : MarkInfoがない
702 : 構造ツリーのルートエントリがない
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFA-4.pdf 7
PDF/A-4 への変換に失敗しました。
エラー数 : 1
100 : サポート外のPDFバージョン
-- 完了 --

java -jar FixUpPDFA.jar C:\in\test.pdf C:\sav\outFixUpPDFE-1.pdf 8
PDF/A-4f への変換に失敗しました。
エラー数 : 1
100 : サポート外のPDFバージョン
-- 完了 --
        
FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-1b.pdf 1
PDF/A-1bへの変換に成功しました。
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-2b.pdf 2
PDF/A-2bへの変換に成功しました。
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-3b.pdf 3
PDF/A-3bへの変換に成功しました。
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-1a.pdf 4
PDF/A-1aへの変換に失敗しました。
エラー数 : 1
276 : テキストをユニコードにマッピングできない
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-2a.pdf 5
PDF/A-2aへの変換に失敗しました。
エラー数 : 3
276 : テキストをユニコードにマッピングできない
700 : MarkInfoがない
702 : 構造ツリーのルートエントリがない
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-3a.pdf 6
PDF/A-3aへの変換に失敗しました。
エラー数 : 3
276 : テキストをユニコードにマッピングできない
700 : MarkInfoがない
702 : 構造ツリーのルートエントリがない
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFA-4.pdf 7
PDF/A-4への変換に失敗しました。
エラー数 : 1
100 : サポート外のPDFバージョン
-- 完了 --

FixUpPDFA.exe C:\in\test.pdf C:\sav\outFixUpPDFE-1.pdf 8
PDF/E-1への変換に失敗しました。
エラー数 : 1
276 : テキストをユニコードにマッピングできない
-- 完了 --
        
AHPDFToolCmd80 -fixedUpPDFA -type 1a -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-1a.pdf
FileName: C:\in\test.pdf
Error Code =276
Error Message =Text can not be mapped to Unicode.

 use time 0.237000s


AHPDFToolCmd80 -fixedUpPDFA -type 1b -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-1b.pdf
FileName: C:\in\test.pdf
ok!

 use time 0.332000s


AHPDFToolCmd80 -fixedUpPDFA -type 2a -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-2a.pdf
FileName: C:\in\test.pdf
Error Code =276
Error Message =Text can not be mapped to Unicode.
Error Code =700
Error Message =Document Catalog has not MarkInfo entry.
Error Code =702
Error Message =Document Catalog has not StructTreeRoot entry.

 use time 0.227000s


AHPDFToolCmd80 -fixedUpPDFA -type 2b -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-2b.pdf
FileName: C:\in\test.pdf
ok!

 use time 0.348000s


AHPDFToolCmd80 -fixedUpPDFA -type 3a -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-3a.pdf
FileName: C:\in\test.pdf
Error Code =276
Error Message =Text can not be mapped to Unicode.
Error Code =700
Error Message =Document Catalog has not MarkInfo entry.
Error Code =702
Error Message =Document Catalog has not StructTreeRoot entry.

 use time 0.226000s


AHPDFToolCmd80 -fixedUpPDFA -type 3b -RGBProfile "sRGB2014.icc" -CMYKProfile "JapanColor2001Coated.icc" -log -d  C:\in\test.pdf -o C:\sav\outFixUpPDFA-3b.pdf
FileName: C:\in\test.pdf
ok!

 use time 0.350000s
        

出力結果イメージ

PDF/A-1b への変換結果

出力イメージ

PDF/A-2b への変換結果

出力イメージ

PDF/A-3b への変換結果

出力イメージ

PDF/A-1a への変換結果

出力イメージ

PDF/A-2a への変換結果

出力イメージ

PDF/A-3a への変換結果

出力イメージ

PDF/A-3b への変換結果

出力イメージ

サンプルコードのダウンロード

サンプルコード

サンプルで使用した入出力PDF