/*
Antenna House PDF Tool API V8.0
C++ Interface sample program
概要:座標を指定して下線、波線、取り消し線注釈
Copyright 2025- Antenna House, Inc.
*/
#include < PdfTk.h >
#include < stdio.h >
using namespace PdfTk;
void addAnnotSquiggly(PtlAnnots&, PtlQuadPoint&, bool);
void addAnnotStrikeOut(PtlAnnots&, PtlQuadPoint&, bool);
void addAnnotUnderline(PtlAnnots&, PtlQuadPoint&, bool);
int main(int argc, char* argv[])
{
if (argc < 3) {
printf("usage: AppendAnnotCoordinateSample.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();
// 0:先頭ページ
PtlPage page = pages.get(0);
PtlAnnots& annots = page.getAnnots();
// 指定する文字列はすべて横書きなので
bool verticalWriting = false;
// 「編集、共有、印刷が行える操作説明書」
{
// left bottom right top
// 26, 234, 133, 243
PtlQuadPoint quad = PtlQuadPoint();
quad.setTopLeft(PtlPoint(26, 243));
quad.setTopRight(PtlPoint(133, 243));
quad.setBottomLeft(PtlPoint(26, 234));
quad.setBottomRight(PtlPoint(133, 234));
//波状下線注釈
addAnnotSquiggly(annots, quad, verticalWriting);
}
// 「実際に操作してみましょう」
{
// left bottom right top
// 136, 189, 179, 195
PtlQuadPoint quad = PtlQuadPoint();
quad.setTopLeft(PtlPoint(136, 195));
quad.setTopRight(PtlPoint(179, 195));
quad.setBottomLeft(PtlPoint(136, 189));
quad.setBottomRight(PtlPoint(179, 189));
//下線注釈
addAnnotUnderline(annots, quad, verticalWriting);
}
// 「ほんの少しのヘルプで雄弁に文章を書く」
{
// left bottom right top
// 24, 108, 167, 116
PtlQuadPoint quad = PtlQuadPoint();
quad.setTopLeft(PtlPoint(24, 116));
quad.setTopRight(PtlPoint(167, 116));
quad.setBottomLeft(PtlPoint(24, 108));
quad.setBottomRight(PtlPoint(167, 108));
//取り消し線注釈
addAnnotStrikeOut(annots, quad, verticalWriting);
}
// ファイルに保存します。
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;
}
void addAnnotSquiggly(PtlAnnots& annots, PtlQuadPoint& quadPoint, bool verticalWriting)
{
//波状下線注釈
PtlAnnotSquiggly annotSquiggly;
//矩形座標を設定 座標の単位はmmで原点(0,0)は左下
PtlQuadPoints& quadPoints = annotSquiggly.getQuadPoints();
quadPoints.append(quadPoint);
//テキストを縦書き方向に囲むかどうかを設定
annotSquiggly.setVerticalDirection(verticalWriting);
//内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotSquiggly.setTextContents("波状下線注釈サンプル");
// 日時の設定(2025/01/01 00:00:00)
annotSquiggly.setDate(PtlDate(2025, 1, 1, 0, 0, 0));
//注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotSquiggly.setAnnotFlags(PtlAnnotText::FLAG_NOROTATE);
//色を設定 setColor(const PtlColorDeviceRGB& color);
PtlColorDeviceRGB color(1.0f, 0.0f, 0.0f);
annotSquiggly.setColor(color);
//境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotSquiggly.setBorderStyle(PtlAnnotText::BORDER_SOLID);
//境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotSquiggly.setBorderWidth(PtlAnnotText::BORDER_WIDTH_THIN);
//注釈の追加
annots.append(annotSquiggly);
}
void addAnnotStrikeOut(PtlAnnots& annots, PtlQuadPoint& quadPoint, bool verticalWriting)
{
//取り消し線注釈
PtlAnnotStrikeOut annotStrikeOut;
//矩形座標を設定 座標の単位はmmで原点(0,0)は左下
PtlQuadPoints& quadPoints = annotStrikeOut.getQuadPoints();
quadPoints.append(quadPoint);
//テキストを縦書き方向に囲むかどうかを設定
annotStrikeOut.setVerticalDirection(verticalWriting);
//内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotStrikeOut.setTextContents("取り消し線注釈サンプル");
// 日時の設定(2025/01/01 00:00:00)
annotStrikeOut.setDate(PtlDate(2025, 1, 1, 0, 0, 0));
//注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotStrikeOut.setAnnotFlags(PtlAnnotText::FLAG_NOROTATE);
//色を設定 setColor(const PtlColorDeviceRGB& color);
PtlColorDeviceRGB color(1.0f, 0.0f, 0.0f);
annotStrikeOut.setColor(color);
//境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotStrikeOut.setBorderStyle(PtlAnnotText::BORDER_SOLID);
//境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotStrikeOut.setBorderWidth(PtlAnnotText::BORDER_WIDTH_THIN);
//注釈の追加
annots.append(annotStrikeOut);
}
void addAnnotUnderline(PtlAnnots& annots, PtlQuadPoint& quadPoint, bool verticalWriting)
{
//下線注釈
PtlAnnotUnderline annotUnderline;
//矩形座標を設定 座標の単位はmmで原点(0,0)は左下
PtlQuadPoints& quadPoints = annotUnderline.getQuadPoints();
quadPoints.append(quadPoint);
//テキストを縦書き方向に囲むかどうかを設定
annotUnderline.setVerticalDirection(verticalWriting);
//内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotUnderline.setTextContents("下線注釈サンプル");
//日時の設定(2025/01/01 00:00:00)
annotUnderline.setDate(PtlDate(2025, 1, 1, 0, 0, 0));
//注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotUnderline.setAnnotFlags(PtlAnnotText::FLAG_NOROTATE);
//色を設定 setColor(const PtlColorDeviceRGB& color);
PtlColorDeviceRGB color(1.0f, 0.0f, 0.0f);
annotUnderline.setColor(color);
//境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotUnderline.setBorderStyle(PtlAnnotText::BORDER_SOLID);
//境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotUnderline.setBorderWidth(PtlAnnotText::BORDER_WIDTH_THIN);
//注釈の追加
annots.append(annotUnderline);
}
PDF Tool APIサンプルコード:座標を指定して下線、波線、取り消し線注釈を追加
座標取得ツールで取得した座標を指定して下線、波線、取り消し線注釈を追加します。
概要
サンプルコードの概要
指定された座標で 下線、波線、取り消し線注釈を追加します。
- PtlQuadPoint: PDFの矩形4隅座標を表現したクラス
- PtlQuadPoint.setTopLeft(PtlPoint): 座標を設定:上左
- PtlQuadPoint.setTopRight(PtlPoint): 座標を設定:上右
- PtlQuadPoint.setBottomLeft(PtlPoint): 座標を設定:下左
- PtlQuadPoint.setBottomRight(PtlPoint): 座標を設定:下右
- PtlAnnotSquiggly: PDFの波状下線注釈を表現したクラス
- PtlAnnotSquiggly.getQuadPoints(): テキストを囲むQuadPointのコンテナを取得
- PtlAnnots.append(PtlAnnotSquiggly): 注釈を追加
- PtlAnnotStrikeOut: PDFの消し線注釈を表現したクラス
- PtlAnnotStrikeOut.getQuadPoints(): テキストを囲むQuadPointのコンテナを取得
- PtlAnnots.append(PtlAnnotStrikeOut): 注釈を追加
- PtlAnnotUnderline: PDFの下線注釈を表現したクラス
- PtlAnnotUnderline.getQuadPoints(): テキストを囲むQuadPointのコンテナを取得
- PtlAnnots.append(PtlAnnotUnderline): 注釈を追加
サンプルコード
/*
Antenna House PDF Tool API V8.0
Java Interface sample program
概要:テキスト検索して下線、波線、取り消し線注釈
Copyright 2025 Antenna House, Inc.
*/
package Sample;
import jp.co.antenna.ptl.*;
public class AppendAnnotCoordinateSample {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 2)
{
System.out.println("usage: java AppendAnnotCoordinateSample 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();)
{
PtlPage page = pages.get(0);
try (PtlAnnots annots = page.getAnnots())
{
try (PtlQuadPoint quad = new PtlQuadPoint())
{
boolean verticalWriting = false;
// 「編集、共有、印刷が行える操作説明書」
try (PtlQuadPoint quad1 = new PtlQuadPoint())
{
// left bottom right top
// 26, 234, 133, 243
quad1.setTopLeft(new PtlPoint(26, 243));
quad1.setTopRight(new PtlPoint(133, 243));
quad1.setBottomLeft(new PtlPoint(26, 234));
quad1.setBottomRight(new PtlPoint(133, 234));
// 波状下線釈追加
addAnnotSquiggly(annots, quad1, verticalWriting);
}
// 「実際に操作してみましょう」
try (PtlQuadPoint quad2 = new PtlQuadPoint())
{
// left bottom right top
// 136, 189, 179, 195
quad2.setTopLeft(new PtlPoint(136, 195));
quad2.setTopRight(new PtlPoint(179, 195));
quad2.setBottomLeft(new PtlPoint(136, 189));
quad2.setBottomRight(new PtlPoint(179, 189));
// 下線注釈
addAnnotUnderline(annots, quad2, verticalWriting);
}
// 「ほんの少しのヘルプで雄弁に文章を書く」
try (PtlQuadPoint quad3 = new PtlQuadPoint())
{
// left bottom right top
// 24, 108, 167, 116
quad3.setTopLeft(new PtlPoint(24, 116));
quad3.setTopRight(new PtlPoint(167, 116));
quad3.setBottomLeft(new PtlPoint(24, 108));
quad3.setBottomRight(new PtlPoint(167, 108));
// 取り消し線注釈
addAnnotStrikeOut(annots, quad3, verticalWriting);
}
}
}
}
// ファイルに保存します。
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("-- 完了 --");
}
}
public static void addAnnotSquiggly(PtlAnnots annots, PtlQuadPoint quadPoint, boolean verticalWriting) throws PtlException, Exception, Error
{
try (PtlAnnotSquiggly annotSquiggly = new PtlAnnotSquiggly()) // 波状下線注釈
{
// 座標を設定 座標の単位はmmで原点(0,0)は左下
try (PtlQuadPoints quadPoints = annotSquiggly.getQuadPoints())
{
quadPoints.append(quadPoint);
}
//テキストを縦書き方向に囲むかどうかを設定
annotSquiggly.setVerticalDirection(verticalWriting);
// 内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotSquiggly.setTextContents("波状下線サンプル");
// 日時の設定(2025/01/01 00:00:00)
try (PtlDate date = new PtlDate(2025, 1, 1, 0, 0, 0))
{
annotSquiggly.setDate(date);
}
// 注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotSquiggly.setAnnotFlags(PtlAnnot.FLAG_NOROTATE);
// 色を設定
try (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
annotSquiggly.setColor(color);
}
// 内部色を設定
try (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 1.0f, 0.0f))
{
annotSquiggly.setInteriorColor(color);
}
// 境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotSquiggly.setBorderStyle(PtlAnnot.BORDER_STYLE.BORDER_SOLID);
// 境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotSquiggly.setBorderWidth(PtlAnnot.BORDER_LINE_WIDTH.BORDER_WIDTH_THIN);
// 不透明度を設定 0.0 ~ 1.0。0.0が透明、1.0が不透明
annotSquiggly.setMarkUpCA(0.8f);
// 注釈の追加
annots.append(annotSquiggly);
}
}
public static void addAnnotStrikeOut(PtlAnnots annots, PtlQuadPoint quadPoint, boolean verticalWriting) throws PtlException, Exception, Error
{
try (PtlAnnotStrikeOut annotStrikeOut = new PtlAnnotStrikeOut()) // 取り消し線注釈
{
// 座標を設定 座標の単位はmmで原点(0,0)は左下
try (PtlQuadPoints quadPoints = annotStrikeOut.getQuadPoints())
{
quadPoints.append(quadPoint);
}
//テキストを縦書き方向に囲むかどうかを設定
annotStrikeOut.setVerticalDirection(verticalWriting);
// 内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotStrikeOut.setTextContents("取り消し線注釈サンプル");
// 日時の設定(2025/01/01 00:00:00)
try (PtlDate date = new PtlDate(2025, 1, 1, 0, 0, 0))
{
annotStrikeOut.setDate(date);
}
// 注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotStrikeOut.setAnnotFlags(PtlAnnot.FLAG_NOROTATE);
// 色を設定
try (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
annotStrikeOut.setColor(color);
}
// 内部色を設定
try (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 1.0f, 0.0f))
{
annotStrikeOut.setInteriorColor(color);
}
// 境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotStrikeOut.setBorderStyle(PtlAnnot.BORDER_STYLE.BORDER_SOLID);
// 境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotStrikeOut.setBorderWidth(PtlAnnot.BORDER_LINE_WIDTH.BORDER_WIDTH_THIN);
// 不透明度を設定 0.0 ~ 1.0。0.0が透明、1.0が不透明
annotStrikeOut.setMarkUpCA(0.8f);
// 注釈の追加
annots.append(annotStrikeOut);
}
}
public static void addAnnotUnderline(PtlAnnots annots, PtlQuadPoint quadPoint, boolean verticalWriting) throws PtlException, Exception, Error
{
try (PtlAnnotUnderline annotUnderline = new PtlAnnotUnderline()) // 下線注釈
{
// 座標を設定 座標の単位はmmで原点(0,0)は左下
try (PtlQuadPoints quadPoints = annotUnderline.getQuadPoints())
{
quadPoints.append(quadPoint);
}
//テキストを縦書き方向に囲むかどうかを設定
annotUnderline.setVerticalDirection(verticalWriting);
// 内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotUnderline.setTextContents("下線注釈サンプル");
// 日時の設定(2025/01/01 00:00:00)
try (PtlDate date = new PtlDate(2025, 1, 1, 0, 0, 0))
{
annotUnderline.setDate(date);
}
// 注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotUnderline.setAnnotFlags(PtlAnnot.FLAG_NOROTATE);
// 色を設定
try (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
annotUnderline.setColor(color);
}
// 内部色を設定
try (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 1.0f, 0.0f))
{
annotUnderline.setInteriorColor(color);
}
// 境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotUnderline.setBorderStyle(PtlAnnot.BORDER_STYLE.BORDER_SOLID);
// 境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotUnderline.setBorderWidth(PtlAnnot.BORDER_LINE_WIDTH.BORDER_WIDTH_THIN);
// 不透明度を設定 0.0 ~ 1.0。0.0が透明、1.0が不透明
annotUnderline.setMarkUpCA(0.8f);
// 注釈の追加
annots.append(annotUnderline);
}
}
}
/*
Antenna House PDF Tool API V8.0
.NET Interface sample program
概要:テキスト検索して下線、波線、取り消し線注釈
Copyright 2025- Antenna House, Inc.
*/
using PdfTkNet;
using System;
using System.Xml;
namespace AppendAnnotCoordinateSample
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("usage: AppendAnnotCoordinateSample.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())
// 0:先頭ページ
using (PtlPage page = pages.get(0))
using (PtlAnnots annots = page.getAnnots())
using (PtlColorDeviceRGB colorRed = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
// 指定する文字列はすべて横書きなので
bool verticalWriting = false;
// 「編集、共有、印刷が行える操作説明書」
using (PtlQuadPoint quad = new PtlQuadPoint())
{
// left bottom right top
// 26, 234, 133, 243
quad.setTopLeft(new PtlPoint(26, 243));
quad.setTopRight(new PtlPoint(133, 243));
quad.setBottomLeft(new PtlPoint(26, 234));
quad.setBottomRight(new PtlPoint(133, 234));
//波状下線注釈
addAnnotSquiggly(annots, quad, verticalWriting);
}
// 「実際に操作してみましょう」
using (PtlQuadPoint quad = new PtlQuadPoint())
{
// left bottom right top
// 136, 189, 179, 195
quad.setTopLeft(new PtlPoint(136, 195));
quad.setTopRight(new PtlPoint(179, 195));
quad.setBottomLeft(new PtlPoint(136, 189));
quad.setBottomRight(new PtlPoint(179, 189));
//下線注釈
addAnnotUnderline(annots, quad, verticalWriting);
}
// 「ほんの少しのヘルプで雄弁に文章を書く」
using (PtlQuadPoint quad = new PtlQuadPoint())
{
// left bottom right top
// 24, 108, 167, 116
quad.setTopLeft(new PtlPoint(24, 116));
quad.setTopRight(new PtlPoint(167, 116));
quad.setBottomLeft(new PtlPoint(24, 108));
quad.setBottomRight(new PtlPoint(167, 108));
//取り消し線注釈
addAnnotStrikeOut(annots, quad, verticalWriting);
}
}
// ファイルに保存します。
doc.save(outputFile);
}
}
catch (PtlException pex)
{
Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP());
pex.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("-- 完了 --");
}
}
static void addAnnotSquiggly(PtlAnnots annots, PtlQuadPoint quadPoint, bool verticalWriting)
{
using (PtlAnnotSquiggly annotSquiggly = new PtlAnnotSquiggly()) //PDFの波状下線注釈
using (PtlAnnotPopup annotpopup = new PtlAnnotPopup())
{
//矩形座標を設定 座標の単位はmmで原点(0,0)は左下
using (PtlQuadPoints points = annotSquiggly.getQuadPoints())
{
points.append(quadPoint);
}
// 検索に使用したキーワードの部分文字列が縦書きか
annotSquiggly.setVerticalDirection(verticalWriting);
//内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotSquiggly.setTextContents("波状下線注釈サンプル");
//日時の設定(2025/2/1 0:0:0)
using (PtlDate date = new PtlDate(2025, 2, 1, 0, 0, 0))
{
annotSquiggly.setDate(date);
}
//注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotSquiggly.setAnnotFlags(PtlAnnotText.ANNOT_FLAGS.FLAG_NOROTATE);
//色を設定 setColor(const PtlColorDeviceRGB& color);
using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
annotSquiggly.setColor(color);
}
//境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotSquiggly.setBorderStyle(PtlAnnotText.BORDER_STYLE.BORDER_SOLID);
//境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotSquiggly.setBorderWidth(PtlAnnotText.BORDER_LINE_WIDTH.BORDER_WIDTH_THIN);
//注釈の追加
annots.append(annotSquiggly);
}
}
static void addAnnotStrikeOut(PtlAnnots annots, PtlQuadPoint quadPoint, bool verticalWriting)
{
using (PtlAnnotStrikeOut annotStrikeOut = new PtlAnnotStrikeOut()) //PDFの消し線注釈
using (PtlAnnotPopup annotpopup = new PtlAnnotPopup())
{
//矩形座標を設定 座標の単位はmmで原点(0,0)は左下
using (PtlQuadPoints points = annotStrikeOut.getQuadPoints())
{
points.append(quadPoint);
}
// 検索に使用したキーワードの部分文字列が縦書きか
annotStrikeOut.setVerticalDirection(verticalWriting);
//内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotStrikeOut.setTextContents("取り消し線注釈サンプル");
//日時の設定(2025/2/1 0:0:0)
using (PtlDate date = new PtlDate(2025, 2, 1, 0, 0, 0))
{
annotStrikeOut.setDate(date);
}
//注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotStrikeOut.setAnnotFlags(PtlAnnotText.ANNOT_FLAGS.FLAG_NOROTATE);
//色を設定 setColor(const PtlColorDeviceRGB& color);
using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
annotStrikeOut.setColor(color);
}
//境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotStrikeOut.setBorderStyle(PtlAnnotText.BORDER_STYLE.BORDER_SOLID);
//境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotStrikeOut.setBorderWidth(PtlAnnotText.BORDER_LINE_WIDTH.BORDER_WIDTH_THIN);
//注釈の追加
annots.append(annotStrikeOut);
}
}
static void addAnnotUnderline(PtlAnnots annots, PtlQuadPoint quadPoint, bool verticalWriting)
{
using (PtlAnnotUnderline annotUnderLine = new PtlAnnotUnderline()) //PDFの下線注釈
using (PtlAnnotPopup annotpopup = new PtlAnnotPopup())
{
//矩形座標を設定 座標の単位はmmで原点(0,0)は左下
using (PtlQuadPoints points = annotUnderLine.getQuadPoints())
{
points.append(quadPoint);
}
// 検索に使用したキーワードの部分文字列が縦書きか
annotUnderLine.setVerticalDirection(verticalWriting);
//内容を設定(注釈用に表示されるテキスト・可読な形式での注釈コンテンツの代替説明)
annotUnderLine.setTextContents("下線注釈サンプル");
//日時の設定(2025/2/1 0:0:0)
using (PtlDate date = new PtlDate(2025, 2, 1, 0, 0, 0))
{
annotUnderLine.setDate(date);
}
//注釈フラグを設定(論理和) FLAG_NOROTATE = 0x00000010, /* 注釈の外観をページにあわせて回転しません。 */
annotUnderLine.setAnnotFlags(PtlAnnotText.ANNOT_FLAGS.FLAG_NOROTATE);
//色を設定 setColor(const PtlColorDeviceRGB& color);
using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f))
{
annotUnderLine.setColor(color);
}
//境界線スタイルを設定 BORDER_SOLID = 1, /* 実線(注釈を囲む実線の矩形) */
annotUnderLine.setBorderStyle(PtlAnnotText.BORDER_STYLE.BORDER_SOLID);
//境界線幅を設定 BORDER_WIDTH_THIN = 1, /* 細い */
annotUnderLine.setBorderWidth(PtlAnnotText.BORDER_LINE_WIDTH.BORDER_WIDTH_THIN);
//注釈の追加
annots.append(annotUnderLine);
}
}
}
}
実行例
コマンドラインでの実行例
AppendAnnotCoordinateSample.exe C:\in\in.pdf C:\sav\outAppendAnnotCoordinateSample.pdf 完了!
java -jar AppendAnnotCoordinateSample.jar C:\in\in.pdf C:\sav\outAppendAnnotCoordinateSample.pdf -- 完了 --
AppendAnnotCoordinateSample.exe C:\in\in.pdf C:\sav\outAppendAnnotCoordinateSample.pdf -- 完了 --
出力結果イメージ
座標取得ツールで取得した座標を取得します。

座標取得ツールで矩形を選択すると選択した矩形の座標が取得できます。
「編集、共有、印刷が行える操作説明書」(26, 234, 133, 243)
「実際に操作してみましょう」(136, 189, 179, 195)
「ほんの少しのヘルプで雄弁に文章を書く」(24, 108, 167, 116)
今回はこれらをプログラム内で直接 PtlQuadPoint に指定して、下線、波線、取り消し線注釈を追加しました。

出力されたPDFには下線、波線、取り消し線注釈が追加されました。

