/*
Antenna House PDF Tool API V8.0
C++ Interface sample program
概要:ページの拡大縮小
Copyright 2015-2025 Antenna House, Inc.
*/
#include < PdfTk.h >
#include < stdio.h >
using namespace PdfTk;
int main(int argc, char* argv[])
{
if (argc < 3) {
printf("usage: ZoomPage.exe in-pdf-file out-pdf-file\n");
return 1;
}
try
{
PtlParamInput input(argv[1]);
PtlParamOutput output(argv[2]);
PtlPDFDocument doc;
// PDFファイルをロードします。
doc.load(input);
//ページコンテナの取得
PtlPages& pages = doc.getPages();
if (pages.isEmpty()){
printf("ページコンテナが空\n");
return 1;
}
int numPages = doc.getPageCount();
for(int i=0; i < numPages; ++i) {
// ページの取得
PtlPage page = pages.get(i);
page.zoom(0.5f);
}
// ファイルに保存します。
doc.save(output);
printf("完了!\n");
}
catch (const PtlException &e)
{
fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());
return 1;
}
return 0;
}
PDF Tool APIサンプルコード:指定したサイズにページを拡大・縮小
指定したサイズにページを拡大・縮小します。
概要
サンプルコードの概要
PDFのページをページを指定したサイズに拡大・縮小します。
- PtlPage :ページのコンテナを表現するクラス
- PtlPage.zoom(float ratio) :ページの拡大縮小
サンプルコード
/*
Antenna House PDF Tool API V8.0
Java Interface sample program
概要:ページの拡大縮小
Copyright 2018-2025 Antenna House, Inc.
*/
package Sample;
import jp.co.antenna.ptl.*;
public class ZoomPage {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 2)
{
System.out.println("usage: java ZoomPage in-pdf-file out-pdf-file");
return;
}
try (PtlParamInput inputFile = new PtlParamInput(args[0]);
PtlParamOutput outputFile = new PtlParamOutput(args[1]);
PtlPDFDocument doc = new PtlPDFDocument())
{
// PDFファイルをロード
doc.load(inputFile);
try (PtlPages pages = doc.getPages()) //ページコンテナの取得
{
// ページコンテナが空かどうか
if (pages.isEmpty())
{
System.out.println("ページコンテナが空\n");
return;
}
int numPages = doc.getPageCount();
for (int i = 0; i < numPages; ++i)
{
try (PtlPage page = pages.get(i)) // ページの取得
{
page.zoom(0.5f);
//page.zoom(2.0f);
}
}
}
// ファイルに保存します。
doc.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
概要:ページの拡大縮小
Copyright 2015-2025 Antenna House, Inc.
*/
using System;
using PdfTkNet;
namespace ZoomPage
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("usage: ZoomPage.exe in-pdf-file out-pdf-file");
return;
}
try
{
using (PtlParamInput inputFile = new PtlParamInput(args[0]))
using (PtlParamOutput outputFile = new PtlParamOutput(args[1]))
using (PtlPDFDocument doc = new PtlPDFDocument())
{
// PDFファイルをロードします。
doc.load(inputFile);
using (PtlPages pages = doc.getPages()) // ページコンテナ
{
// ページコンテナが空かどうか
if (pages.isEmpty())
{
Console.WriteLine("ページコンテナが空");
return;
}
int numPages = doc.getPageCount();
for (int i = 0; i < numPages; ++i)
{
using (PtlPage page = pages.get(i)) // ページの取得
{
page.zoom(0.5f);
//page.zoom(2.0f);
}
}
}
// ファイルに保存します。
doc.save(outputFile);
}
}
catch (PtlException pex)
{
Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP());
pex.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("-- 完了 --");
}
}
}
}
AHPDFToolCmd80.exe -zoom -pageNo 8 -size 0 -d C:\in\in.pdf -o C:\sav\outZoomPage.pdf
実行例
コマンドラインでの実行例
ZoomPage.exe C:\in\in.pdf C:\sav\outZoomPage.pdf 完了!
java -jar ZoomPage.jar C:\in\in.pdf C:\sav\outZoomPage.pdf -- 完了 --
ZoomPage.exe C:\in\in.pdf C:\sav\outZoomPage.pdf -- 完了 --
AHPDFToolCmd80.exe -zoom -pageNo 0 -size 8 -d C:\in\in.pdf -o C:\sav\outZoomPage.pdf use time 0.207000s
出力結果イメージ
入力したPDFの全てのページのサイズが0.5倍に変更されています。
コマンドでは入力したPDFの全てのページのサイズが0.5倍に変更されています。

