From ade592d842b1880b7f01b1c6ad4b382569d67014 Mon Sep 17 00:00:00 2001 From: knowcenter Date: Fri, 2 Mar 2007 08:25:07 +0000 Subject: now its posible to calculate pagelength of arbitrary page git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@40 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../knowcenter/wag/egov/egiz/pdf/PDFUtilities.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java index 05854dd..5384a8c 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java @@ -35,9 +35,47 @@ import com.lowagie.text.DocumentException; * Contains useful helpers for accessing PDF documents. * * @author wprinz + * @author mruhmer */ public abstract class PDFUtilities { + public static float calculatePageLength(final byte[] pdf,int page ,float footer_line) throws PDFDocumentException + { + try + { + ByteArrayInputStream original_bais = new ByteArrayInputStream(pdf); + byte [] normalized_pdf = TextualSignature.normalizePDF(original_bais); + + ByteArrayInputStream bais = new ByteArrayInputStream(normalized_pdf); + + PDFParser parser = new PDFParser(bais); + File temporary_dir = SettingsReader.getTemporaryDirectory(); + parser.setTempDirectory(temporary_dir); + parser.parse(); + + PDDocument pdfDocument_ = parser.getPDDocument(); + float page_length = calculatePageLength(pdfDocument_,page , footer_line); + pdfDocument_.close(); + return page_length; + } + catch (IOException e) + { + throw new PDFDocumentException(201, e); + } + catch (DocumentException e) + { + throw new PDFDocumentException(201, e); + } + } + public static float calculatePageLength(PDDocument document,int page ,float footer_line) throws IOException + { + //int last_page_id = document.getNumberOfPages(); + List allPages = document.getDocumentCatalog().getAllPages(); + PDPage pdpage = (PDPage) allPages.get(page); + + return calculatePageLength(pdpage, footer_line); + } + public static float calculateLastPageLength(final byte[] pdf, float footer_line) throws PDFDocumentException { try -- cgit v1.2.3