Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions jsignpdf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,46 @@
</build>

<dependencies>
<!-- DSS (Digital Signature Service) dependencies -->
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-service</artifactId>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-pades</artifactId>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-pades-pdfbox</artifactId>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-token</artifactId>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-utils-apache-commons</artifactId>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-cms-stream</artifactId>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-validation</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<artifactId>bcpkix-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<artifactId>bcutil-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
70 changes: 27 additions & 43 deletions jsignpdf/src/main/java/net/sf/jsignpdf/PdfExtraInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
*/
package net.sf.jsignpdf;

import java.io.IOException;

import net.sf.jsignpdf.types.PageInfo;
import net.sf.jsignpdf.utils.PdfUtils;

import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfReader;
import eu.europa.esig.dss.model.DSSDocument;
import eu.europa.esig.dss.pdf.AnnotationBox;
import eu.europa.esig.dss.pdf.pdfbox.PdfBoxDocumentReader;

/**
* Provides additional information for selected input PDF file.
Expand All @@ -52,65 +55,46 @@ public PdfExtraInfo(BasicSignerOptions anOptions) {
}

/**
* Returns number of pages in PDF document. If error occures (file not found or sth. similar) -1 is returned.
* Returns number of pages in PDF document using DSS framework.
* If error occurs (file not found or similar) -1 is returned.
*
* @return number of pages (or -1 if error occures)
* @return number of pages (or -1 if error occurs)
*/
public int getNumberOfPages() {
int tmpResult = 0;
PdfReader reader = null;
try {
try {
reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes());
} catch (Exception e) {
try {
reader = new PdfReader(options.getInFile(), new byte[0]);
} catch (Exception e2) {
// try to read without password
reader = new PdfReader(options.getInFile());
}
DSSDocument document = PdfUtils.getDSSDocument(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes());

// Use DSS PdfBoxDocumentReader to get page count
try (PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document)) {
return reader.getNumberOfPages();
}
tmpResult = reader.getNumberOfPages();
} catch (Exception e) {
tmpResult = -1;
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
return -1;
}

return tmpResult;
}

/**
* Returns page info.
* Returns page info using DSS framework.
*
* @param aPage number of page for which size should be returned
* @return FloatPoint or null
* @return PageInfo or null
*/
public PageInfo getPageInfo(int aPage) {
PageInfo tmpResult = null;
PdfReader reader = null;
try {
reader = PdfUtils.getPdfReader(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes());
final Rectangle tmpRect = reader.getPageSizeWithRotation(aPage);
if (tmpRect != null) {
tmpResult = new PageInfo(tmpRect.getRight(), tmpRect.getTop());
DSSDocument document = PdfUtils.getDSSDocument(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes());

// Use DSS PdfBoxDocumentReader to get page dimensions
try (PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document)) {
AnnotationBox pageBox = reader.getPageBox(aPage);
if (pageBox != null) {
return new PageInfo((float)pageBox.getWidth(), (float)pageBox.getHeight());
}
}
} catch (Exception e) {
// nothing to do
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
}

return tmpResult;
return null;
}

}
6 changes: 4 additions & 2 deletions jsignpdf/src/main/java/net/sf/jsignpdf/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ private static void signFiles(SignerOptionsFromCmdLine anOpts) {
final SignerLogic tmpLogic = new SignerLogic(anOpts);
if (ArrayUtils.isEmpty(anOpts.getFiles())) {
// we've used -lp (loadproperties) parameter
if (!tmpLogic.signFile()) {
// Use DSS signing with legacy fallback
if (!tmpLogic.runWithResult()) {
exit(Constants.EXIT_CODE_ALL_SIG_FAILED);
}
return;
Expand Down Expand Up @@ -243,7 +244,8 @@ private static void signFiles(SignerOptionsFromCmdLine anOpts) {
tmpName.append(anOpts.getOutPrefix());
tmpName.append(tmpNameBase).append(anOpts.getOutSuffix()).append(tmpSuffix);
anOpts.setOutFile(tmpName.toString());
if (tmpLogic.signFile()) {
// Use DSS signing with legacy fallback
if (tmpLogic.runWithResult()) {
successCount++;
} else {
failedCount++;
Expand Down
Loading