From b47b187c8af41741a1394127d03b3dc1da2af0ed Mon Sep 17 00:00:00 2001 From: yhampe Date: Mon, 15 Jan 2024 09:43:23 +0100 Subject: [PATCH] RED-7375: table extractor prototype added layer for table extractor results in ViewerDocumentService --- .../visualization/ViewerDocumentService.java | 30 +++++++++++++++---- publish-custom-image.sh | 4 +-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/ViewerDocumentService.java b/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/ViewerDocumentService.java index 61d0525..8e5134a 100644 --- a/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/ViewerDocumentService.java +++ b/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/ViewerDocumentService.java @@ -66,6 +66,7 @@ public class ViewerDocumentService { // If we collect all COSDictionaries we changed and tell it explicitly to only add the changed ones by using saveIncremental it's very fast. Set dictionariesToUpdate = new HashSet<>(); PDOptionalContentGroup layer = addLayerToDocument(pdDocument, dictionariesToUpdate, layerVisibilityDefaultValue); + PDOptionalContentGroup tableExtractorLayer = addLayerToDocument(pdDocument, dictionariesToUpdate, true); PDFont font = new PDType1Font(Standard14Fonts.FontName.HELVETICA); for (int pageNumber = 0; pageNumber < pdDocument.getNumberOfPages(); pageNumber++) { @@ -108,11 +109,6 @@ public class ViewerDocumentService { contentStream.addRect((float) r.getX(), (float) r.getY(), (float) r.getWidth(), (float) r.getHeight()); contentStream.fill(); } - for(TableCells tableCells: extractedTableCells.get(pageNumber)) { - contentStream.setStrokingColor(Color.CYAN); - contentStream.addRect((float) tableCells.getX0(), (float) tableCells.getY0(), (float) tableCells.getWidth(), (float) tableCells.getHeight()); - contentStream.stroke(); - } for (PlacedText placedText : visualizationsOnPage.getPlacedTexts()) { contentStream.setFont(font, FONT_SIZE); contentStream.beginText(); @@ -129,6 +125,30 @@ public class ViewerDocumentService { } contentStream.restoreGraphicsState(); contentStream.endMarkedContent(); + contentStream.beginMarkedContent(COSName.OC, tableExtractorLayer); + contentStream.saveGraphicsState(); + + contentStream.setLineWidth(LINE_WIDTH); + for (TableCells tableCells : extractedTableCells.get(pageNumber)) { + contentStream.setStrokingColor(new Color(0xFF0000)); + contentStream.addRect((float) tableCells.getX0(), (float) tableCells.getY0(), (float) tableCells.getWidth(), (float) tableCells.getHeight()); + contentStream.stroke(); + contentStream.setFont(font, FONT_SIZE); + contentStream.beginText(); + Matrix textMatrix = new Matrix((float) textDeRotationMatrix.getScaleX(), + (float) textDeRotationMatrix.getShearX(), + (float) textDeRotationMatrix.getShearY(), + (float) textDeRotationMatrix.getScaleY(), + tableCells.getX0() , + tableCells.getY0()); + // textMatrix.translate(-((font.getStringWidth(tableCells.getLabel()) / 1000) * FONT_SIZE + (2 * LINE_WIDTH) + 4), -FONT_SIZE); + // contentStream.setTextMatrix(textMatrix); + // contentStream.showText(tableCells.getLabel()); + contentStream.endText(); + } + contentStream.restoreGraphicsState(); + contentStream.endMarkedContent(); + } dictionariesToUpdate.add(pdPage.getCOSObject()); dictionariesToUpdate.add(pdPage.getResources().getCOSObject()); diff --git a/publish-custom-image.sh b/publish-custom-image.sh index 2610fc3..97f176c 100644 --- a/publish-custom-image.sh +++ b/publish-custom-image.sh @@ -4,5 +4,5 @@ gradle assemble buildNumber=${1:-1} -gradle bootBuildImage --cleanCache --publishImage -PbuildbootDockerHostNetwork=true -Pversion=$USER-$buildNumber -echo "nexus.knecon.com:5001/red/${dir}-server-v1:$USER-$buildNumber" +gradle bootBuildImage --cleanCache --publishImage -Pversion=layout-parser-yannik-$buildNumber --stacktrace +echo "nexus.knecon.com:5001/red/${dir}-server-v1:table-extractor-yannik-$buildNumber"