/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:色透かしの挿入 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace AppendColorWatermark { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: AppendColorWatermark.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 (PtlParamWaterMarkColor watermarkcolor = new PtlParamWaterMarkColor()) { // 透かしの名前の設定 watermarkcolor.setName("透かしの名前"); //透かしを配置するマージンの設定 watermarkcolor.setMargin(10.0f, 10.0f, 10.0f, 10.0f); // 透かしのZオーダーの設定 ZORDER_BACK = 2 /* 背面 */ watermarkcolor.setZorder(PtlParamWaterMark.ZORDER.ZORDER_BACK); // 透かしを入れるページの範囲の設定 PAGE_RANGE_ALL = 0 /* 全ページ */ watermarkcolor.setPageRange(PtlParamWaterMark.PAGE_RANGE.PAGE_RANGE_ALL); // 透かしの不透明度の設定 watermarkcolor.setOpacity(0.4f); // 透かしに指定する色の設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f)) { watermarkcolor.setColor(color); } // 透かしの設定 doc.appendWaterMark(watermarkcolor); } } } }