aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-08 18:07:56 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-08 18:07:56 +0200
commit023cff0dc812b943b636cdb9d26e251e233fbcbb (patch)
tree321e75f0610110cf4dc35bb36809748397c9555f /pdf-as-lib/src/main/java/at
parent818a6ab23ecad46089c13fdb99a24ae360cae6f5 (diff)
downloadpdf-as-4-023cff0dc812b943b636cdb9d26e251e233fbcbb.tar.gz
pdf-as-4-023cff0dc812b943b636cdb9d26e251e233fbcbb.tar.bz2
pdf-as-4-023cff0dc812b943b636cdb9d26e251e233fbcbb.zip
Some changes
Diffstat (limited to 'pdf-as-lib/src/main/java/at')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java27
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java13
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java171
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java23
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java6
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java5
6 files changed, 160 insertions, 85 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java
index 84e85686..7c8cb2e4 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java
@@ -23,15 +23,25 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl.positioning;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageNode;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
-import at.gv.egiz.pdfas.lib.impl.stamping.IPDFVisualObject;
import at.gv.egiz.pdfas.common.utils.PDFUtils;
+import at.gv.egiz.pdfas.lib.impl.stamping.IPDFVisualObject;
import at.knowcenter.wag.egov.egiz.pdf.PDFUtilities;
import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
/**
* Created with IntelliJ IDEA. User: afitzek Date: 8/29/13 Time: 4:30 PM To
@@ -39,6 +49,9 @@ import org.apache.pdfbox.pdmodel.common.PDRectangle;
*/
public class Positioning {
+ private static final Logger logger = LoggerFactory
+ .getLogger(Positioning.class);
+
/**
* The left/right margin.
*/
@@ -88,7 +101,7 @@ public class Positioning {
public static PositioningInstruction adjustSignatureTableandCalculatePosition(
final PDDocument pdfDataSource, IPDFVisualObject pdf_table,
TablePos pos, boolean legacy32) throws PdfAsException {
-
+
PDFUtils.checkPDFPermissions(pdfDataSource);
// get pages of currentdocument
@@ -108,7 +121,7 @@ public class Positioning {
// ") cannot be parsed.");
}
}
-
+
PDPage pdPage = (PDPage) pdfDataSource.getDocumentCatalog()
.getAllPages().get(page - 1);
PDRectangle cropBox = pdPage.getCropBox();
@@ -185,9 +198,11 @@ public class Positioning {
// fit
// Now we have to getfreespace in page and reguard footerline
float footer_line = pos.getFooterLine();
+
float pre_page_length = PDFUtilities.calculatePageLength(pdfDataSource,
page - 1, page_height - footer_line, /* page_rotation, */
legacy32);
+
if (pre_page_length == Float.NEGATIVE_INFINITY) {
// we do have an empty page or nothing in area above footerline
pre_page_length = page_height;
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 146e4993..4e82efa5 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
@@ -35,6 +35,7 @@ import java.util.List;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.exceptions.SignatureException;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -137,7 +138,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
signer.setPDSignature(signature);
SignatureOptions options = new SignatureOptions();
-
+
// Is visible Signature
if (requestedSignature.isVisual()) {
logger.info("Creating visual siganture block");
@@ -231,14 +232,14 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
position.setWidth(visualObject.getWidth());
requestedSignature.setSignaturePosition(position);
-
+
PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties(
pdfObject.getStatus().getSettings(), pdfObject,
(PdfBoxVisualObject) visualObject,
positioningInstruction);
properties.buildSignature();
-
+
/*
* ByteArrayOutputStream sigbos = new ByteArrayOutputStream();
* sigbos.write(StreamUtils.inputStreamToByteArray(properties
@@ -333,9 +334,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
options.setPage(positioningInstruction.getPage());
options.setVisualSignature(properties.getVisibleSignature());
}
-
+
doc.addSignature(signature, signer, options);
-
+
String sigFieldName = signatureProfileSettings.getSignFieldValue();
if (sigFieldName == null) {
@@ -372,7 +373,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
} else {
logger.warn("Failed to name Signature Field! [Cannot find acroForm!]");
}
-
+
if (requestedSignature.isVisual()) {
// if(requestedSignature.getSignaturePosition().)
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 00340db1..3d89d49f 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
@@ -57,6 +57,7 @@ import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSigBuilder;
+import org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSignDesigner;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
@@ -78,28 +79,31 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
float y, float width, float height) {
try {
contentStream.setStrokingColor(Color.RED);
- contentStream.drawLine(x, y, x+width, y);
+ contentStream.drawLine(x, y, x + width, y);
contentStream.setStrokingColor(Color.BLUE);
- contentStream.drawLine(x, y, x, y-height);
+ contentStream.drawLine(x, y, x, y - height);
contentStream.setStrokingColor(Color.GREEN);
- contentStream.drawLine(x+width, y, x+width, y-height);
+ contentStream.drawLine(x + width, y, x + width, y - height);
contentStream.setStrokingColor(Color.ORANGE);
- contentStream.drawLine(x, y-height, x+width, y-height);
-
+ contentStream.drawLine(x, y - height, x + width, y - height);
+
contentStream.setStrokingColor(Color.BLACK);
} catch (Throwable e) {
e.printStackTrace();
}
}
-
+
private void drawDebugPadding(PDPageContentStream contentStream, float x,
float y, float padding, float width, float height) {
try {
contentStream.setStrokingColor(Color.RED);
- contentStream.drawLine(x, y, x+padding, y-padding);
- contentStream.drawLine(x+width, y, x+width-padding, y-padding);
- contentStream.drawLine(x+width, y-height, x+width-padding, y-height+padding);
- contentStream.drawLine(x, y-height, x+padding, y-height+padding);
+ contentStream.drawLine(x, y, x + padding, y - padding);
+ contentStream.drawLine(x + width, y, x + width - padding, y
+ - padding);
+ contentStream.drawLine(x + width, y - height, x + width - padding,
+ y - height + padding);
+ contentStream.drawLine(x, y - height, x + padding, y - height
+ + padding);
contentStream.setStrokingColor(Color.BLACK);
} catch (Throwable e) {
e.printStackTrace();
@@ -170,19 +174,20 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
contentStream.drawLine(x, nexty, x + width, nexty);
lasty = nexty;
if (i < abstractTable.getRowHeights().length) {
- //nexty -= abstractTable.getRowHeights()[i] + padding * 2;
+ // nexty -= abstractTable.getRowHeights()[i] + padding * 2;
nexty -= abstractTable.getRowHeights()[i];
}
- //if (subtable && i + 1 == abstractTable.getRowHeights().length) {
- // nexty -= padding;
- //}
+ // if (subtable && i + 1 ==
+ // abstractTable.getRowHeights().length) {
+ // nexty -= padding;
+ // }
float nextx = x;
float ypos = y;
float yheight = y + abstractTable.getHeight();
if (subtable) {
- //ypos -= padding;
+ // ypos -= padding;
yheight = y + abstractTable.getHeight();
}
@@ -208,7 +213,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
}
contentStream.drawLine(x, nexty, x + tableWidth, nexty);
-
+
}
float textx = x;
@@ -218,19 +223,20 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
for (int j = 0; j < row.size(); j++) {
Entry cell = (Entry) row.get(j);
- Style inherit_style = Style.doInherit(cell.getStyle(), abstractTable.style);
+ Style inherit_style = Style.doInherit(cell.getStyle(),
+ abstractTable.style);
cell.setStyle(inherit_style);
- //if(subtable) {
- drawDebugPadding(contentStream, textx, texty, padding,
- ((colsSizes != null) ? colsSizes[j] : colWidth),
+ // if(subtable) {
+ drawDebugPadding(contentStream, textx, texty, padding,
+ ((colsSizes != null) ? colsSizes[j] : colWidth),
abstractTable.getRowHeights()[i]);
- //}
- //if(true) {
- // textx += (colsSizes != null) ? colsSizes[j] : colWidth;
- // continue;
- //}
-
+ // }
+ // if(true) {
+ // textx += (colsSizes != null) ? colsSizes[j] : colWidth;
+ // continue;
+ // }
+
if (cell.getType() == Entry.TYPE_CAPTION
|| cell.getType() == Entry.TYPE_VALUE) {
@@ -242,7 +248,6 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
fontSize = abstractTable.getValueFont().getFontSize();
}
-
String text = (String) cell.getValue();
// COSName name = COSName.getPDFName("ANDI_TAG!");
@@ -251,8 +256,9 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
String fontName = textFont.equals(PDType1Font.COURIER) ? "COURIER"
: "HELVETICA";
- float fheight = textFont.getFontDescriptor().getCapHeight() / 1000 * fontSize;
-
+ float fheight = textFont.getFontDescriptor().getCapHeight()
+ / 1000 * fontSize;
+
String[] tlines = text.split("\n");
float textHeight = fontSize * tlines.length;
@@ -270,7 +276,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
halign = cellStyle.getValueHAlign();
}
float ty = texty - padding;
- float tx = textx+padding;
+ float tx = textx + padding;
if (Style.BOTTOM.equals(valign)) {
float bottom_offset = abstractTable.getRowHeights()[i]
- textHeight;
@@ -304,7 +310,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
maxWidth = lineWidth;
}
}
-
+
if (Style.CENTER.equals(halign)) {
float offset = columnWidth - maxWidth - 2 * padding;
if (offset > 0) {
@@ -319,7 +325,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
}
drawDebugLine(contentStream, tx, ty, maxWidth, textHeight);
-
+
contentStream.beginText();
if (innerFormResources.getFonts().containsValue(textFont)) {
@@ -330,10 +336,11 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
} else {
contentStream.setFont(textFont, fontSize);
}
-
- logger.debug("Writing: " + tx + " : " + (ty-fheight) + " = " + text
- + " as " + cell.getType() + " w " + fontName);
- contentStream.moveTextPositionByAmount(tx, (ty-fheight));
+
+ logger.debug("Writing: " + tx + " : " + (ty - fheight)
+ + " = " + text + " as " + cell.getType() + " w "
+ + fontName);
+ contentStream.moveTextPositionByAmount(tx, (ty - fheight));
if (text.contains("\n")) {
String[] lines = text.split("\n");
@@ -358,11 +365,10 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
}
ImageObject image = images.get(img_ref);
PDXObjectImage pdImage = image.getImage();
-
+
float imgx = textx + padding;
float hoffset = ((colsSizes != null) ? colsSizes[j]
- : colWidth)
- - image.getWidth();
+ : colWidth) - image.getWidth();
if (cell.getStyle().getImageVAlign() != null
&& cell.getStyle().getImageVAlign()
.equals(Style.CENTER)) {
@@ -372,8 +378,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
&& cell.getStyle().getImageHAlign()
.equals(Style.RIGHT)) {
imgx += hoffset;
- }
-
+ }
+
float imgy = texty - padding;
float voffset = abstractTable.getRowHeights()[i]
- image.getHeight();
@@ -386,13 +392,16 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
&& cell.getStyle().getImageVAlign()
.equals(Style.BOTTOM)) {
imgy -= voffset;
- }
-
- drawDebugLine(contentStream, imgx, imgy, image.getWidth(), image.getHeight());
-
- logger.debug("Image: " + imgx + " : " + (imgy - image.getHeight()));
- contentStream.drawXObject(pdImage, imgx, imgy - image.getHeight(),
- image.getWidth(), image.getHeight());
+ }
+
+ drawDebugLine(contentStream, imgx, imgy, image.getWidth(),
+ image.getHeight());
+
+ logger.debug("Image: " + imgx + " : "
+ + (imgy - image.getHeight()));
+ contentStream.drawXObject(pdImage, imgx,
+ imgy - image.getHeight(), image.getWidth(),
+ image.getHeight());
// contentStream.endMarkedContentSequence();
} else if (cell.getType() == Entry.TYPE_TABLE) {
@@ -407,11 +416,12 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
tbl_value.table.setStyle(inherit_styletab);
logger.debug("Table: " + tableX + " : " + tableY);
- //logger.debug("Table height: " + );
- TableDrawUtils.drawTable(page, contentStream, tableX, tableY,
- (colsSizes != null) ? colsSizes[j] : colWidth,
- abstractTable.getRowHeights()[i],
- tbl_value, doc, true, innerFormResources, images, settings);
+ // logger.debug("Table height: " + );
+ TableDrawUtils.drawTable(page, contentStream, tableX,
+ tableY, (colsSizes != null) ? colsSizes[j]
+ : colWidth,
+ abstractTable.getRowHeights()[i], tbl_value, doc,
+ true, innerFormResources, images, settings);
}
textx += (colsSizes != null) ? colsSizes[j] : colWidth;
}
@@ -432,9 +442,9 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
private void drawTable2(PDPage page, PDPageContentStream contentStream,
float x, float y, float width, float height,
PDFBoxTable abstractTable, PDDocument doc, boolean subtable) {
-
+
}
-
+
private PDFAsVisualSignatureProperties properties;
private PDFAsVisualSignatureDesigner designer;
private ISettings settings;
@@ -473,6 +483,18 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
logger.debug("ProcSet array has been created");
}
+ public void createMyPage(PDFAsVisualSignatureDesigner properties) {
+ PDPage page = properties.getSignaturePage();
+ if (page == null) {
+ page = new PDPage();
+ page.setMediaBox(new PDRectangle(properties.getPageWidth(),
+ properties.getPageHeight()));
+
+ }
+ getStructure().setPage(page);
+ logger.info("PDF page has been created");
+ }
+
@Override
public void createTemplate(PDPage page) throws IOException {
PDDocument template = new PDDocument();
@@ -560,22 +582,24 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
float iwidth = (int) Math.floor((double) width);
iwidth -= 2 * padding;
-
+
float iheight = (int) Math.floor((double) height);
iheight -= 2 * padding;
-
+
float origWidth = (float) img.getWidth();
float origHeight = (float) img.getHeight();
-
+
float wfactor = iwidth / origWidth;
float hfactor = iheight / origHeight;
float scaleFactor = wfactor;
- if(hfactor < wfactor) {
+ if (hfactor < wfactor) {
scaleFactor = hfactor;
}
-
- iwidth = (float) Math.floor((double)(scaleFactor * origWidth));
- iheight = (float) Math.floor((double)(scaleFactor * origHeight));
+
+ iwidth = (float) Math
+ .floor((double) (scaleFactor * origWidth));
+ iheight = (float) Math
+ .floor((double) (scaleFactor * origHeight));
if (table.style != null) {
if (table.style.getImageScaleToFit() != null) {
@@ -585,8 +609,9 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
.getHeight();
}
}
-
- logger.debug("Scaling image to: " + iwidth + " x " + iheight);
+
+ logger.debug("Scaling image to: " + iwidth + " x "
+ + iheight);
if (img.getAlphaRaster() == null
&& img.getColorModel().hasAlpha()) {
@@ -595,7 +620,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
PDXObjectImage pdImage = new PDJpeg(template, img);
- ImageObject image = new ImageObject(pdImage, iwidth, iheight);
+ ImageObject image = new ImageObject(pdImage, iwidth,
+ iheight);
images.put(img_ref, image);
innerFormResources.addXObject(pdImage, "Im");
}
@@ -610,12 +636,16 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
@Override
public void createInnerFormStream(PDDocument template) {
try {
-
+
// Hint we have to create all PDXObjectImages before creating the
// PDPageContentStream
// only PDFbox developers know why ...
- innerFormResources = new PDResources();
- getStructure().getPage().setResources(innerFormResources);
+ //if (getStructure().getPage().getResources() != null) {
+ // innerFormResources = getStructure().getPage().getResources();
+ //} else {
+ innerFormResources = new PDResources();
+ getStructure().getPage().setResources(innerFormResources);
+ //}
readTableResources(properties.getMainTable(), template);
PDPageContentStream stream = new PDPageContentStream(template,
@@ -623,7 +653,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
// stream.setFont(PDType1Font.COURIER, 5);
TableDrawUtils.drawTable(getStructure().getPage(), stream, 1, 1,
designer.getWidth(), designer.getHeight(),
- properties.getMainTable(), template, false, innerFormResources, images, settings);
+ properties.getMainTable(), template, false,
+ innerFormResources, images, settings);
stream.close();
PDStream innterFormStream = getStructure().getPage().getContents();
getStructure().setInnterFormStream(innterFormStream);
@@ -680,7 +711,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
String innerFormComment = getStructure().getInnterFormStream()
.getInputStreamAsString();
- //logger.debug("Inner Form Stream: " + innerFormComment);
+ // logger.debug("Inner Form Stream: " + innerFormComment);
// appendRawCommands(getStructure().getInnterFormStream().createOutputStream(),
// getStructure().getInnterFormStream().getInputStreamAsString());
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java
index 1638f102..45789491 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java
@@ -52,7 +52,9 @@ public class PDFAsVisualSignatureDesigner {
private float[] formaterRectangleParams = { 0, 0, 100, 50 }; // default
private byte[] AffineTransformParams = { 1, 0, 0, 1, 0, 0 }; // default
private float imageSizeInPercents;
-// private PDDocument document = null;
+ private PDDocument document = null;
+ private int page = 0;
+ private boolean newpage = false;
PDFAsVisualSignatureProperties properties;
/**
@@ -68,6 +70,9 @@ public class PDFAsVisualSignatureDesigner {
PDFAsVisualSignatureProperties properties, boolean newpage) throws IOException {
this.properties = properties;
calculatePageSize(doc, page, newpage);
+ document = doc;
+ this.page = page;
+ this.newpage = newpage;
}
/**
@@ -363,6 +368,22 @@ public class PDFAsVisualSignatureDesigner {
public float getPageWidth() {
return pageWidth;
}
+
+ public PDPage getSignaturePage() {
+ if (page < 1) {
+ throw new IllegalArgumentException("First page of pdf is 1, not "
+ + page);
+ }
+ PDPage pdPage = null;
+ List<?> pages = document.getDocumentCatalog().getAllPages();
+ if(newpage) {
+ pdPage = new PDPage();
+ } else {
+ pdPage = (PDPage) pages.get(page - 1);
+ }
+
+ return pdPage;
+ }
/**
*
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 1ee3674a..bcc75338 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
@@ -25,6 +25,7 @@ package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox;
import java.io.IOException;
+import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
@@ -53,7 +54,6 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
this.settings = settings;
try {
main = visObj.getTable();
-
} catch (Throwable e) {
e.printStackTrace();
}
@@ -89,4 +89,8 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
return this.rotationAngle;
}
+ public PDFAsVisualSignatureDesigner getDesigner() {
+ return designer;
+ }
+
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java
index 0147ad61..e9a4d7f5 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java
@@ -29,6 +29,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
@@ -309,7 +312,7 @@ public class TableDrawUtils {
try {
float innerHeight = height;
float innerWidth = width;
-
+
String img_ref = (String) cell.getValue();
if (!images.containsKey(img_ref)) {
logger.error("Image not prepared! : " + img_ref);