mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Finishing of text extracting tool
This commit is contained in:
@ -34,7 +34,7 @@ QString PDFToolFetchTextApplication::getStandardString(PDFToolAbstractApplicatio
|
||||
return PDFToolTranslationContext::tr("Fetch text");
|
||||
|
||||
case Description:
|
||||
return PDFToolTranslationContext::tr("Fetch text content from a document.");
|
||||
return PDFToolTranslationContext::tr("Fetch text content from document.");
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
@ -53,6 +53,12 @@ int PDFToolFetchTextApplication::execute(const PDFToolOptions& options)
|
||||
return ErrorDocumentReading;
|
||||
}
|
||||
|
||||
if (!document.getStorage().getSecurityHandler()->isAllowed(pdf::PDFSecurityHandler::Permission::CopyContent))
|
||||
{
|
||||
PDFConsole::writeError(PDFToolTranslationContext::tr("Document doesn't allow to copy content."), options.outputCodec);
|
||||
return ErrorPermissions;
|
||||
}
|
||||
|
||||
QString parseError;
|
||||
std::vector<pdf::PDFInteger> pages = options.getPageRange(document.getCatalog()->getPageCount(), parseError, true);
|
||||
|
||||
@ -78,7 +84,20 @@ int PDFToolFetchTextApplication::execute(const PDFToolOptions& options)
|
||||
|
||||
if (!item.text.isEmpty())
|
||||
{
|
||||
formatter.writeText("text", item.text);
|
||||
bool showText = (item.flags.testFlag(pdf::PDFDocumentTextFlow::Text)) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::PageStart) && options.textShowPageNumbers) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::PageEnd) && options.textShowPageNumbers) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureTitle) && options.textShowStructTitles) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureLanguage) && options.textShowStructLanguage) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureAlternativeDescription) && options.textShowStructAlternativeDescription) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureExpandedForm) && options.textShowStructExpandedForm) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureActualText) && options.textShowStructActualText) ||
|
||||
(item.flags.testFlag(pdf::PDFDocumentTextFlow::StructurePhoneme) && options.textShowStructPhoneme);
|
||||
|
||||
if (showText)
|
||||
{
|
||||
formatter.writeText("text", item.text);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.flags.testFlag(pdf::PDFDocumentTextFlow::StructureItemEnd))
|
||||
@ -106,7 +125,7 @@ int PDFToolFetchTextApplication::execute(const PDFToolOptions& options)
|
||||
|
||||
PDFToolAbstractApplication::Options PDFToolFetchTextApplication::getOptionsFlags() const
|
||||
{
|
||||
return ConsoleFormat | OpenDocument | PageSelector | TextAnalysis;
|
||||
return ConsoleFormat | OpenDocument | PageSelector | TextAnalysis | TextShow;
|
||||
}
|
||||
|
||||
} // namespace pdftool
|
||||
|
Reference in New Issue
Block a user