/* Antenna House PDF Tool API V8.0 .Net Interface sample program 概要:複数矩形テキスト抽出 Copyright 2025 Antenna House, Inc. */ using System; using PdfTkNet; using static System.Net.Mime.MediaTypeNames; namespace MultiRectExtractText { class Program { static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage: MultiRectExtractText.exe in-pdf-file"); return; } try { using (PtlParamInput input = new PtlParamInput(args[0])) using (PtlPDFDocument doc = new PtlPDFDocument()) { // PDFファイルをロードします。 doc.load(input); // ページコンテナの取得 using (PtlPages pages = doc.getPages()) using (PtlPage page = pages.get(0)) using (PtlParamExtractText paramExtractText = new PtlParamExtractText()) using (PtlSize pageSize = page.getSize()) // ページサイズ using (PtlRect rect = new PtlRect(0.0f, 0.0f, pageSize.getWidth() / 2, pageSize.getHeight() / 2)) // テキスト抽出する範囲 using (PtlRect rect2 = new PtlRect(0.0f, pageSize.getHeight() / 2, pageSize.getWidth() / 2, pageSize.getHeight())) { paramExtractText.appendRect(rect); paramExtractText.appendRect(rect2); using (PtlContent content = page.getContent()) using (PtlExtractTextResults textList = content.extractTexts(paramExtractText)) { for (int i = 0; i < textList.getCount(); i++) { using (PtlExtractTextResult result = textList.get(i)) { string text = result.getText(); Console.WriteLine(text); } } } } } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } } }