/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:レイヤーの描画 Copyright 2018-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace DrawLayer { class Program { static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("usage: DrawLayer.exe in-pdf-file out-pdf-file in-pdf-file2"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) //元PDF using (PtlParamOutput outputFile = new PtlParamOutput(args[1])) //出力PDF using (PtlPDFDocument doc = new PtlPDFDocument()) { // PDFファイルをロードします。 doc.load(inputFile); using (PtlPages pages = doc.getPages()) { //ページコンテナが空かどうか if (pages.isEmpty()) { Console.WriteLine("ページコンテナが空"); return; } using (PtlPage page = pages.get(0)) // 先頭ページ { // レイヤーの描画 drawLayer(page, 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 drawLayer(PtlPage page, string pathPdf) { using (PtlSize pageSize = page.getSize()) // ページサイズ using (PtlContent content = page.getContent()) // ページコンテントの取得 using (PtlParamInput inputFile2 = new PtlParamInput(pathPdf)) //挿入するPDF using (PtlRect rect = new PtlRect(0.0f, 0.0f, pageSize.getWidth(), pageSize.getHeight())) // 描画矩形 using (PtlPDFDocument doc2 = new PtlPDFDocument()) { // PDFファイルをロードします。 doc2.load(inputFile2); using (PtlPages pages2 = doc2.getPages()) { //ページコンテナが空かどうか if (pages2.isEmpty()) { Console.WriteLine("ページコンテナが空"); return; } using (PtlPage pageInsert = pages2.get(0)) // 先頭ページ using (PtlParamDrawLayer param = new PtlParamDrawLayer()) // レイヤーのパラメーター { // レイヤーにするページ param.setPage(pageInsert); // レイヤーの名前 param.setName("レイヤー"); // レイヤーを前面に param.setZorder(PtlParamDrawLayer.ZORDER.ZORDER_FRONT); // レイヤーを表示 param.setShow(PtlParamDrawLayer.SHOW.SHOW_ON); // レイヤーの描画 content.drawLayer(rect, PtlContent.ALIGN.ALIGN_CENTER, param); } } } } } }