/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:PDF透かしの挿入 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace AppendPdfWatermark { class Program { static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("usage: AppendPdfWatermark.exe in-pdf-file out-pdf-file watermark-pdf"); 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, args[2]); // ファイルに保存します。 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, String pathPdf) { // 透かしの設定 using (PtlParamWaterMarkPDF watermarkpdf = new PtlParamWaterMarkPDF()) { // 透かしの名前の設定 watermarkpdf.setName("透かしの名前"); // 透かしの配置の設定 ALIGN_CENTER = 5 /* 中央 */ watermarkpdf.setAlign(PtlParamWaterMark.ALIGN.ALIGN_CENTER); // 透かしのZオーダーの設定 ZORDER_FRONT = 1 /* 前面 */ watermarkpdf.setZorder(PtlParamWaterMark.ZORDER.ZORDER_FRONT); // 透かしを入れるページの範囲の設定 PAGE_RANGE_ALL = 0 /* 全ページ */ watermarkpdf.setPageRange(PtlParamWaterMark.PAGE_RANGE.PAGE_RANGE_ALL); // 先頭ページに透かしを配置しない設定の範囲の設定 watermarkpdf.setNotInFirst(false); // 最終ページに透かしを配置しない設定の設定 watermarkpdf.setNotInLast(false); // PDF表示時に透かしを表示する指定の設定 watermarkpdf.setDisplayWaterMark(true); // PDF印刷時に透かしを印刷する指定の設定 watermarkpdf.setPrintWaterMark(true); // 透かしの不透明度の設定 watermarkpdf.setOpacity(0.5f); // 透かしをタイリングして配置するかどうかの設定 watermarkpdf.setTiling(false); using (PtlParamInput watermark = new PtlParamInput(pathPdf)) using (PtlPDFDocument doc_watermark = new PtlPDFDocument()) { // 透かしに使用するPDFファイルをロードします。 doc_watermark.load(watermark); // 透かしに使用するページの取得 using (PtlPages pages = doc_watermark.getPages()) using (PtlPage page = pages.get(0)) { // 透かしに使用するPDF文書ページを設定 watermarkpdf.setPage(page); } } // 透かしの倍率の設定 watermarkpdf.setScale(0.5f); // 透かしの設定 doc.appendWaterMark(watermarkpdf); } } } }