/*
Antenna House PDF Tool API V7.0
C++ Interface sample program
概要:フォームデータのXFDFへのエクスポート
Copyright 2021 Antenna House,Inc.
*/
#include < PdfTk.h >
#include < stdio.h >
using namespace PdfTk;
using namespace std;
int main(int argc, char* argv[])
{
if (argc != 3)
{
printf("usage: ExportFormDataXFDF.exe in-pdf-file out-xfdf-file \n");
return 1;
}
try {
PtlParamInput input(argv[1]);
PtlParamOutput output(argv[2]);
PtlPDFDocument doc;
// PDFファイルをロードします。
doc.load(input);
doc.exportFormFieldsToXFDF(output); //フォームフィールドデータのXFDF文書へのエクスポート
printf("-- 完了 --\n");
}
catch (const PtlException& e)
{
fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());
return 1;
}
}
PDF Tool APIサンプルコード:PDF フォームデータのXFDF へのエクスポート
対話フォームPDFからフォームデータのみを抜き出したXFDFファイルを作成します。
概要
サンプルコードの概要
この操作例では入力済みフォームフィールドのデータをXFDFファイルの形で出力しています。
XFDFファイルはテキストエディタなどで開いて内容を確認することや書き換えることができます。
- PtlPDFDocument.importFormFieldsFromXFDF(PtlParamInput inParam): フォームデータをXFDF形式で書き出す
サンプルコード
/*
Antenna House PDF Tool API V7.0
Java Interface sample program
概要:フォームデータのXFDFへのエクスポート
Copyright 2021 Antenna House,Inc.
*/
package Sample;
import jp.co.antenna.ptl.*;
public class ExportFormDataXFDF {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 2)
{
System.out.println("usage: java ExportFormDataXFDF in-pdf-file out-xfdf-file");
return;
}
try (PtlParamInput input = new PtlParamInput(args[0]);
PtlParamOutput output = new PtlParamOutput(args[1]);
PtlPDFDocument doc = new PtlPDFDocument())
{
// PDFファイルをロードします。
doc.load(input);
doc.exportFormFieldsToXFDF(output); //フォームフィールドデータのXFDF文書へのエクスポート
}
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 V7.0
.NET Interface sample program
概要:フォームデータのXFDFへのエクスポート
Copyright 2021 Antenna House,Inc.
*/
using System;
using PdfTkNet;
namespace ExportFormDataXFDF
{
class ExportFormDataXFDF
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("usage: ExportFormDataXFDF.exe in-pdf-file out-xfdf-file");
return;
}
try
{
using (PtlParamInput input = new PtlParamInput(args[0]))
using (PtlParamOutput output = new PtlParamOutput(args[1]))
using (PtlPDFDocument doc = new PtlPDFDocument())
{
// PDFファイルをロードします。
doc.load(input);
doc.exportFormFieldsToXFDF(output); //フォームフィールドデータのXFDF文書へのエクスポート
Console.WriteLine("-- 完了 --");
}
}
catch (PtlException pex)
{
Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP());
pex.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
実行例
コマンドラインでの実行例
ExportFormDataXFDF.exe C:\in\formdata.pdf C:\sav\outExportFormDataXFDF.xfdf -- 完了 --
java -jar ExportFormDataXFDF.jar C:\in\formdata.pdf C:\sav\outExportFormDataXFDF.xfdf -- 完了 --
ExportFormDataXFDF.exe C:\in\formdata.pdf C:\sav\outExportFormDataXFDF.xfdf -- 完了 --
出力結果イメージ
出力されたXFDFファイルには入力PDFのフォームフィールドのデータが出力されています。

