/* Antenna House PDF Tool API V8.0 .NET Interface sample program 概要:パスの描画 Copyright 2025 Antenna House, Inc. */ using PdfTkNet; using System; using static PdfTkNet.PtlParamDrawShape; namespace DrawShape { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: DrawShape.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); using (PtlPages pages = doc.getPages()) { // ページコンテナが空かどうか if (pages.isEmpty()) { Console.WriteLine("ページコンテナが空"); return; } using (PtlPage page = pages.get(0)) // 先頭ページ { // パスの描画 drawShape(page); } } // ファイルに保存します。 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 drawShape(PtlPage page) { using (PtlContent content = page.getContent()) // ページコンテントの取得 using (PtlSize pageSize = page.getSize()) // ページサイズ { // パス出力 using (PtlParamDrawShape paramDrawShape = new PtlParamDrawShape()) // パスの描画に使うパラメータクラス { // 丸角矩形の描画 using (PtlRect rect = new PtlRect(10.0f, 10.0f, pageSize.getWidth()-10.0f, pageSize.getHeight()-10.0f)) using (PtlColorDeviceRGB colorFill = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f)) using (PtlColorDeviceRGB colorStroke = new PtlColorDeviceRGB(0.0f, 0.0f, 1.0f)) { paramDrawShape.setLineColor(colorStroke); paramDrawShape.setFillColor(colorFill); PtlParamDrawShape.LINE_STYLE lineStyle = PtlParamDrawShape.LINE_STYLE.LINE_STYLE_SOLID; // 実線 //PtlParamDrawShape.LINE_STYLE lineStyle = PtlParamDrawShape.LINE_STYLE.LINE_STYLE_DASHED; // 点線 paramDrawShape.setLineStyle(lineStyle); //PtlParamDrawShape.LINE_WIDTH lineWidth = PtlParamDrawShape.LINE_WIDTH.LINE_WIDTH_THIN; // 細 //PtlParamDrawShape.LINE_WIDTH lineWidth = PtlParamDrawShape.LINE_WIDTH.LINE_WIDTH_MIDDLE; // 中 PtlParamDrawShape.LINE_WIDTH lineWidth = PtlParamDrawShape.LINE_WIDTH.LINE_WIDTH_THICK; // 太 paramDrawShape.setLineWidth(lineWidth); // 線の太さ paramDrawShape.setOpacity(0.5f); content.drawRoundRect(rect, 10.0f, 10.0f, paramDrawShape); // 角丸矩形の描画 } // 矩形/円の描画 using (PtlRect rect = new PtlRect(30.0f, 30.0f, pageSize.getWidth() - 30.0f, pageSize.getHeight() - 30.0f)) using (PtlColorDeviceRGB colorFill = new PtlColorDeviceRGB(1.0f, 1.0f, 0.0f)) using (PtlColorDeviceRGB colorStroke = new PtlColorDeviceRGB(0.0f, 1.0f, 1.0f)) { paramDrawShape.setLineColor(colorStroke); paramDrawShape.setFillColor(colorFill); paramDrawShape.setOpacity(0.3f); content.drawRect(rect, paramDrawShape); // 矩形の描画 content.drawCircle(rect, paramDrawShape); // 円の描画 } // 線の描画 using (PtlColorDeviceRGB colorStroke = new PtlColorDeviceRGB(0.0f, 1.0f, 0.0f)) { paramDrawShape.setLineColor(colorStroke); using (PtlPoint from = new PtlPoint(30.0f, 30.0f)) using (PtlPoint to = new PtlPoint(pageSize.getWidth() - 30, pageSize.getHeight() - 30.0f)) { content.drawLine(from, to, paramDrawShape); // 線の描画 } using (PtlPoint from = new PtlPoint(30.0f, pageSize.getHeight() - 30.0f)) using (PtlPoint to = new PtlPoint(pageSize.getWidth() - 30.0f, 30.0f)) { content.drawLine(from, to, paramDrawShape); // 線の描画 } } // 折れ線 PolyLine using (PtlPoints pointsMM = new PtlPoints()) { pointsMM.append(new PtlPoint(70.0f, 30.0f)); pointsMM.append(new PtlPoint(140.0f, 110.0f)); pointsMM.append(new PtlPoint(110.0f, 180.0f)); pointsMM.append(new PtlPoint(190.0f, 130.0f)); pointsMM.append(new PtlPoint(260.0f, 160.0f)); pointsMM.append(new PtlPoint(230.0f, 90.0f)); pointsMM.append(new PtlPoint(270.0f, 30.0f)); pointsMM.append(new PtlPoint(180.0f, 70.0f)); paramDrawShape.setLineColor(new PtlColorDeviceRGB(0.2f, 0.2f, 0.2f)); paramDrawShape.setOpacity(0.9f); paramDrawShape.setLineWidth(PtlParamDrawShape.LINE_WIDTH.LINE_WIDTH_THICK); content.drawPolyline(pointsMM, paramDrawShape); } // 多角形注釈 Polygon using (PtlPoints pointsMM = new PtlPoints()) { pointsMM.append(new PtlPoint(30.0f, 30.0f)); pointsMM.append(new PtlPoint(100.0f, 110.0f)); pointsMM.append(new PtlPoint(70.0f, 180.0f)); pointsMM.append(new PtlPoint(120.0f, 130.0f)); pointsMM.append(new PtlPoint(220.0f, 160.0f)); pointsMM.append(new PtlPoint(190.0f, 90.0f)); pointsMM.append(new PtlPoint(230.0f, 30.0f)); pointsMM.append(new PtlPoint(140.0f, 70.0f)); paramDrawShape.setOpacity(0.3f); paramDrawShape.setFillColor(new PtlColorDeviceRGB(1.0f, 1.0f, 0.0f)); content.drawPolygon(pointsMM, paramDrawShape); } } } } } }