diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-15 14:23:04 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-15 14:23:04 +0200 |
commit | cfbd5f9d8af638aa830aa535feadb094109e6455 (patch) | |
tree | 5d65bb93b64314f7e3f3455002b4c909242e5bc5 /pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl | |
parent | 0e31e524b419cd898139d1b8afa92cb794a3f821 (diff) | |
download | pdf-as-4-cfbd5f9d8af638aa830aa535feadb094109e6455.tar.gz pdf-as-4-cfbd5f9d8af638aa830aa535feadb094109e6455.tar.bz2 pdf-as-4-cfbd5f9d8af638aa830aa535feadb094109e6455.zip |
Rebuild API to support Java DataSource and Streams for in and output
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl')
7 files changed, 120 insertions, 113 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java index 7fe39ff7..c853f7eb 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -32,11 +32,12 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.OutputStream; +import java.io.InputStream; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import org.apache.commons.io.IOUtils; import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; @@ -57,6 +58,7 @@ import at.gv.egiz.pdfas.common.settings.Settings; import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; import at.gv.egiz.pdfas.common.utils.PDFUtils; import at.gv.egiz.pdfas.common.utils.StreamUtils; +import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource; import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; import at.gv.egiz.pdfas.lib.api.PdfAs; @@ -100,9 +102,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { logger.info("Initializing PDF-AS with config: " + cfgFile.getPath()); this.settings = new Settings(cfgFile); } - + public PdfAsImpl(ISettings cfgObject) { - logger.info("Initializing PDF-AS with config: " + cfgObject.getClass().getName()); + logger.info("Initializing PDF-AS with config: " + + cfgObject.getClass().getName()); this.settings = cfgObject; } @@ -123,14 +126,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { } } - if (parameter.getDataSource() == null - || parameter.getDataSource().getByteData() == null) { + if (parameter.getDataSource() == null) { throw new PdfAsValidationException("error.pdf.sig.10", null); } - if (parameter.getOutput() == null) { - throw new PdfAsValidationException("error.pdf.sig.11", null); - } } private void verifyVerifyParameter(VerifyParameter parameter) @@ -140,8 +139,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { throw new PdfAsSettingsException("Invalid settings object!"); } - if (parameter.getDataSource() == null - || parameter.getDataSource().getByteData() == null) { + if (parameter.getDataSource() == null) { throw new PdfAsValidationException("error.pdf.verify.01", null); } } @@ -162,8 +160,8 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { status = new OperationStatus(settings, parameter); // set Original PDF Document Data - status.getPdfObject().setOriginalDocument( - parameter.getDataSource().getByteData()); + status.getPdfObject() + .setOriginalDocument(parameter.getDataSource()); PDDocument doc = status.getPdfObject().getDocument(); PDFUtils.checkPDFPermissions(doc); @@ -227,33 +225,32 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { List<VerifyResult> result = new ArrayList<VerifyResult>(); ISettings settings = (ISettings) parameter.getConfiguration(); VerifierDispatcher verifier = new VerifierDispatcher(settings); - doc = PDDocument.load(new ByteArrayInputStream(parameter - .getDataSource().getByteData())); + doc = PDDocument.load(parameter.getDataSource().getInputStream()); COSDictionary trailer = doc.getDocument().getTrailer(); - if(trailer == null) { + if (trailer == null) { // No signatures ... return result; } COSDictionary root = (COSDictionary) trailer .getDictionaryObject(COSName.ROOT); - if(root == null) { + if (root == null) { // No signatures ... return result; } COSDictionary acroForm = (COSDictionary) root .getDictionaryObject(COSName.ACRO_FORM); - if(acroForm == null) { + if (acroForm == null) { // No signatures ... return result; } COSArray fields = (COSArray) acroForm .getDictionaryObject(COSName.FIELDS); - if(fields == null) { + if (fields == null) { // No signatures ... return result; } - + int lastSig = -1; for (int i = 0; i < fields.size(); i++) { COSDictionary field = (COSDictionary) fields.getObject(i); @@ -262,6 +259,9 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { lastSig = i; } } + + byte[] inputData = IOUtils.toByteArray(parameter.getDataSource() + .getInputStream()); for (int i = 0; i < fields.size(); i++) { COSDictionary field = (COSDictionary) fields.getObject(i); @@ -273,11 +273,11 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { // verify only specific siganture! verifyThis = signatureToVerify == currentSignature; } - - if(signatureToVerify == -2) { + + if (signatureToVerify == -2) { verifyThis = i == lastSig; } - + if (verifyThis) { logger.trace("Found Signature: "); COSBase base = field.getDictionaryObject("V"); @@ -303,13 +303,13 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { COSString content = (COSString) dict .getDictionaryObject("Contents"); - + ByteArrayOutputStream contentData = new ByteArrayOutputStream(); for (int j = 0; j < bytes.length; j = j + 2) { int offset = bytes[j]; int length = bytes[j + 1]; - contentData.write(parameter.getDataSource() - .getByteData(), offset, length); + + contentData.write(inputData, offset, length); } contentData.close(); @@ -317,13 +317,17 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { dict.getNameAsString("Filter"), dict.getNameAsString("SubFilter")); - IVerifier lvlVerifier = verifier.getVerifierByLevel(parameter.getSignatureVerificationLevel()); - lvlVerifier.setConfiguration(parameter.getConfiguration()); + IVerifier lvlVerifier = verifier + .getVerifierByLevel(parameter + .getSignatureVerificationLevel()); + lvlVerifier.setConfiguration(parameter + .getConfiguration()); if (verifyFilter != null) { List<VerifyResult> results = verifyFilter.verify( contentData.toByteArray(), content.getBytes(), - parameter.getVerificationTime(), bytes, lvlVerifier); + parameter.getVerificationTime(), bytes, + lvlVerifier); if (results != null && !results.isEmpty()) { result.addAll(results); } @@ -402,7 +406,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { // set Original PDF Document Data status.getPdfObject().setOriginalDocument( - status.getSignParamter().getDataSource().getByteData()); + status.getSignParamter().getDataSource()); // STAMPER! // stampPdf(status); @@ -452,16 +456,20 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { String signature = new COSString(request.getSignature()) .getHexString(); byte[] pdfSignature = signature.getBytes(); - //byte[] input = PDFUtils.blackOutSignature(status.getPdfObject().getSignedDocument(), - // request.getSignatureDataByteRange()); - VerifyResult verifyResult = SignatureUtils.verifySignature(request.getSignature(), request.getSignatureData()); - RequestedSignature requestedSignature = request.getStatus().getRequestedSignature(); - - if(!StreamUtils.dataCompare(requestedSignature.getCertificate().getFingerprintSHA(), - ((X509Certificate)verifyResult.getSignerCertificate()).getFingerprintSHA())) { + // byte[] input = + // PDFUtils.blackOutSignature(status.getPdfObject().getSignedDocument(), + // request.getSignatureDataByteRange()); + VerifyResult verifyResult = SignatureUtils.verifySignature( + request.getSignature(), request.getSignatureData()); + RequestedSignature requestedSignature = request.getStatus() + .getRequestedSignature(); + + if (!StreamUtils.dataCompare(requestedSignature.getCertificate() + .getFingerprintSHA(), ((X509Certificate) verifyResult + .getSignerCertificate()).getFingerprintSHA())) { throw new PdfAsSignatureException("Certificates missmatch!"); } - + for (int i = 0; i < pdfSignature.length; i++) { status.getPdfObject().getSignedDocument()[offset + i] = pdfSignature[i]; } @@ -501,14 +509,8 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { throws IOException { // ================================================================ // Create SignResult - SignResultImpl result = new SignResultImpl(status.getSignParamter() - .getOutput()); - OutputStream outputStream = result.getOutputDocument() - .createOutputStream(); - - outputStream.write(status.getPdfObject().getSignedDocument()); - - outputStream.close(); + SignResultImpl result = new SignResultImpl(new ByteArrayInputStream( + status.getPdfObject().getSignedDocument())); result.setSignerCertificate(status.getRequestedSignature() .getCertificate()); @@ -518,28 +520,28 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { return result; } - public Image generateVisibleSignaturePreview(SignParameter parameter, X509Certificate cert, int resolution) - throws PdfAsException { - + public Image generateVisibleSignaturePreview(SignParameter parameter, + X509Certificate cert, int resolution) throws PdfAsException { + OperationStatus status = null; try { // Status initialization if (!(parameter.getConfiguration() instanceof ISettings)) { throw new PdfAsSettingsException("Invalid settings object!"); } - + ISettings settings = (ISettings) parameter.getConfiguration(); status = new OperationStatus(settings, parameter); - + RequestedSignature requestedSignature = new RequestedSignature( status); requestedSignature.setCertificate(cert); - + if (!requestedSignature.isVisual()) { logger.warn("Profile is invisible so not block image is generated"); return null; } - + PDFObject pdfObject = status.getPdfObject(); PDDocument origDoc = new PDDocument(); @@ -547,42 +549,41 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { ByteArrayOutputStream baos = new ByteArrayOutputStream(); origDoc.save(baos); baos.close(); - - pdfObject.setOriginalDocument(baos.toByteArray()); + + pdfObject.setOriginalDocument(new ByteArrayDataSource(baos.toByteArray())); SignatureProfileSettings signatureProfileSettings = TableFactory .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); - + pdfObject, main); + SignatureProfileConfiguration signatureProfileConfiguration = pdfObject .getStatus().getSignatureProfileConfiguration( requestedSignature.getSignatureProfileID()); - + String signaturePosString = signatureProfileConfiguration .getDefaultPositioning(); PositioningInstruction positioningInstruction = null; - if(signaturePosString != null) { - positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "", origDoc, + if (signaturePosString != null) { + 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(); - + SignaturePositionImpl position = new SignaturePositionImpl(); position.setX(positioningInstruction.getX()); position.setY(positioningInstruction.getY()); @@ -591,44 +592,49 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { position.setWidth(visualObject.getWidth()); requestedSignature.setSignaturePosition(position); - + PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties( - pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject, - positioningInstruction); + pdfObject.getStatus().getSettings(), pdfObject, + (PdfBoxVisualObject) visualObject, positioningInstruction); properties.buildSignature(); - PDDocument visualDoc = PDDocument.load(properties.getVisibleSignature()); - //PDPageable pageable = new PDPageable(visualDoc); + PDDocument visualDoc = PDDocument.load(properties + .getVisibleSignature()); + // PDPageable pageable = new PDPageable(visualDoc); List<PDPage> pages = new ArrayList<PDPage>(); visualDoc.getDocumentCatalog().getPages().getAllKids(pages); - + PDPage firstPage = pages.get(0); - + float stdRes = 72; float targetRes = resolution; float factor = targetRes / stdRes; - - BufferedImage outputImage = firstPage.convertToImage(BufferedImage.TYPE_4BYTE_ABGR, (int)targetRes); - - BufferedImage cutOut = new BufferedImage((int)(position.getWidth() * factor), (int)(position.getHeight() * factor), + + 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); - + 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) { + } catch (PdfAsException e) { logger.error("PDF-AS Exception", e); throw e; - } catch(Throwable e) { + } catch (Throwable e) { logger.error("Throwable Exception", e); throw new PdfAsException("", e); } - + } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java index 362715a3..7a141525 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java @@ -23,8 +23,9 @@ ******************************************************************************/ package at.gv.egiz.pdfas.lib.impl; +import javax.activation.DataSource; + import at.gv.egiz.pdfas.lib.api.Configuration; -import at.gv.egiz.pdfas.lib.api.DataSource; import at.gv.egiz.pdfas.lib.api.PdfAsParameter; public class PdfAsParameterImpl implements PdfAsParameter { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java index ddf2eaef..f547b2b0 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignParameterImpl.java @@ -23,16 +23,16 @@ ******************************************************************************/ package at.gv.egiz.pdfas.lib.impl; +import javax.activation.DataSource; + import at.gv.egiz.pdfas.lib.api.Configuration; -import at.gv.egiz.pdfas.lib.api.DataSink; -import at.gv.egiz.pdfas.lib.api.DataSource; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; public class SignParameterImpl extends PdfAsParameterImpl implements SignParameter { protected String signatureProfileId = null; protected String signaturePosition = null; - protected DataSink output = null; + protected DataSource output = null; protected IPlainSigner signer = null; public SignParameterImpl(Configuration configuration, @@ -58,11 +58,11 @@ public class SignParameterImpl extends PdfAsParameterImpl implements SignParamet this.signaturePosition = signaturePosition; } - public void setOutput(DataSink output) { + public void setOutput(DataSource output) { this.output = output; } - public DataSink getOutput() { + public DataSource getOutput() { return this.output; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java index 87fb2881..1a0e6490 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java @@ -23,23 +23,23 @@ ******************************************************************************/ package at.gv.egiz.pdfas.lib.impl; +import java.io.InputStream; import java.security.cert.X509Certificate; -import at.gv.egiz.pdfas.lib.api.DataSink; import at.gv.egiz.pdfas.lib.api.SignaturePosition; import at.gv.egiz.pdfas.lib.api.sign.SignResult; public class SignResultImpl implements SignResult { - protected DataSink dataSink; + protected InputStream dataSink; protected X509Certificate certificate; protected SignaturePosition position; - public SignResultImpl(DataSink dataSink) { + public SignResultImpl(InputStream dataSink) { this.dataSink = dataSink; } - public DataSink getOutputDocument() { + public InputStream getOutputDocument() { return this.dataSink; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java index 166c17e0..ea1da9e7 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/VerifyParameterImpl.java @@ -25,8 +25,9 @@ package at.gv.egiz.pdfas.lib.impl; import java.util.Date; +import javax.activation.DataSource; + import at.gv.egiz.pdfas.lib.api.Configuration; -import at.gv.egiz.pdfas.lib.api.DataSource; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; public class VerifyParameterImpl extends PdfAsParameterImpl implements VerifyParameter { 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 6d17e919..a129f18a 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 @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import org.apache.commons.io.IOUtils; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; @@ -42,11 +43,8 @@ import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageNode; import org.apache.pdfbox.pdmodel.PDResources; -import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement; -import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot; import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent; import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; -import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureOptions; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; @@ -75,7 +73,6 @@ import at.gv.egiz.pdfas.lib.impl.stamping.TableFactory; import at.gv.egiz.pdfas.lib.impl.stamping.ValueResolver; import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureProperties; import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PdfBoxVisualObject; -import at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.tagging.PDFBoxTaggingUtils; import at.gv.egiz.pdfas.lib.impl.status.PDFObject; import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; import at.gv.egiz.pdfas.lib.util.SignatureUtils; @@ -100,7 +97,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // write to temporary file FileOutputStream fos = new FileOutputStream(new File(fisTmpFile)); - fos.write(pdfObject.getOriginalDocument()); + IOUtils.copy(pdfObject.getOriginalDocument().getInputStream(), fos); FileInputStream fis = new FileInputStream(new File(fisTmpFile)); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java index 628c87a1..f69c20a4 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/PDFObject.java @@ -23,8 +23,10 @@ ******************************************************************************/ package at.gv.egiz.pdfas.lib.impl.status; -import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.OutputStream; + +import javax.activation.DataSource; import org.apache.pdfbox.pdmodel.PDDocument; @@ -33,7 +35,7 @@ public class PDFObject { private OperationStatus status; private PDDocument doc; - private byte[] originalDocument; + private DataSource originalDocument; private byte[] signedDocument; public PDFObject(OperationStatus operationStatus) { @@ -60,16 +62,16 @@ public class PDFObject { } } - public byte[] getOriginalDocument() { + public DataSource getOriginalDocument() { return originalDocument; } - public void setOriginalDocument(byte[] originalDocument) throws IOException { + public void setOriginalDocument(DataSource originalDocument) throws IOException { this.originalDocument = originalDocument; if(doc != null) { doc.close(); } - this.doc = PDDocument.load(new ByteArrayInputStream(this.originalDocument)); + this.doc = PDDocument.load(this.originalDocument.getInputStream()); if(this.doc != null) { this.doc.getDocument().setWarnMissingClose(false); } |