PDF Tool APIサンプル集:行間を広くした文字列・文字間隔をかえた文字列
PDF出力する元ファイル(入力ファイル)パス、PDFの出力先となるファイルパスを指定して
行間を広くした文字列・文字間隔をかえた文字列を書きこんで出力するコンソールアプリケーションです。
概要
コマンドラインでの実行例
sample.exe c:\test\test.pdf c:\sav\out.pdf
ダウンロード
出力結果イメージ
サンプルコード
/*
Antenna House PDF Tool API V7.0
C# Interface sample program
概要:行間を広くした文字列・文字間隔をかえた文字列の描画のサンプル
Copyright 2021 Antenna House,Inc.
*/
using System;
using PdfTkNet;
namespace sample05cs
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("PDF Tool API V7.0 C# サンプル");
// 入出力ファイル名と設定ファイル名の初期値を設定
string inFilePath = @"C:\test\test.pdf";
string outFilePath = @"C:\sav\out.pdf";
// 入力ファイル名
if (args.Length > 0)
{
inFilePath = args[0];
}
// 出力ファイル名
if (args.Length > 1)
{
outFilePath = args[1];
}
try
{
using (PtlParamInput input = new PtlParamInput(inFilePath))
using (PtlParamOutput output = new PtlParamOutput(outFilePath))
using (PtlPDFDocument doc = new PtlPDFDocument())
{
doc.load(input);
using (PtlPages pages = doc.getPages())
using (PtlPage page0 = pages.get(0))
using (PtlSize pageSize = page0.getSize())
using (PtlContent content = page0.getContent())
using (PtlColorDeviceRGB colorRed = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
using (PtlParamFont fontNormal = new PtlParamFont("メイリオ", 18.0f, false, false, true))
using (PtlRect rect = new PtlRect(10, 10, pageSize.getWidth() - 10, pageSize.getHeight() - 10))
using (PtlTextBox textBox = content.drawTextBox(rect, PtlContent.ALIGN.ALIGN_TOP_LEFT, pageSize.getWidth() - 20, pageSize.getHeight() - 20))
{
// TextBoxの縁取りを付ける
textBox.setOutlineColor(colorRed);
using (PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox())
{
paramWriteString.setFont(fontNormal);
string text50 = ("通常文字。");
textBox.writeStringNL(text50, paramWriteString);
string text51 = ("「これは、私が小さいときに、村の茂平というおじいさんからきいたお話です。むかしは、私たちの村のちかくの、中山というところに小さなお城があって、中山さまというおとのさまが、おられたそうです。その中山から、少しはなれた山の中に、「ごん狐」という狐がいました。」(新美南吉「ごん狐」)");
textBox.writeStringNL(text51, paramWriteString);
textBox.writeNL();
paramWriteString.setLineSpacing(1.5f);
string text60 = ("行間を広くします。");
textBox.writeStringNL(text60, paramWriteString);
string text61 = ("「これは、私が小さいときに、村の茂平というおじいさんからきいたお話です。むかしは、私たちの村のちかくの、中山というところに小さなお城があって、中山さまというおとのさまが、おられたそうです。その中山から、少しはなれた山の中に、「ごん狐」という狐がいました。」(新美南吉「ごん狐」)");
textBox.writeStringNL(text61, paramWriteString);
textBox.writeNL();
paramWriteString.setLineSpacing(1.0f);
string text40 = ("行間を狭くします。");
textBox.writeStringNL(text40, paramWriteString);
string text41 = ("「これは、私が小さいときに、村の茂平というおじいさんからきいたお話です。むかしは、私たちの村のちかくの、中山というところに小さなお城があって、中山さまというおとのさまが、おられたそうです。その中山から、少しはなれた山の中に、「ごん狐」という狐がいました。」(新美南吉「ごん狐」)");
textBox.writeStringNL(text41, paramWriteString);
textBox.writeNL();
string text7 = ("文字間隔をかえてみます。");
textBox.writeStringNL(text7, paramWriteString);
string text72 = ("文字間隔狭い(-1)。");
paramWriteString.setCharSpacing(-1);
textBox.writeStringNL(text72, paramWriteString);
string text73 = ("文字間隔広い(1)。");
paramWriteString.setCharSpacing(1);
textBox.writeStringNL(text73, paramWriteString);
string text74 = ("文字間隔広い(2)。");
paramWriteString.setCharSpacing(2);
textBox.writeStringNL(text74, paramWriteString);
}
textBox.terminate();
}
doc.save(output);
}
}
catch (PtlException e)
{
Console.WriteLine(string.Format("Error code : {0} {1}", e.getErrorCode(), e.getErrorMessage()));
return;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}
}
}
}

