From 98a8921b697e2b03c3f1a873ec1dadd02f954aa6 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 6 May 2014 13:25:43 +0200 Subject: Fixed Positioning on empty page with only annotation --- .../at/knowcenter/wag/egov/egiz/pdf/PDFPage.java | 6 +++--- .../knowcenter/wag/egov/egiz/pdf/PDFUtilities.java | 25 ++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag/egov') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java index e482d50c..f2cd4085 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java @@ -538,10 +538,10 @@ public class PDFPage extends PDFTextStripper { public void processAnnotation(PDAnnotation anno) { float current_y = anno.getRectangle().getLowerLeftY(); - int pageRotation = this.getCurrentPage().findRotation(); + int pageRotation = anno.getPage().findRotation(); // logger_.debug("PageRotation = " + pageRotation); if (pageRotation == 0) { - float page_height = this.getCurrentPage().findMediaBox().getHeight(); + float page_height = anno.getPage().findMediaBox().getHeight(); current_y = page_height - anno.getRectangle().getLowerLeftY(); } if (pageRotation == 90) { @@ -551,7 +551,7 @@ public class PDFPage extends PDFTextStripper { current_y = anno.getRectangle().getUpperRightY(); } if (pageRotation == 270) { - float page_height = this.getCurrentPage().findMediaBox().getHeight(); + float page_height = anno.getPage().findMediaBox().getHeight(); current_y = page_height - anno.getRectangle().getUpperRightX(); } diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java index 3f5e67fc..808efbe4 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java @@ -82,19 +82,22 @@ public abstract class PDFUtilities { try { PDFPage my_page = new PDFPage(effectivePageHeight, legacy32); PDResources resources = page.findResources(); - COSStream stream = page.getContents().getStream(); - // List articles = page.getThreadBeads(); - // my_page.processMyPage(page); - my_page.processStream(page, resources, stream); - + if (page.getContents() != null) { + COSStream stream = page.getContents().getStream(); + // List articles = page.getThreadBeads(); + // my_page.processMyPage(page); + my_page.processStream(page, resources, stream); + } if (!legacy32) { - Iterator annotationsIt = page.getAnnotations() - .iterator(); + if (page.getAnnotations() != null) { + Iterator annotationsIt = page + .getAnnotations().iterator(); - while (annotationsIt.hasNext()) { - PDAnnotation annotation = annotationsIt.next(); - if(!annotation.isInvisible()) { - my_page.processAnnotation(annotation); + while (annotationsIt.hasNext()) { + PDAnnotation annotation = annotationsIt.next(); + if (!annotation.isInvisible()) { + my_page.processAnnotation(annotation); + } } } } -- cgit v1.2.3