aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-02-22 08:50:45 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-02-22 08:50:45 +0100
commita51e5b49070a6e6d4e4723e714b08e08884ddd7b (patch)
tree1176c6c4e6e0d25a82806f6c2ca5a2fc6c5d6682 /pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl
parent36ddff26736c03a0f02ca636889a130fa1548f35 (diff)
downloadpdf-as-4-a51e5b49070a6e6d4e4723e714b08e08884ddd7b.tar.gz
pdf-as-4-a51e5b49070a6e6d4e4723e714b08e08884ddd7b.tar.bz2
pdf-as-4-a51e5b49070a6e6d4e4723e714b08e08884ddd7b.zip
introduced minimum width for visual signature when positioned with a placeholder
Diffstat (limited to 'pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl')
-rw-r--r--pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java413
1 files changed, 179 insertions, 234 deletions
diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
index 31098e97..3e9fa702 100644
--- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
+++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
@@ -103,15 +103,13 @@ import iaik.x509.X509Certificate;
public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
- private static final Logger logger = LoggerFactory
- .getLogger(PADESPDFBOXSigner.class);
-
- public void signPDF(PDFObject genericPdfObject,
- RequestedSignature requestedSignature,
+ private static final Logger logger = LoggerFactory.getLogger(PADESPDFBOXSigner.class);
+
+ public void signPDF(PDFObject genericPdfObject, RequestedSignature requestedSignature,
PDFASSignatureInterface genericSigner) throws PdfAsException {
String fisTmpFile = null;
- PDFAsVisualSignatureProperties properties=null;
+ PDFAsVisualSignatureProperties properties = null;
if (!(genericPdfObject instanceof PDFBOXObject)) {
// tODO:
@@ -148,10 +146,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
doc = pdfObject.getDocument();
-
+
SignaturePlaceholderData signaturePlaceholderData = PlaceholderFilter
- .checkPlaceholderSignature(pdfObject.getStatus(),
- pdfObject.getStatus().getSettings());
+ .checkPlaceholderSignature(pdfObject.getStatus(), pdfObject.getStatus().getSettings());
TablePos tablePos = null;
@@ -159,41 +156,42 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// Placeholder found!
logger.info("Placeholder data found.");
if (signaturePlaceholderData.getProfile() != null) {
- logger.debug("Placeholder Profile set to: "
- + signaturePlaceholderData.getProfile());
- requestedSignature
- .setSignatureProfileID(signaturePlaceholderData
- .getProfile());
+ logger.debug("Placeholder Profile set to: " + signaturePlaceholderData.getProfile());
+ requestedSignature.setSignatureProfileID(signaturePlaceholderData.getProfile());
}
tablePos = signaturePlaceholderData.getTablePos();
if (tablePos != null) {
- logger.debug("Placeholder Position set to: "
- + tablePos.toString());
+
+ SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus()
+ .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID());
+
+ float minWidth = signatureProfileConfiguration.getMinWidth();
+
+ if (tablePos.getWidth() < minWidth) {
+ tablePos.width = minWidth;
+ logger.debug("Correcting placeholder with to minimum width {}", minWidth);
+ }
+
+ logger.debug("Placeholder Position set to: " + tablePos.toString());
}
}
PDSignature signature = new PDSignature();
signature.setFilter(COSName.getPDFName(signer.getPDFFilter())); // default
// filter
- signature.setSubFilter(COSName.getPDFName(signer
- .getPDFSubFilter()));
+ signature.setSubFilter(COSName.getPDFName(signer.getPDFSubFilter()));
SignatureProfileSettings signatureProfileSettings = TableFactory
- .createProfile(
- requestedSignature.getSignatureProfileID(),
- pdfObject.getStatus().getSettings());
-
- ValueResolver resolver = new ValueResolver(requestedSignature,
- pdfObject.getStatus());
- String signerName = resolver.resolve("SIG_SUBJECT",
- signatureProfileSettings.getValue("SIG_SUBJECT"),
+ .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings());
+
+ ValueResolver resolver = new ValueResolver(requestedSignature, pdfObject.getStatus());
+ String signerName = resolver.resolve("SIG_SUBJECT", signatureProfileSettings.getValue("SIG_SUBJECT"),
signatureProfileSettings);
signature.setName(signerName);
signature.setSignDate(Calendar.getInstance());
- String signerReason = signatureProfileSettings
- .getSigningReason();
+ String signerReason = signatureProfileSettings.getSigningReason();
if (signerReason == null) {
signerReason = "PAdES Signature";
@@ -202,21 +200,20 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
signature.setReason(signerReason);
logger.debug("Signing reason: " + signerReason);
- logger.debug("Signing @ "
- + signer.getSigningDate().getTime().toString());
+ logger.debug("Signing @ " + signer.getSigningDate().getTime().toString());
// the signing date, needed for valid signature
// signature.setSignDate(signer.getSigningDate());
signer.setPDSignature(signature);
-
+
int signatureSize = 0x1000;
try {
String reservedSignatureSizeString = signatureProfileSettings.getValue(SIG_RESERVED_SIZE);
- if(reservedSignatureSizeString != null) {
+ if (reservedSignatureSizeString != null) {
signatureSize = Integer.parseInt(reservedSignatureSizeString);
}
logger.debug("Reserving {} bytes for signature", signatureSize);
- } catch(NumberFormatException e) {
+ } catch (NumberFormatException e) {
logger.warn("Invalid configuration value: {} should be a number using 0x1000", SIG_RESERVED_SIZE);
}
options.setPreferedSignatureSize(signatureSize);
@@ -225,9 +222,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
if (requestedSignature.isVisual()) {
logger.info("Creating visual siganture block");
- SignatureProfileConfiguration signatureProfileConfiguration = pdfObject
- .getStatus().getSignatureProfileConfiguration(
- requestedSignature.getSignatureProfileID());
+ SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus()
+ .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID());
if (tablePos == null) {
// ================================================================
@@ -235,17 +231,14 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// fixed
// position
- String posString = pdfObject.getStatus()
- .getSignParamter().getSignaturePosition();
+ String posString = pdfObject.getStatus().getSignParamter().getSignaturePosition();
TablePos signaturePos = null;
- String signaturePosString = signatureProfileConfiguration
- .getDefaultPositioning();
+ String signaturePosString = signatureProfileConfiguration.getDefaultPositioning();
if (signaturePosString != null) {
- logger.debug("using signature Positioning: "
- + signaturePos);
+ logger.debug("using signature Positioning: " + signaturePos);
signaturePos = new TablePos(signaturePosString);
}
@@ -264,20 +257,16 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
tablePos = new TablePos();
}
}
- boolean legacy32Position = signatureProfileConfiguration
- .getLegacy32Positioning();
+
+ boolean legacy32Position = signatureProfileConfiguration.getLegacy32Positioning();
// create Table describtion
- Table main = TableFactory.createSigTable(
- signatureProfileSettings, MAIN,
- pdfObject.getStatus(), requestedSignature);
+ Table main = TableFactory.createSigTable(signatureProfileSettings, MAIN, pdfObject.getStatus(),
+ requestedSignature);
- IPDFStamper stamper = StamperFactory
- .createDefaultStamper(pdfObject.getStatus()
- .getSettings());
+ IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject.getStatus().getSettings());
- IPDFVisualObject visualObject = stamper
- .createVisualPDFObject(pdfObject, main);
+ IPDFVisualObject visualObject = stamper.createVisualPDFObject(pdfObject, main);
/*
* PDDocument originalDocument = PDDocument .load(new
@@ -285,12 +274,10 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
* .getPdfObject().getOriginalDocument()));
*/
- PositioningInstruction positioningInstruction = Positioning
- .determineTablePositioning(tablePos, "", doc,
- visualObject, legacy32Position);
+ PositioningInstruction positioningInstruction = Positioning.determineTablePositioning(tablePos, "",
+ doc, visualObject, legacy32Position);
- logger.debug("Positioning: {}",
- positioningInstruction.toString());
+ logger.debug("Positioning: {}", positioningInstruction.toString());
if (positioningInstruction.isMakeNewPage()) {
int last = doc.getNumberOfPages() - 1;
@@ -307,22 +294,19 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
// handle rotated page
- PDDocumentCatalog documentCatalog = doc
- .getDocumentCatalog();
+ PDDocumentCatalog documentCatalog = doc.getDocumentCatalog();
PDPageNode documentPages = documentCatalog.getPages();
List<PDPage> documentPagesKids = new ArrayList<PDPage>();
documentPages.getAllKids(documentPagesKids);
int targetPageNumber = positioningInstruction.getPage();
logger.debug("Target Page: " + targetPageNumber);
// rootPages.getAllKids(kids);
- PDPage targetPage = documentPagesKids
- .get(targetPageNumber - 1);
+ PDPage targetPage = documentPagesKids.get(targetPageNumber - 1);
int rot = targetPage.findRotation();
logger.debug("Page rotation: " + rot);
// positioningInstruction.setRotation(positioningInstruction.getRotation()
// + rot);
- logger.debug("resulting Sign rotation: "
- + positioningInstruction.getRotation());
+ logger.debug("resulting Sign rotation: " + positioningInstruction.getRotation());
SignaturePositionImpl position = new SignaturePositionImpl();
position.setX(positioningInstruction.getX());
@@ -333,10 +317,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
requestedSignature.setSignaturePosition(position);
- properties = new PDFAsVisualSignatureProperties(
- pdfObject.getStatus().getSettings(), pdfObject,
- (PdfBoxVisualObject) visualObject,
- positioningInstruction, signatureProfileSettings);
+ properties = new PDFAsVisualSignatureProperties(pdfObject.getStatus().getSettings(), pdfObject,
+ (PdfBoxVisualObject) visualObject, positioningInstruction, signatureProfileSettings);
properties.buildSignature();
@@ -352,8 +334,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// replace placeholder
InputStream is = null;
try {
- is = PADESPDFBOXSigner.class
- .getResourceAsStream("/placeholder/empty.jpg");
+ is = PADESPDFBOXSigner.class.getResourceAsStream("/placeholder/empty.jpg");
PDJpeg img = new PDJpeg(doc, is);
img.getCOSObject().setNeedToBeUpdate(true);
@@ -366,20 +347,13 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// rootPages.getAllKids(kids);
PDPage page = kids.get(pageNumber - 1);
- logger.info("Placeholder name: "
- + signaturePlaceholderData
- .getPlaceholderName());
- COSDictionary xobjectsDictionary = (COSDictionary) page
- .findResources().getCOSDictionary()
+ logger.info("Placeholder name: " + signaturePlaceholderData.getPlaceholderName());
+ COSDictionary xobjectsDictionary = (COSDictionary) page.findResources().getCOSDictionary()
.getDictionaryObject(COSName.XOBJECT);
- xobjectsDictionary.setItem(signaturePlaceholderData
- .getPlaceholderName(), img);
+ xobjectsDictionary.setItem(signaturePlaceholderData.getPlaceholderName(), img);
xobjectsDictionary.setNeedToBeUpdate(true);
- page.findResources().getCOSObject()
- .setNeedToBeUpdate(true);
- logger.info("Placeholder name: "
- + signaturePlaceholderData
- .getPlaceholderName());
+ page.findResources().getCOSObject().setNeedToBeUpdate(true);
+ logger.info("Placeholder name: " + signaturePlaceholderData.getPlaceholderName());
} finally {
IOUtils.closeQuietly(is);
}
@@ -387,8 +361,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
if (signatureProfileSettings.isPDFA()) {
PDDocumentCatalog root = doc.getDocumentCatalog();
- COSBase base = root.getCOSDictionary().getItem(
- COSName.OUTPUT_INTENTS);
+ COSBase base = root.getCOSDictionary().getItem(COSName.OUTPUT_INTENTS);
if (base == null) {
InputStream colorProfile = null;
try {
@@ -396,8 +369,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
.getResourceAsStream("/icm/sRGB Color Space Profile.icm");
try {
- PDOutputIntent oi = new PDOutputIntent(doc,
- colorProfile);
+ PDOutputIntent oi = new PDOutputIntent(doc, colorProfile);
oi.setInfo("sRGB IEC61966-2.1");
oi.setOutputCondition("sRGB IEC61966-2.1");
oi.setOutputConditionIdentifier("sRGB IEC61966-2.1");
@@ -408,8 +380,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
logger.info("added Output Intent");
} catch (Throwable e) {
e.printStackTrace();
- throw new PdfAsException(
- "Failed to add Output Intent", e);
+ throw new PdfAsException("Failed to add Output Intent", e);
}
} finally {
IOUtils.closeQuietly(colorProfile);
@@ -417,18 +388,15 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
}
-
-
options.setPage(positioningInstruction.getPage());
options.setVisualSignature(properties.getVisibleSignature());
}
-
+
visualSignatureDocumentGuard = options.getVisualSignature();
doc.addSignature(signature, signer, options);
- String sigFieldName = signatureProfileSettings
- .getSignFieldValue();
+ String sigFieldName = signatureProfileSettings.getSignFieldValue();
if (sigFieldName == null) {
sigFieldName = "PDF-AS Signatur";
@@ -440,18 +408,18 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
PDAcroForm acroFormm = doc.getDocumentCatalog().getAcroForm();
- // PDStructureTreeRoot pdstRoot = doc.getDocumentCatalog().getStructureTreeRoot();
- // COSDictionary dic = doc.getDocumentCatalog().getCOSDictionary();
- // PDStructureElement el = new PDStructureElement("Widget", pdstRoot);
-
-
+ // PDStructureTreeRoot pdstRoot =
+ // doc.getDocumentCatalog().getStructureTreeRoot();
+ // COSDictionary dic =
+ // doc.getDocumentCatalog().getCOSDictionary();
+ // PDStructureElement el = new PDStructureElement("Widget",
+ // pdstRoot);
PDSignatureField signatureField = null;
if (acroFormm != null) {
@SuppressWarnings("unchecked")
List<PDField> fields = acroFormm.getFields();
-
if (fields != null) {
for (PDField pdField : fields) {
if (pdField != null) {
@@ -459,13 +427,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
PDSignatureField tmpSigField = (PDSignatureField) pdField;
if (tmpSigField.getSignature() != null
- && tmpSigField.getSignature()
- .getDictionary() != null) {
- if (tmpSigField
- .getSignature()
- .getDictionary()
- .equals(signature
- .getDictionary())) {
+ && tmpSigField.getSignature().getDictionary() != null) {
+ if (tmpSigField.getSignature().getDictionary()
+ .equals(signature.getDictionary())) {
signatureField = (PDSignatureField) pdField;
}
@@ -478,11 +442,11 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
if (signatureField != null) {
- signatureField.setPartialName(sigFieldName);
+ signatureField.setPartialName(sigFieldName);
}
- if(properties!=null){
+ if (properties != null) {
signatureField.setAlternateFieldName(properties.getAlternativeTableCaption());
- }else{
+ } else {
signatureField.setAlternateFieldName(sigFieldName);
}
} else {
@@ -491,94 +455,94 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// PDF-UA
logger.info("Adding pdf/ua content.");
- try{
+ try {
PDDocumentCatalog root = doc.getDocumentCatalog();
PDStructureTreeRoot treeRoot = root.getStructureTreeRoot();
- if(treeRoot != null) {
- logger.info("Tree Root: {}", treeRoot.toString());
- List<Object> kids = treeRoot.getKids();
-
- if(kids==null){
- logger.info("No kid-elements in structure tree Root, maybe not PDF/UA document");
- }
+ if (treeRoot != null) {
+ logger.info("Tree Root: {}", treeRoot.toString());
+ List<Object> kids = treeRoot.getKids();
- PDStructureElement docElement = null;
- for(Object k: kids){
- if(k instanceof PDStructureElement){
- docElement=(PDStructureElement) k;
- break;
- // if(((PDStructureElement) k).getStructureType().equals("Document")){
- // docElement=(PDStructureElement) k;
- // }
+ if (kids == null) {
+ logger.info("No kid-elements in structure tree Root, maybe not PDF/UA document");
}
- }
-
- PDStructureElement sigBlock = new PDStructureElement(
- "Form", docElement);
-
- //create object dictionary and add as child element
- COSDictionary objectdic= new COSDictionary();
- objectdic.setName("Type", "OBJR");
- objectdic.setItem("Pg", signatureField.getWidget().getPage());
- objectdic.setItem("Obj", signatureField.getWidget());
-
- List<Object> l = new ArrayList<Object>();
- l.add(objectdic);
- sigBlock.setKids(l);
-
- sigBlock.setTitle("Signature Table");
- sigBlock.setParent(docElement);
- docElement.appendKid(sigBlock);
-
- //Create and add Attribute dictionary to mitigate PAC warning
- COSDictionary sigBlockDic = (COSDictionary) sigBlock.getCOSObject();
- COSDictionary sub = new COSDictionary();
-
- sub.setName("O", "Layout");
- sub.setName("Placement", "Block");
- sigBlockDic.setItem(COSName.A, sub);
- sigBlockDic.setNeedToBeUpdate(true);
+ PDStructureElement docElement = null;
+ for (Object k : kids) {
+ if (k instanceof PDStructureElement) {
+ docElement = (PDStructureElement) k;
+ break;
+ // if(((PDStructureElement)
+ // k).getStructureType().equals("Document")){
+ // docElement=(PDStructureElement) k;
+ // }
+ }
+ }
- //Modify number tree
- PDNumberTreeNode ntn = treeRoot.getParentTree();
- if(ntn==null){
- ntn = new PDNumberTreeNode(objectdic, null);
- logger.info("No number-tree-node found!");
- }
+ PDStructureElement sigBlock = new PDStructureElement("Form", docElement);
+
+ // create object dictionary and add as child element
+ COSDictionary objectdic = new COSDictionary();
+ objectdic.setName("Type", "OBJR");
+ objectdic.setItem("Pg", signatureField.getWidget().getPage());
+ objectdic.setItem("Obj", signatureField.getWidget());
+
+ List<Object> l = new ArrayList<Object>();
+ l.add(objectdic);
+ sigBlock.setKids(l);
+
+ sigBlock.setTitle("Signature Table");
+ sigBlock.setParent(docElement);
+ docElement.appendKid(sigBlock);
+
+ // Create and add Attribute dictionary to mitigate PAC
+ // warning
+ COSDictionary sigBlockDic = (COSDictionary) sigBlock.getCOSObject();
+ COSDictionary sub = new COSDictionary();
+
+ sub.setName("O", "Layout");
+ sub.setName("Placement", "Block");
+ sigBlockDic.setItem(COSName.A, sub);
+ sigBlockDic.setNeedToBeUpdate(true);
+
+ // Modify number tree
+ PDNumberTreeNode ntn = treeRoot.getParentTree();
+ if (ntn == null) {
+ ntn = new PDNumberTreeNode(objectdic, null);
+ logger.info("No number-tree-node found!");
+ }
- COSDictionary ntndic=ntn.getCOSDictionary();
- COSArray ntndicnumbersarray = (COSArray)ntndic.getDictionaryObject(COSName.NUMS);
- int arrindex = ntndicnumbersarray.size();
- int treeindex = arrindex/2;
+ COSDictionary ntndic = ntn.getCOSDictionary();
+ COSArray ntndicnumbersarray = (COSArray) ntndic.getDictionaryObject(COSName.NUMS);
+ int arrindex = ntndicnumbersarray.size();
+ int treeindex = arrindex / 2;
- ntndicnumbersarray.add(arrindex, COSInteger.get(treeindex));
- ntndicnumbersarray.add(arrindex+1, sigBlock.getCOSObject());
+ ntndicnumbersarray.add(arrindex, COSInteger.get(treeindex));
+ ntndicnumbersarray.add(arrindex + 1, sigBlock.getCOSObject());
- treeRoot.setParentTree(ntn);
- treeRoot.setParentTreeNextKey(treeindex+1);
+ treeRoot.setParentTree(ntn);
+ treeRoot.setParentTreeNextKey(treeindex + 1);
- //setStructureParent
- PDAnnotationWidget widg=signatureField.getWidget();
- widg.setStructParent(treeindex);
+ // setStructureParent
+ PDAnnotationWidget widg = signatureField.getWidget();
+ widg.setStructParent(treeindex);
- //add the Tabs /S Element for Tabbing through annots
- PDPage p = signatureField.getWidget().getPage();
- p.getCOSDictionary().setName("Tabs", "S");
- p.getCOSObject().setNeedToBeUpdate(true);
+ // add the Tabs /S Element for Tabbing through annots
+ PDPage p = signatureField.getWidget().getPage();
+ p.getCOSDictionary().setName("Tabs", "S");
+ p.getCOSObject().setNeedToBeUpdate(true);
- ntndic.setNeedToBeUpdate(true);
- sigBlock.getCOSObject().setNeedToBeUpdate(true);
- treeRoot.getCOSObject().setNeedToBeUpdate(true);
- objectdic.getCOSObject().setNeedToBeUpdate(true);
- docElement.getCOSObject().setNeedToBeUpdate(true);
+ ntndic.setNeedToBeUpdate(true);
+ sigBlock.getCOSObject().setNeedToBeUpdate(true);
+ treeRoot.getCOSObject().setNeedToBeUpdate(true);
+ objectdic.getCOSObject().setNeedToBeUpdate(true);
+ docElement.getCOSObject().setNeedToBeUpdate(true);
}
- }catch(Throwable e){
- if (signatureProfileSettings.isPDFUA()==true){
+ } catch (Throwable e) {
+ if (signatureProfileSettings.isPDFUA() == true) {
logger.error("Could not create PDF-UA conform document!");
throw new PdfAsException("error.pdf.sig.pdfua.1", e);
- }else{
+ } else {
logger.info("Could not create PDF-UA conform signature");
}
}
@@ -634,8 +598,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
tmpFileIs.close();
} finally {
IOUtils.closeQuietly(tmpFileIs);
- if(options != null) {
- if(options.getVisualSignature() != null) {
+ if (options != null) {
+ if (options.getVisualSignature() != null) {
options.getVisualSignature().close();
}
}
@@ -655,8 +619,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
// bos.write();
// bos.close();
- pdfObject.setSignedDocument(StreamUtils
- .inputStreamToByteArray(readReadyFile));
+ pdfObject.setSignedDocument(StreamUtils.inputStreamToByteArray(readReadyFile));
readReadyFile.close();
} finally {
IOUtils.closeQuietly(readReadyFile);
@@ -681,7 +644,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
}
- if(fisTmpFile != null) {
+ if (fisTmpFile != null) {
helper.deleteFile(fisTmpFile);
}
logger.debug("Signature done!");
@@ -695,21 +658,19 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
@Override
- public PDFASSignatureInterface buildSignaturInterface(IPlainSigner signer,
- SignParameter parameters, RequestedSignature requestedSignature) {
+ public PDFASSignatureInterface buildSignaturInterface(IPlainSigner signer, SignParameter parameters,
+ RequestedSignature requestedSignature) {
return new PdfboxSignerWrapper(signer, parameters, requestedSignature);
}
@Override
- public PDFASSignatureExtractor buildBlindSignaturInterface(
- X509Certificate certificate, String filter, String subfilter,
- Calendar date) {
+ public PDFASSignatureExtractor buildBlindSignaturInterface(X509Certificate certificate, String filter,
+ String subfilter, Calendar date) {
return new SignatureDataExtractor(certificate, filter, subfilter, date);
}
@Override
- public void checkPDFPermissions(PDFObject genericPdfObject)
- throws PdfAsException {
+ public void checkPDFPermissions(PDFObject genericPdfObject) throws PdfAsException {
if (!(genericPdfObject instanceof PDFBOXObject)) {
// tODO:
throw new PdfAsException();
@@ -727,10 +688,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
@Override
- public Image generateVisibleSignaturePreview(SignParameter parameter,
- java.security.cert.X509Certificate cert, int resolution,
- OperationStatus status, RequestedSignature requestedSignature)
- throws PDFASError {
+ public Image generateVisibleSignaturePreview(SignParameter parameter, java.security.cert.X509Certificate cert,
+ int resolution, OperationStatus status, RequestedSignature requestedSignature) throws PDFASError {
try {
PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject();
@@ -740,37 +699,30 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
origDoc.save(baos);
baos.close();
- pdfObject.setOriginalDocument(new ByteArrayDataSource(baos
- .toByteArray()));
+ pdfObject.setOriginalDocument(new ByteArrayDataSource(baos.toByteArray()));
SignatureProfileSettings signatureProfileSettings = TableFactory
- .createProfile(requestedSignature.getSignatureProfileID(),
- pdfObject.getStatus().getSettings());
+ .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings());
// create Table describtion
- Table main = TableFactory.createSigTable(signatureProfileSettings,
- MAIN, pdfObject.getStatus(), requestedSignature);
+ Table main = TableFactory.createSigTable(signatureProfileSettings, MAIN, pdfObject.getStatus(),
+ requestedSignature);
- IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject
- .getStatus().getSettings());
+ IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject.getStatus().getSettings());
- IPDFVisualObject visualObject = stamper.createVisualPDFObject(
- pdfObject, main);
+ IPDFVisualObject visualObject = stamper.createVisualPDFObject(pdfObject, main);
- SignatureProfileConfiguration signatureProfileConfiguration = pdfObject
- .getStatus().getSignatureProfileConfiguration(
- requestedSignature.getSignatureProfileID());
+ SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus()
+ .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID());
- String signaturePosString = signatureProfileConfiguration
- .getDefaultPositioning();
+ String signaturePosString = signatureProfileConfiguration.getDefaultPositioning();
PositioningInstruction positioningInstruction = null;
if (signaturePosString != null) {
- positioningInstruction = Positioning.determineTablePositioning(
- new TablePos(signaturePosString), "", origDoc,
- visualObject, false);
+ positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "",
+ origDoc, visualObject, false);
} else {
- positioningInstruction = Positioning.determineTablePositioning(
- new TablePos(), "", origDoc, visualObject, false);
+ positioningInstruction = Positioning.determineTablePositioning(new TablePos(), "", origDoc,
+ visualObject, false);
}
origDoc.close();
@@ -785,15 +737,13 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
requestedSignature.setSignaturePosition(position);
PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties(
- pdfObject.getStatus().getSettings(), pdfObject,
- (PdfBoxVisualObject) visualObject, positioningInstruction,
- signatureProfileSettings);
+ pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject,
+ positioningInstruction, signatureProfileSettings);
properties.buildSignature();
PDDocument visualDoc;
synchronized (PDDocument.class) {
- visualDoc = PDDocument.load(properties
- .getVisibleSignature());
+ visualDoc = PDDocument.load(properties.getVisibleSignature());
}
// PDPageable pageable = new PDPageable(visualDoc);
List<PDPage> pages = new ArrayList<PDPage>();
@@ -805,23 +755,18 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
float targetRes = resolution;
float factor = targetRes / stdRes;
- BufferedImage outputImage = firstPage.convertToImage(
- BufferedImage.TYPE_4BYTE_ABGR, (int) targetRes);
+ BufferedImage outputImage = firstPage.convertToImage(BufferedImage.TYPE_4BYTE_ABGR, (int) targetRes);
- BufferedImage cutOut = new BufferedImage(
- (int) (position.getWidth() * factor),
- (int) (position.getHeight() * factor),
- BufferedImage.TYPE_4BYTE_ABGR);
+ BufferedImage cutOut = new BufferedImage((int) (position.getWidth() * factor),
+ (int) (position.getHeight() * factor), BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics = (Graphics2D) cutOut.getGraphics();
- graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut
- .getHeight(), (int) (1 * factor), (int) (outputImage
- .getHeight() - ((position.getHeight() + 1) * factor)),
- (int) ((1 + position.getWidth()) * factor),
- (int) (outputImage.getHeight()
- - ((position.getHeight() + 1) * factor) + (position
- .getHeight() * factor)), null);
+ graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut.getHeight(), (int) (1 * factor),
+ (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor)),
+ (int) ((1 + position.getWidth()) * factor), (int) (outputImage.getHeight()
+ - ((position.getHeight() + 1) * factor) + (position.getHeight() * factor)),
+ null);
return cutOut;
} catch (PdfAsException e) {
logger.warn("PDF-AS Exception", e);