/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:パスの描画 Copyright 2015-2021 Antenna House, Inc. */ using System; using PdfTkNet; 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; //int 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); } } } } } } }