diff options
| author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2026-03-04 17:55:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-04 17:55:09 +0100 |
| commit | 052beaf9a9b004dbbe3a0c64220c8875f1ac845f (patch) | |
| tree | f75d3675042a3570579d10483b3f51eb36cfdb5f | |
| parent | 422bfc5c6083ae57257f09e0c0ad1b208094e903 (diff) | |
| parent | 17c7158d166b58c403ea0c354a0a98fd20a4a3e0 (diff) | |
| download | pdf-as-4-052beaf9a9b004dbbe3a0c64220c8875f1ac845f.tar.gz pdf-as-4-052beaf9a9b004dbbe3a0c64220c8875f1ac845f.tar.bz2 pdf-as-4-052beaf9a9b004dbbe3a0c64220c8875f1ac845f.zip | |
Merge pull request #81 from a-sit/feature/fix_wrong_auto_pos
fix(core): correct empty space detection for signature block position…
| -rw-r--r-- | pdf-as-pdfbox-2/src/main/java/at/knowcenter/wag/egov/egiz/pdfbox2/pdf/PDFUtilities.java | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/pdf-as-pdfbox-2/src/main/java/at/knowcenter/wag/egov/egiz/pdfbox2/pdf/PDFUtilities.java b/pdf-as-pdfbox-2/src/main/java/at/knowcenter/wag/egov/egiz/pdfbox2/pdf/PDFUtilities.java index 995b4e10..741860e2 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/knowcenter/wag/egov/egiz/pdfbox2/pdf/PDFUtilities.java +++ b/pdf-as-pdfbox-2/src/main/java/at/knowcenter/wag/egov/egiz/pdfbox2/pdf/PDFUtilities.java @@ -68,33 +68,37 @@ public abstract class PDFUtilities implements IConfigurationConstants{ public static float getMaxYPosition( PDDocument pdfDataSource, int page, IPDFVisualObject pdfTable, float signatureMarginVertical, float footer_line, ISettings settings) throws IOException { - - PositioningRenderer renderer = new PositioningRenderer(pdfDataSource); - //BufferedImage bim = renderer.renderImage(page); - - int width = (int) pdfDataSource.getPage(page).getCropBox().getWidth(); - int height = (int) pdfDataSource.getPage(page).getCropBox().getHeight(); - BufferedImage bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + int width = (int) pdfDataSource.getPage(page).getCropBox().getWidth(); + int height = (int) pdfDataSource.getPage(page).getCropBox().getHeight(); + + // flip image in case of page rotation is 90 or 270 + BufferedImage bim = (pdfDataSource.getPage(page).getRotation() % 180 == 0) + ? new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB) + : new BufferedImage(height, width, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = bim.createGraphics(); graphics.setBackground(MAGIC_COLOR); - + + PositioningRenderer renderer = new PositioningRenderer(pdfDataSource); renderer.renderPageToGraphics(page, graphics); - Color bgColor = MAGIC_COLOR; - - if("true".equals(settings.getValue(BG_COLOR_DETECTION))){ //only used if background color should be determined automatically - bgColor = determineBackgroundColor(bim); - } - + /* + * Only used if background color should be determined automatically. + * That can be necessary of PDF contains page-size images. + */ + Color bgColor = "true".equals(settings.getValue(BG_COLOR_DETECTION)) + ? determineBackgroundColor(bim) + : MAGIC_COLOR; + int yCoord = bim.getHeight() - 1 - (int)footer_line; for(int row = yCoord; row >= 0; row--) { - if (row == 0) - yCoord = row; - else - { + if (row == 0) { + yCoord = row; + + } else { for(int col = 0; col < bim.getWidth(); col++){ int val = bim.getRGB(col, row); if(val != bgColor.getRGB()){ @@ -105,11 +109,14 @@ public abstract class PDFUtilities implements IConfigurationConstants{ } } } + String outFile = settings.getValue(SIG_PLACEMENT_DEBUG_OUTPUT); - if(outFile!=null){ + if(outFile != null){ ImageIOUtil.writeImage(bim, outFile, 72); } + return yCoord; + } public static Color determineBackgroundColor(BufferedImage bim){ |
