From bf3beb28c1ec92ca6110f8de0bf9eeb0b598a6de Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Fri, 6 Jun 2014 11:04:24 +0200 Subject: Signature Position merge, Table Borders offset fix --- .../lib/impl/signing/pdfbox/PADESPDFBOXSigner.java | 24 +- .../pdfbox/PDFAsVisualSignatureBuilder.java | 23 +- .../pdfbox/PDFAsVisualSignatureProperties.java | 2 +- .../lib/impl/stamping/pdfbox/PDFBoxTable.java | 2 - .../at/knowcenter/wag/egov/egiz/pdf/TablePos.java | 271 ++++++++++++--------- 5 files changed, 193 insertions(+), 129 deletions(-) (limited to 'pdf-as-lib/src/main') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java index b583e48e..1e33a3cb 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java @@ -171,17 +171,29 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { String posString = pdfObject.getStatus().getSignParamter() .getSignaturePosition(); - if (posString == null) { - posString = signatureProfileConfiguration + TablePos signaturePos = null; + + String signaturePosString = signatureProfileConfiguration .getDefaultPositioning(); - } + if(signaturePosString != null) { + logger.debug("using signature Positioning: " + signaturePos); + signaturePos = new TablePos(signaturePosString); + } + logger.debug("using Positioning: " + posString); - if (posString == null) { - tablePos = new TablePos(); + if (posString != null) { + // Merge Signature Position + tablePos = new TablePos(posString, signaturePos); } else { - tablePos = new TablePos(posString); + // Fallback to signature Position! + tablePos = signaturePos; + } + + if(tablePos == null) { + // Last Fallback default position + tablePos = new TablePos(); } } boolean legacy32Position = signatureProfileConfiguration diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java index d2049f24..e64d735a 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java @@ -52,7 +52,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { .getLogger(PDFAsVisualSignatureBuilder.class); private void drawTable(PDPage page, PDPageContentStream contentStream, - float x, float y, PDFBoxTable abstractTable, PDDocument doc, + float x, float y, float width, float height, PDFBoxTable abstractTable, PDDocument doc, boolean subtable) throws IOException, PdfAsException { final int rows = abstractTable.getRowCount(); @@ -109,9 +109,9 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { for (int i = 0; i < rows; i++) { ArrayList row = abstractTable.getRow(i); // Draw row border! - logger.debug("ROW LINE: {} {} {} {}", x, nexty, x + tableWidth, + logger.debug("ROW LINE: {} {} {} {}", x, nexty, x + width, nexty); - contentStream.drawLine(x, nexty, x + tableWidth, nexty); + contentStream.drawLine(x, nexty, x + width, nexty); lasty = nexty; if (i < abstractTable.getRowHeights().length) { nexty -= abstractTable.getRowHeights()[i] + padding * 2; @@ -144,7 +144,9 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } } } - contentStream.drawLine(nextx, lasty, nextx, nexty); + if(!subtable) { + contentStream.drawLine(nextx, lasty, nextx, nexty); + } } contentStream.drawLine(x, nexty, x + tableWidth, nexty); @@ -359,8 +361,10 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { tbl_value.table.setStyle(inherit_styletab); logger.debug("Table: " + tableX + " : " + tableY); - drawTable(page, contentStream, tableX, tableY, tbl_value, - doc, true); + drawTable(page, contentStream, tableX, tableY, + (colsSizes != null) ? colsSizes[j] : colWidth, + abstractTable.getRowHeights()[i] + padding * 2, + tbl_value, doc, true); } textx += (colsSizes != null) ? colsSizes[j] : colWidth; } @@ -379,6 +383,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } private PDFAsVisualSignatureProperties properties; + private PDFAsVisualSignatureDesigner designer; private ISettings settings; private PDResources innerFormResources; private Map images = new HashMap(); @@ -396,9 +401,11 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } public PDFAsVisualSignatureBuilder( - PDFAsVisualSignatureProperties properties, ISettings settings) { + PDFAsVisualSignatureProperties properties, ISettings settings, + PDFAsVisualSignatureDesigner designer) { this.properties = properties; this.settings = settings; + this.designer = designer; } @Override @@ -541,8 +548,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { PDPageContentStream stream = new PDPageContentStream(template, getStructure().getPage()); // stream.setFont(PDType1Font.COURIER, 5); - drawTable(getStructure().getPage(), stream, 1, 1, + designer.getWidth(), designer.getHeight(), properties.getMainTable(), template, false); stream.close(); PDStream innterFormStream = getStructure().getPage().getContents(); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java index 1b3cf688..6ed57703 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java @@ -50,7 +50,7 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties { @Override public void buildSignature() throws IOException { - PDFAsVisualSignatureBuilder builder = new PDFAsVisualSignatureBuilder(this, this.settings); + PDFAsVisualSignatureBuilder builder = new PDFAsVisualSignatureBuilder(this, this.settings, designer); PDFAsTemplateCreator creator = new PDFAsTemplateCreator(builder); setVisibleSignature(creator.buildPDF(designer)); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java index 1bbfbe9a..da228dae 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java @@ -11,8 +11,6 @@ import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.org.apache.bcel.internal.generic.Type; - import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException; import at.gv.egiz.pdfas.common.settings.ISettings; diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java index 2eb3b341..420a8f0a 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java @@ -158,6 +158,138 @@ public class TablePos implements Serializable //nothing to do --> default } + private void parsePosString(String pos_string) throws PdfAsException { + //parse posstring and throw exception + //[x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo] + + String[] strs = pos_string.split(";"); + try + { + for (int cmds = 0;cmds