/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:テキスト透かしの挿入 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace AppendTextWatermark { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: AppendTextWatermark.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); // 透かしの追加 appendWatermark(doc); // ファイルに保存します。 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 appendWatermark(PtlPDFDocument doc) { using (PtlParamWaterMarkText watermarktext = new PtlParamWaterMarkText()) { // 透かしの名前の設定 watermarktext.setName("透かしの名前"); // 透かしを配置する矩形の設定 watermarktext.setRect(new PtlRect(10.0f, 10.0f, 150.0f, 150.0f)); // 透かしの配置の設定 ALIGN_BOTTOM_LEFT = 7 /* 左下 */ watermarktext.setAlign(PtlParamWaterMark.ALIGN.ALIGN_BOTTOM_LEFT); // 透かしのZオーダーの設定 ZORDER_BACK = 2 /* 前面 */ watermarktext.setZorder(PtlParamWaterMark.ZORDER.ZORDER_FRONT); // 透かしを入れるページの範囲の設定 PAGE_RANGE_ALL = 0 /* 全ページ */ watermarktext.setPageRange(PtlParamWaterMark.PAGE_RANGE.PAGE_RANGE_ALL); // 透かしの不透明度の設定 watermarktext.setOpacity(1.0f); // 透かしをタイリングして配置するかどうかの設定 watermarktext.setTiling(false); // 透かしに指定する文字列の設定 watermarktext.setString("PDFToolAPI TextWatermark"); // 透かしに指定するフォントの設定 using (PtlParamFont font = new PtlParamFont("Times New Roman", 180.0f, PtlParamFont.WEIGHT.WEIGHT_NORMAL, false, true)) { watermarktext.setFont(font); } // 透かしの文字に指定する色の設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f)) { watermarktext.setTextColor(color); } // 透かしの文字の縁取りに指定する色の設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(0.0f, 1.0f, 0.0f)) { watermarktext.setOutlineColor(color); } // 透かしのテキストを対角線上に配置する設定 watermarktext.setWriteDiagonal(false); // 透かしのテキストを任意の角度で配置する設定 watermarktext.setTextAngle(15.0f); // 透かしの設定 doc.appendWaterMark(watermarktext); } } } }