/*
Antenna House PDF Tool API V7.0
C++ Interface sample program
概要:開き方の取得
Copyright 2013-2021 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が持つ文書プロパティから文書が持つ情報を取得できます。
- PtlPDFDocument.getDocProperty() : PDFドキュメントの文書プロパティを取得
- PtlDocProperty : PDFの文書プロパティを表現したクラス
- PtlDocProperty.getDocInfo() : 文書情報を取得
- PtlDocInfo : PDFの文書情報を表現したクラス
- PtlDocInfo.getTitle() : タイトルの取得
- PtlDocInfo.getAuthor() : 著者を取得
- PtlDocInfo.getSubject() : サブジェクトを取得
- PtlDocInfo.getKeywords() : キーワードを取得
- PtlDocInfo.getCreator() : 元のドキュメントを生成した準拠製品の名前を取得
- PtlDocInfo.getProducer() : PDF に変換した準拠製品の名前を取得
- PtlDocInfo.getCreationDate() : 作成日付を取得
- PtlDocInfo.getModDate() : 更新日付を取得
- PtlCustomProperties : カスタムプロパティのコンテナを表現するクラス
- PtlCustomProperties.isEmpty() : コンテナが空かどうかを取得
- PtlCustomProperties.getCount() : カスタムプロパティの数を取得
- PtlCustomProperties.get(int index) : 指定したインデックス番号のカスタムプロパティを取得。indexは0が先頭
- PtlCustomProperty : カスタムプロパティを表現するクラス
サンプルコード
/*
Antenna House PDF Tool API V7.0
Java Interface sample program
概要:文書情報の取得
Copyright 2015-2021 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 V7.0
.NET Interface sample program
概要:文書情報の取得
Copyright 2013-2021 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("-- 完了 --");
}
}
}
}
AHPDFToolCmd70.exe -getFileInfo –d c:\in\test.pdf
実行例
コマンドラインでの実行例
GetDocInfo.exe C:\in\test.pdf Title : タイトル Author : 作成者 Subject : サブタイトル Keywords : キーワード Creator : クセロ PDF v2.00β3 Producer : Xelo PDF Library CreationDate : 2007/4/24 10:23:31 ModDate : 2013/5/23 16:44:25 完了!
java -jar GetDocInfo.jar C:\in\test.pdf Title : タイトル Author : 作成者 Subject : サブタイトル Keywords : キーワード Creator : クセロ PDF v2.00β3 Producer : Xelo PDF Library CreationDate : 2007/4/24 10:23:31 ModDate : 2013/5/23 16:44:25 -- 完了 --
GetDocInfo.exe C:\in\test.pdf Title : タイトル Author : 作成者 Subject : サブタイトル Keywords : キーワード Creator : クセロ PDF v2.00β3 Producer : Xelo PDF Library CreationDate : 2007/4/24 10:23:31 ModDate : 2013/5/23 16:44:25 -- 完了 --
AHPDFToolCmd70.exe -getFileInfo -d c:\in\test.pdf
PDF Version
major : 1
minor : 5
Document Information
Title : タイトル
Subject : サブタイトル
Author : 作成者
Keywords : キーワード
Creator : クセロ PDF v2.00β3
Producer : Xelo PDF Library
CreateDate : 2007/4/24 10:23:31
ModifyDate : 2013/5/23 16:44:25
Max Page : 16
View Information
Direction : Left to Right
PageLayout : Single Page
PageMode : Use None
FitWindow : false
CenterWindow : false
Full Screen : false
Display Doc Title : false
Hide Menubar : false
Hide Toolbar : false
Hide Window UI : false
Action : none
Security Information
Not Encrypted.
Standard Information
Signature : false
PDF/A : false
PDF/X : false
use time 0.033000s
出力結果イメージ
入力PDFに指定したPDF文書の文書プロパティに含まれる文書情報がコマンドライン上に表示されます。

