Document content flow basics

This commit is contained in:
Jakub Melka
2020-10-17 16:56:39 +02:00
parent b0f8e1f1e3
commit 0ccdb1e46f
10 changed files with 664 additions and 290 deletions

View File

@ -65,17 +65,48 @@ int PDFToolFetchTextApplication::execute(const PDFToolOptions& options)
pdf::PDFDocumentTextFlowFactory factory;
pdf::PDFDocumentTextFlow documentTextFlow = factory.create(&document, pages, options.textAnalysisAlgorithm);
PDFOutputFormatter formatter(options.outputStyle, options.outputCodec);
formatter.beginDocument("text-extraction", QString());
formatter.endl();
for (const pdf::PDFDocumentTextFlow::Item& item : documentTextFlow.getItems())
{
if (item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureItemStart))
{
formatter.beginHeader("item", item.text);
}
if (!item.text.isEmpty())
{
formatter.writeText("text", item.text);
}
if (item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureItemEnd))
{
formatter.endHeader();
}
if (item.flags.testFlag(pdf::PDFDocumentTextFlow::PageEnd))
{
formatter.endl();
}
}
formatter.endDocument();
for (const pdf::PDFRenderError& error : factory.getErrors())
{
PDFConsole::writeError(error.message, options.outputCodec);
}
PDFConsole::writeText(formatter.getString(), options.outputCodec);
return ExitSuccess;
}
PDFToolAbstractApplication::Options PDFToolFetchTextApplication::getOptionsFlags() const
{
return ConsoleFormat | OpenDocument | TextAnalysis;
return ConsoleFormat | OpenDocument | PageSelector | TextAnalysis;
}
} // namespace pdftool