aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2026-03-04 17:40:42 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2026-03-04 17:40:42 +0100
commit17c7158d166b58c403ea0c354a0a98fd20a4a3e0 (patch)
tree0b84b9d2199680b647b56815b2f6833d9eb531f8
parent04b752f38832e309d96392f0c1a3a6e02de55edc (diff)
downloadpdf-as-4-17c7158d166b58c403ea0c354a0a98fd20a4a3e0.tar.gz
pdf-as-4-17c7158d166b58c403ea0c354a0a98fd20a4a3e0.tar.bz2
pdf-as-4-17c7158d166b58c403ea0c354a0a98fd20a4a3e0.zip
fix(core): correct empty space detection for signature block positioning on rotated PDF pages
Hint: fixes incorrect placement when a PDF page contains rotation metadata
-rw-r--r--pdf-as-pdfbox-2/src/main/java/at/knowcenter/wag/egov/egiz/pdfbox2/pdf/PDFUtilities.java45
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){