/* Antenna House PDF Tool API V8.0 .NET Interface sample program 概要:注釈をコンテントへ書き込み Copyright 2025 Antenna House, Inc. */ using System; using PdfTkNet; namespace AnnotToContent { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: AnnotToContent.exe in-pdf-file out-pdf-file"); return; } try { using (PtlParamInput input = new PtlParamInput(args[0])) using (PtlParamOutput output = new PtlParamOutput(args[1])) using (PtlPDFDocument doc = new PtlPDFDocument()) { // PDFファイルをロードします。 doc.load(input); // ページコンテナの取得 using (PtlPages pages = doc.getPages()) { // ページコンテナが空かどうか if (pages.isEmpty()) { Console.WriteLine("ページコンテナが空"); return; } int numPages = pages.getCount(); for (int i = 0; i < numPages; i++) { Console.WriteLine("ページ : " + (i + 1)); using (PtlPage page = pages.get(i)) // ページの取得 using (PtlAnnots annots = page.getAnnots()) // 注釈コンテナの取得 { // 注釈コンテナが空かどうか if (annots.isEmpty()) { Console.WriteLine("注釈なし"); } else { using (PtlContent content = page.getContent()) { // 注釈数の取得 int numAnnots = annots.getCount(); Console.WriteLine("注釈数 : " + numAnnots); for (int j = numAnnots - 1; j >= 0; j--) { using (PtlAnnot annot = annots.get(j)) { bool bl=content.drawForm(annot); // ページに書き込む annots.remove(j); // 元の注釈を削除する } } } } } } doc.save(output); } } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } } }