/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:フォームの描画 Copyright 2015-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace DrawForm { class Program { static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("usage: DrawForm.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)) // 先頭ページ { // フォームの描画 drawForm(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 drawForm(PtlPage page, string pathPdf) { using (PtlContent content = page.getContent()) // ページコンテントの取得 using (PtlParamInput inputFile2 = new PtlParamInput(pathPdf)) //挿入するPDF using (PtlRect rect = new PtlRect(0.0f, 0.0f, 100.0f, 100.0f)) // 描画矩形 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)) // 先頭ページ { // フォームの描画 content.drawForm(rect, PtlContent.ALIGN.ALIGN_CENTER, pageInsert); } } } } } }