diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java | 38 |
1 files changed, 38 insertions, 0 deletions
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
|