From 6d416edf737b9899aef7194aa66c35103dba07ce Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 11 Feb 2014 08:19:04 +0100 Subject: Support rotation of the signature block by r attribute in pos string --- .../at/gv/egiz/pdfas/stmp/itext/ITextStamper.java | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'stamper/stmp-itext/src/main/java/at/gv/egiz') diff --git a/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java b/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java index 1b026300..afcac94c 100644 --- a/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java +++ b/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java @@ -35,6 +35,7 @@ import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfStamper; +import com.lowagie.text.pdf.PdfTemplate; public class ITextStamper implements IPDFStamper { @@ -501,11 +502,39 @@ public class ITextStamper implements IPDFStamper { PdfPTable table = object.getTable(); + + logger.info("Positioning: X " + positioningInstruction.getX() + " Y " + positioningInstruction.getY()); + logger.info("Positioning: P " + positioningInstruction.getPage()); logger.info("Visual Object: " + visualObject.getWidth() + " x " + visualObject.getHeight()); - //PdfTemplate table_template = content.createTemplate(visualObject.getWidth(), visualObject.getHeight()); - table.writeSelectedRows(0, -1, positioningInstruction.getX(), + PdfTemplate table_template = content.createTemplate(table.getTotalWidth(), table.getTotalHeight()); + + /* table.writeSelectedRows(0, -1, positioningInstruction.getX(), positioningInstruction.getY(), content); + */ + table.writeSelectedRows(0, -1, 0, + table.getTotalHeight(), table_template); + //table_template. + + float rotate = positioningInstruction.getRotation(); + + if(rotate != 0) { + //set up the affine transform + float angle = (float)(-rotate * (Math.PI / 180)); + float fxScale = (float)(Math.cos(angle)); + float fyScale = (float)(Math.cos(angle)); + float fxRote = (float)(-Math.sin(angle)); + float fyRote = (float)(Math.sin(angle)); + + content.addTemplate(table_template, fxScale, fxRote, fyRote, fyScale, + positioningInstruction.getX(), + positioningInstruction.getY() - table.getTotalHeight()); + } else { + content.addTemplate(table_template, positioningInstruction.getX(), + positioningInstruction.getY() - table.getTotalHeight()); + } + + stamper.close(); -- cgit v1.2.3