/*
Antenna House PDF Tool API V8.0
C++ Interface sample program
概要:文書情報の取得
Copyright 2013-2025 Antenna House, Inc.
*/
#include < PdfTk.h >
#include < stdio.h >
using namespace PdfTk;
int main(int argc, char* argv[])
{
if (argc < 2) {
printf("usage: GetDocInfo.exe in-pdf-file\n");
return 1;
}
try
{
PtlParamInput input(argv[1]);
PtlPDFDocument doc;
// PDFファイルをロードします。
doc.load(input);
//PDFの文書プロパティ
PtlDocProperty& docproperty = doc.getDocProperty();
//PDFの文書情報
PtlDocInfo& docinf = docproperty.getDocInfo();
//タイトル取得
PtlParamString title = docinf.getTitle();
printf("Title : %s\n", title.c_str());
//著者取得
PtlParamString author = docinf.getAuthor();
printf("Author : %s\n", author.c_str());
//サブジェクト取得
PtlParamString subject = docinf.getSubject();
printf("Subject : %s\n", subject.c_str());
//キーワード取得
PtlParamString keywords = docinf.getKeywords();
printf("Keywords : %s\n", keywords.c_str());
//クリエータ取得
PtlParamString creator = docinf.getCreator();
printf("Creator : %s\n", creator.c_str());
//プロデューサ取得
PtlParamString producer = docinf.getProducer();
printf("Producer : %s\n", producer.c_str());
//作成日付を取得
PtlDate creationDate = docinf.getCreationDate();
printf("CreationDate : %d/%d/%d %d:%d:%d\n"
, creationDate.getYear()
, creationDate.getMonth()
, creationDate.getDay()
, creationDate.getHour()
, creationDate.getMin()
, creationDate.getSec());
//更新日付を取得
PtlDate modDate = docinf.getModDate();
printf("ModDate : %d/%d/%d %d:%d:%d\n"
, modDate.getYear()
, modDate.getMonth()
, modDate.getDay()
, modDate.getHour()
, modDate.getMin()
, modDate.getSec());
printf("完了!\n");
}
catch (const PtlException &e)
{
fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());
}
return 0;
}
PDF Tool APIサンプルコード:文書の情報取得(文書情報のみ)
入力PDFの「タイトル」や「作成者」などの文書情報文書を取得します。
概要
サンプルコードの概要
文書の情報を取得します。
- PtlDocProperty :PDFの文書プロパティを表現したクラスです
- PtlPDFDocument.getDocProperty() :文書プロパティを取得
- PtlDocInfo :PDFの文書情報を表現したクラスです
- PtlDocProperty.getDocInfo() :文書情報を取得
- PtlDocInfo.getTitle() :タイトルを取得
サンプルコード
/*
Antenna House PDF Tool API V8.0
Java Interface sample program
概要:文書情報の取得
Copyright 2015-2025 Antenna House, Inc.
*/
package Sample;
import jp.co.antenna.ptl.*;
public class GetDocInfo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 1)
{
System.out.println("usage: java GetDocInfo in-pdf-file");
return;
}
try (PtlParamInput inputFile = new PtlParamInput(args[0]);
PtlPDFDocument doc = new PtlPDFDocument())
{
// PDFファイルをロード
doc.load(inputFile);
try (PtlDocProperty docProperty = doc.getDocProperty(); //PDFの文書プロパティ
PtlDocInfo docinf = docProperty.getDocInfo()) { //PDFの文書情報
// タイトル取得
System.out.println("Title : " + docinf.getTitle());
// 著者取得
System.out.println("Author : " + docinf.getAuthor());
// サブジェクト取得
System.out.println("Subject : " + docinf.getSubject());
// キーワード取得
System.out.println("Keywords : " + docinf.getKeywords());
// クリエータ取得
System.out.println("Creator : " + docinf.getCreator());
// プロデューサ取得
System.out.println("Producer : " + docinf.getProducer());
// 作成日付を取得
try (PtlDate dateCreate = docinf.getCreationDate())
{
System.out.println("CreationDate : "
+ dateCreate.getYear()
+ "/" + dateCreate.getMonth()
+ "/" + dateCreate.getDay()
+ " " + dateCreate.getHour()
+ ":" + dateCreate.getMin()
+ ":" + dateCreate.getSec());
}
// 更新日付を取得
try (PtlDate dateMod = docinf.getModDate())
{
System.out.println("ModDate : "
+ dateMod.getYear()
+ "/" + dateMod.getMonth()
+ "/" + dateMod.getDay()
+ " " + dateMod.getHour()
+ ":" + dateMod.getMin()
+ ":" + dateMod.getSec());
}
}
}
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
概要:文書情報の取得
Copyright 2013-2025 Antenna House, Inc.
*/
using System;
using PdfTkNet;
namespace GetDocInfo
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("usage: GetDocInfo.exe in-pdf-file");
return;
}
try
{
using (PtlParamInput inputFile = new PtlParamInput(args[0]))
using (PtlPDFDocument doc = new PtlPDFDocument())
{
//PDFファイルをロードします。
doc.load(inputFile);
//PDFの文書プロパティ
using (PtlDocProperty docproperty = doc.getDocProperty())
{
//PDFの文書情報
using (PtlDocInfo docinf = docproperty.getDocInfo())
{
//タイトル取得
Console.WriteLine("Title : " + docinf.getTitle());
//著者取得
Console.WriteLine("Author : " + docinf.getAuthor());
//サブジェクト取得
Console.WriteLine("Subject : " + docinf.getSubject());
//キーワード取得
Console.WriteLine("Keywords : " + docinf.getKeywords());
//クリエータ取得
Console.WriteLine("Creator : " + docinf.getCreator());
//プロデューサ取得
Console.WriteLine("Producer : " + docinf.getProducer());
//作成日付を取得
using (PtlDate date = docinf.getCreationDate())
{
int year = date.getYear();
int month = date.getMonth();
int day = date.getDay();
int hour = date.getHour();
int min = date.getMin();
int sec = date.getSec();
Console.WriteLine("CreationDate : {0}/{1}/{2} {3}:{4}:{5}", year, month, day, hour, min, sec);
}
//更新日付を取得
using (PtlDate date = docinf.getModDate())
{
int year = date.getYear();
int month = date.getMonth();
int day = date.getDay();
int hour = date.getHour();
int min = date.getMin();
int sec = date.getSec();
Console.WriteLine("ModDate : {0}/{1}/{2} {3}:{4}:{5}", year, month, day, hour, min, sec);
}
}
}
}
}
catch (PtlException pex)
{
Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP());
pex.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("-- 完了 --");
}
}
}
}
AHPDFToolCmd80.exe -getFileInfo -docInfo -d C:\in\test1.pdf
実行例
コマンドラインでの実行例
GetDocInfo.exe C:\in\test1.pdf Title : PDF Tool API V7.0 コマンドライン説明書 Author : アンテナハウス株式会社 Subject : Keywords : Creator : AH Formatter V6.6 MR1 for Linux64 : 6.6.2.35616 (2018/10/15 18:42JST) Producer : Antenna House PDF Output Library 6.6.1317 (Linux64) CreationDate : 2021/4/23 11:26:49 ModDate : 2021/5/25 17:33:30 完了!
java -jar GetDocInfo.jar C:\in\test1.pdf Title : PDF Tool API V7.0 コマンドライン説明書 Author : アンテナハウス株式会社 Subject : Keywords : Creator : AH Formatter V6.6 MR1 for Linux64 : 6.6.2.35616 (2018/10/15 18:42JST) Producer : Antenna House PDF Output Library 6.6.1317 (Linux64) CreationDate : 2021/4/23 11:26:49 ModDate : 2021/5/25 17:33:30 -- 完了 --
GetDocInfo.exe C:\in\test1.pdf Title : PDF Tool API V7.0 コマンドライン説明書 Author : アンテナハウス株式会社 Subject : Keywords : Creator : AH Formatter V6.6 MR1 for Linux64 : 6.6.2.35616 (2018/10/15 18:42JST) Producer : Antenna House PDF Output Library 6.6.1317 (Linux64) CreationDate : 2021/4/23 11:26:49 ModDate : 2021/5/25 17:33:30 -- 完了 --
AHPDFToolCmd80.exe -getFileInfo -docInfo -d C:\in\test1.pdf
Document Information
Title : PDF Tool API V7.0 コマンドライン説明書
Subject :
Author : アンテナハウス株式会社
Keywords :
Creator : AH Formatter V6.6 MR1 for Linux64 : 6.6.2.35616 (2018/10/15 18:42JST)
Producer : Antenna House PDF Output Library 6.6.1317 (Linux64)
CreateDate : 2021/4/23 11:26:49
ModifyDate : 2021/5/25 17:33:30
Max Page : 68
use time 0.030000s
出力結果イメージ
APIでの出力では出力される項目はプログラム内で設定しています。
コマンドラインでの出力ではパラメータで指定した項目が出力されます。
パラメータの詳細はオンラインマニュアル
「PDF Tool API コマンドライン説明書」
「8-1 -getFileInfo:PDFの情報取得」をご参照ください

