@@ -129,6 +129,9 @@ public OcrPdfCreator(final IOcrEngine ocrEngine) {
129129 */
130130 public OcrPdfCreator (final IOcrEngine ocrEngine ,
131131 final OcrPdfCreatorProperties ocrPdfCreatorProperties ) {
132+ if (ocrPdfCreatorProperties .isTagged () && !ocrEngine .isTaggingSupported ()) {
133+ throw new PdfOcrException (PdfOcrExceptionMessageConstant .TAGGING_IS_NOT_SUPPORTED );
134+ }
132135 setOcrEngine (ocrEngine );
133136 setOcrPdfCreatorProperties (ocrPdfCreatorProperties );
134137 }
@@ -471,11 +474,7 @@ private void addToCanvas(final PdfDocument pdfDocument,
471474 // Logical tree, a list of top items, children can be retrieved out of them
472475 List <LogicalStructureTreeItem > logicalTree = new ArrayList <>();
473476 // A map of leaf LogicalStructureTreeItem's to TextInfo's attached to these leaves
474- Map <LogicalStructureTreeItem , List <TextInfo >> leavesTextInfos = new HashMap <>();
475- final boolean taggedSupported = getLogicalTree (pageText , logicalTree , leavesTextInfos );
476- if (!taggedSupported ) {
477- throw new PdfOcrException (PdfOcrExceptionMessageConstant .TAGGING_IS_NOT_SUPPORTED );
478- }
477+ Map <LogicalStructureTreeItem , List <TextInfo >> leavesTextInfos = getLogicalTree (pageText , logicalTree );
479478 pdfDocument .setTagged ();
480479
481480 // Create a map of TextInfo to tag pointers meanwhile creating the required tags.
@@ -634,19 +633,12 @@ private void addImageToCanvas(final ImageData imageData,
634633 }
635634 }
636635
637- /**
638- * @return {@code true} if tagging supported by the engine.
639- * @deprecated In next major version we need to add boolean taggingSupported() method into IOcrEngine
640- * and throw exception in OcrPdfCreator constructor if taggingSupported() returns false but
641- * OcrPdfCreatorProperties.getTagged returns true.
642- */
643- @ Deprecated
644- private static boolean getLogicalTree (List <TextInfo > textInfos ,
645- List <LogicalStructureTreeItem > logicalStructureTreeItems ,
646- Map <LogicalStructureTreeItem , List <TextInfo >> leavesTextInfos ) {
647- boolean taggedSupported = false ;
636+ private static Map <LogicalStructureTreeItem , List <TextInfo >> getLogicalTree (
637+ List <TextInfo > textInfos , List <LogicalStructureTreeItem > logicalStructureTreeItems ) {
638+
639+ Map <LogicalStructureTreeItem , List <TextInfo >> leavesTextInfos = new HashMap <>();
648640 if (textInfos == null ) {
649- return taggedSupported ;
641+ return leavesTextInfos ;
650642 }
651643
652644 for (TextInfo textInfo : textInfos ) {
@@ -656,7 +648,6 @@ private static boolean getLogicalTree(List<TextInfo> textInfos,
656648 continue ;
657649 } else if (structTreeItem != null ) {
658650 topParent = getTopParent (structTreeItem );
659- taggedSupported = true ;
660651 } else {
661652 structTreeItem = new LogicalStructureTreeItem ();
662653 textInfo .setLogicalStructureTreeItem (structTreeItem );
@@ -675,7 +666,7 @@ private static boolean getLogicalTree(List<TextInfo> textInfos,
675666 }
676667 }
677668
678- return taggedSupported ;
669+ return leavesTextInfos ;
679670 }
680671
681672 private static LogicalStructureTreeItem getTopParent (LogicalStructureTreeItem structInfo ) {
0 commit comments