Skip to content

Commit

Permalink
Merge pull request #3 from zsoltii/pullRequest71
Browse files Browse the repository at this point in the history
Rotation support for visual signature - Pull request #71
  • Loading branch information
zsoltii authored Jul 31, 2017
2 parents b045565 + 01a05e3 commit 88f6fa3
Showing 1 changed file with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.Color;
import java.awt.Font;
Expand Down Expand Up @@ -179,6 +181,82 @@ public void rotateTest() throws Exception {
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}

@Test
@Ignore("for pull request #71")
public void rotatePullRequest71Test() throws Exception {
Logger logger = LoggerFactory.getLogger(getClass());
/**
* minolta scanner normal(not rotated) pdf and rotation none.
*
* You can check the pdf rotation by this code:
* PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf"));
* System.out.println("rotation: " + inputPDF.getPage(0).getRotation());
*
* result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line
*
* comment: this is the original working
*/
PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf"));
logger.info("rotation sun.pdf: " + inputPDF.getPage(0).getRotation());

SignatureImageParameters signatureImageParameters = createSignatureImageParameters();

signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE);
DSSDocument document = sign(signablePdfs.get("minoltaScan"));
File checkPdfFile = new File("target/pdf/check_normal_none.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));

/**
* minolta scanner rotated pdf and rotation none (in pdf view the rotated and normal pdf seem equal)
* you can check the pdf rotation by this code:
* PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"));
* System.out.println("rotation: " + inputPDF.getPage(0).getRotation());
*
* result in pdf viewer: signature is top right corner and the sign image line is perpendicular with the sun eyes line
*
* comment: this is the original working
*/
inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"));
logger.info("rotation sun_90.pdf: " + inputPDF.getPage(0).getRotation());

signatureImageParameters = createSignatureImageParameters();

signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE);
document = sign(signablePdfs.get("minoltaScan90"));
checkPdfFile = new File("target/pdf/check_90_none.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));

/**
* minolta scanner rotated pdf and rotation automatic (in pdf view the rotated and normal pdf seem equal)
*
* result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line,
* it will be same as with sun.pdf (not rotated) and rotation none
*/
signatureImageParameters = createSignatureImageParameters();

signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
document = sign(signablePdfs.get("minoltaScan90"));
checkPdfFile = new File("target/pdf/check_90_automatic.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));

/**
* minolta scanner normal(not rotated) pdf and rotation none.
*
* result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line,
* it will be same as with sun.pdf (not rotated) and rotation none
*/
signatureImageParameters = createSignatureImageParameters();

signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
document = sign(signablePdfs.get("minoltaScan"));
checkPdfFile = new File("target/pdf/check_normal_automatic.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}

private DSSDocument sign(DSSDocument document) {
ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
Expand Down

0 comments on commit 88f6fa3

Please sign in to comment.