From 37c44a6f329123fed82d2b3c996664e9174263e2 Mon Sep 17 00:00:00 2001 From: knowcenter Date: Tue, 13 Mar 2007 12:47:37 +0000 Subject: Rotated Pdf-files now are correct handled git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@51 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/knowcenter/wag/egov/egiz/PdfAS.java | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'src/main/java/at/knowcenter') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index 1492791..da98c95 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -71,6 +71,7 @@ import com.lowagie.text.pdf.PdfReader; * webapp, to perform signation and verification. * * @author wprinz + * @author mruhmer */ public abstract class PdfAS { @@ -381,18 +382,15 @@ public abstract class PdfAS public static List findBlockInText(String text, SignatureTypeDefinition sig_type_def, boolean old_style) { - // FIXME[tknall]: AbsoluteTextSignature.java, method findEndOfValue(...) does not work properly for landscape documents because start_index of FoundKeys are not set correctly. - // Hint: Captions and values of landscape documents are separated with " \n" and not with " " only. Vector keys = sig_type_def.getRevertSortedKeys(); Vector captions = sig_type_def.getRevertSortedCaptions(); int last_index = text.length(); - List found_keys = new ArrayList(); for (int key_idx = 0; key_idx < keys.size(); key_idx++) { String key = (String) keys.get(key_idx); - + //logger_.debug("Key="+key); if (old_style && key.equals(SignatureTypes.SIG_KZ)) { // If separating the old style way - skip The "Kennzeichnung" @@ -404,10 +402,15 @@ public abstract class PdfAS // int found_index = text.lastIndexOf(caption); // we're searching for captions that start at the beginning of the line. - int found_index = text.lastIndexOf("\n" + caption) + 1; // the +1 + int found_index =text.lastIndexOf("\n" +caption) + 1;//text.lastIndexOf("\n" + caption) + 1; // the +1 text.lastIndexOf(caption) + 1; // // compensates the // \n - + if (found_index == 0) + { + //try without /n + found_index = text.lastIndexOf(caption); + } + logger_.debug("found key:"+caption+" at index:"+found_index); if (key.equals(SignatureTypes.SIG_ID)) { if (found_index < 0 || found_index >= last_index) @@ -427,16 +430,16 @@ public abstract class PdfAS } FoundKey fk = new FoundKey(key, caption, found_index); - found_keys.add(fk); + found_keys.add(fk); last_index = found_index; } } sortFoundKeysDescendingly(found_keys); - + boolean matched = checkThatOrderIsCorrectAndCorrectFoundKeys(found_keys, keys, old_style); // boolean found_required = checkFoundRequiredKeys(found_keys, old_style); - + //logger_.debug("KKKKKKKKKKmatched="+matched); if (matched) { return found_keys; @@ -777,7 +780,7 @@ public abstract class PdfAS String connector) throws NormalizeException, PDFDocumentException, SignatureException { String text_to_be_verified = signature_holder.getSignedText(); - + //logger_.debug("verify text_to_be_verified"+text_to_be_verified); SignatureObject so_to_be_verified = signature_holder.getSignatureObject(); if (text_to_be_verified == null) @@ -830,7 +833,6 @@ public abstract class PdfAS final String user_name, final String user_password) throws SignatureException, PDFDocumentException { logger_.info("User signed a document: " + user_name); - if (text_to_sign == null) { throw new SignatureException(301, "Signature can not be produced. Text is null."); @@ -901,7 +903,7 @@ public abstract class PdfAS final String user_name, final String user_password, TablePos pos) throws PresentableException { Signator signator = SignatorFactory.createSignator(algorithm); - + IncrementalUpdateInformation iui = signator.prepareSign(pdf, signature_type, pos, ConnectorFactory.needsSIG_ID(connector)); iui.signed_signature_object = sign(iui.document_text, signature_type, connector, user_name, user_password); @@ -947,9 +949,9 @@ public abstract class PdfAS { ByteArrayInputStream bais = new ByteArrayInputStream(pdf, 0, length); String raw_document_text = TextualSignature.extractTextTextual(bais); - + //logger_.info("extractNormalizedTextTextual raw_document_text="+raw_document_text); String document_text = normalizeText(raw_document_text); - + logger_.info("extractNormalizedTextTextual document_text ="+document_text); return document_text; } @@ -1043,7 +1045,7 @@ public abstract class PdfAS public static PositioningInstruction adjustSignatureTableandCalculatePosition( final byte[] pdf, PdfPTable pdf_table, TablePos pos) throws PDFDocumentException { - //first check pageinstruction in TablePos-object + //first check pageinstruction in TablePos-object //new,auto,absolut PdfReader reader = readInPdfDocument(pdf); //get pages of currentdocument @@ -1061,6 +1063,8 @@ public abstract class PdfAS boolean make_new_page = pos.isNewPage(); //getPagedimensions Rectangle psize = reader.getPageSizeWithRotation(page); + int page_rotation = reader.getPageRotation(page); + float page_width = psize.width(); float page_height = psize.height(); //now we can calculate x-position @@ -1110,7 +1114,7 @@ public abstract class PdfAS //up to here no checks have to be made if Tablesize and Pagesize are fit //Now we have to getfreespace in page and reguard footerline float footer_line = pos.getFooterLine(); - float pre_page_length = PDFUtilities.calculatePageLength(pdf, page-1, page_height-footer_line); + float pre_page_length = PDFUtilities.calculatePageLength(pdf, page-1, page_height-footer_line, page_rotation); if (pre_page_length == Float.NEGATIVE_INFINITY) { //we do have an empty page or nothing in area above footerline @@ -1155,7 +1159,7 @@ public abstract class PdfAS /** * Sets the width of the table according to the layout of the document and * calculates the y position where the PDFPTable should be placed. - * + * @deprecated * @param pdf * The PDF document. * @param pdf_table @@ -1205,7 +1209,7 @@ public abstract class PdfAS * This algorithm tries to position the table between the end of the text and * the footer line. *

- * + * @deprecated * @param pdf * The PDF document. * @param pdf_table -- cgit v1.2.3