/* Antenna House PDF Tool API V8.0 .NET Interface sample program 概要:テキスト抽出:行の末尾に改行コード挿入 Copyright 2025- Antenna House, Inc. */ using System; using PdfTkNet; namespace ExtractTextInsertReturn { internal class ExtractTextInsertReturn { static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage: ExtractTextInsertReturn.exe in-pdf-file"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) //元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)) // 先頭ページ { // テキスト抽出 extractTextInsertReturn(page); } } } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } static void extractTextInsertReturn(PtlPage page) { using (PtlSize pageSize = page.getSize()) // ページサイズの取得 using (PtlContent content = page.getContent()) // ページコンテントの取得 using (PtlParamExtractText paramExtractText = new PtlParamExtractText()) // テキスト抽出パラメータ { // 抽出するテキストのタイプを設定(改行はTEXT_SORTの場合のみ有効 paramExtractText.setTextType(PtlParamExtractText.TEXT_TYPE.TEXT_SORT); //改行の挿入を設定 paramExtractText.setInsertReturn(true); // テキスト抽出 String text = content.extractText(paramExtractText); Console.WriteLine(text); } } } }