/* Antenna House PDF Tool API V8.0 .NET Interface sample program 概要:テキストオブジェクトの挿入 Copyright 2013-2025 Antenna House, Inc. */ using PdfTkNet; using System; using System.Xml; namespace WriteTextAngle { class WriteTextAngle { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: WriteTextAngle.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 pageno = pages.getCount(); for (int i = 0; i < pageno; i++) { using (PtlPage page = pages.get(i)) // 先頭ページ { // テキスト追加 writeString(page); } } } // ファイルに保存します。 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 writeString(PtlPage page) { using (PtlContent content = page.getContent()) // ページコンテントの取得 { PtlSize pagesize = page.getSize(); // 文字列回転出力 using (PtlRect rect = new PtlRect(0.0f, 0.0f, pagesize.getWidth(), pagesize.getHeight())) using (PtlParamWriteString writestring = new PtlParamWriteString()) // 文字の描画に使うパラメータクラス { // フォント指定に使うパラメータクラス using (PtlParamFont font = new PtlParamFont()) { // フォント名の設定 font.setName("游ゴシック"); // サイズの設定 font.setSize(8.0f); // フォントの設定 writestring.setFont(font); } // 文字色設定 using (PtlColorDeviceRGB colorText = new PtlColorDeviceRGB(0.5f, 1.0f, 0.8f)) { writestring.setTextColor(colorText); } // 文字列出力 content.writeString(rect, PtlContent.ALIGN.ALIGN_BOTTOM_LEFT, 330.0f, "アンテナハウス株式会社", writestring); } } } } }