프로그래밍 방식으로 AEM Document Services 사용 using-aem-document-services-programmatically
이 문서의 샘플 및 예제를 통해 OSGi 환경의 AEM Forms에서 AEM Document Services를 이해하고 사용할 수 있습니다. JEE 환경의 AEM Forms에 대한 샘플 및 예는 를 참조하십시오.
전제 조건 prerequisite
-
DocAssurance 서비스 API를 사용하기 전에 DocAssurance 서비스를 구성합니다.
-
AEM Maven 프로젝트로 AEM Forms 클라이언트 SDK를 다운로드하고 구성합니다. AEM Document Services를 사용하여 Maven 프로젝트를 빌드하는 데 필요한 클라이언트 클래스는 AEM Forms 클라이언트 SDK에서 사용할 수 있습니다
DocAssurance 서비스 docassurance-service
DocAssurance 서비스에는 다음 서비스가 포함됩니다.
- 서명 서비스
- 암호화 서비스
- Reader 확장 서비스
DocAssurance 서비스를 사용하여 다음 작업을 수행할 수 있습니다.
보이지 않는 서명 필드 추가 adding-an-invisible-signature-field
디지털 서명은 서명의 그래픽 표현을 포함하는 양식 필드인 서명 필드에 나타납니다. 서명 필드는 표시되거나 표시되지 않을 수 있습니다. 서명자는 기존 서명 필드를 사용하거나 서명 필드를 프로그래밍 방식으로 추가할 수 있습니다. 두 경우 모두 서명 필드가 있어야 PDF 문서에 서명할 수 있습니다. 서명 서비스 Java API 또는 서명 웹 서비스 API를 사용하여 서명 필드를 프로그래밍 방식으로 추가할 수 있습니다. PDF 문서에 두 개 이상의 서명 필드를 추가할 수 있습니다. 그러나 각 서명 필드 이름은 고유해야 합니다.
구문: addInvisibleSignatureField(Document inDoc, String signatureFieldName, FieldMDPOptionSpec fieldMDPOptionsSpec, PDFSeedValueOptionSpec seedValueOptionsSpec, UnlockOptions unlockOptions)
입력 매개 변수
다음은 PDF 문서에 보이지 않는 서명 필드를 추가하는 샘플 Java 코드입니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.IOException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PositionRectangle;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
* Digital signatures appear in signature fields, which are form fields that contain a graphic representation of the signature.
* Signature fields can be visible or invisible. Signers can use a pre existing signature field, or a signature field can be
* programmatically added. In either case, the signature field must exist before a PDF document can be signed.
* You can programmatically add a signature field by using the Signature service Java API or Signature web service API.
* You can add more than one signature field to a PDF document; however, each signature field name must be unique.
*
* The following Java code example adds an invisible signature field named SignatureField1 to a PDF document.
*/
@Component
@Service(value=AddInvisibleSignatureField.class)
public class AddInvisibleSignatureField {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to an pdf document stored at disk
* @param outputFile - path where the output file has to be saved
* @throws SignaturesBaseException
* @throws DuplicateSignatureFieldException
* @throws PermissionsException
* @throws PDFOperationException
* @throws InvalidArgumentException
* @throws DocAssuranceException
*
*/
public void addInvisibleSignatureField(String inputFile, String outputFile) throws InvalidArgumentException, PDFOperationException, PermissionsException, DuplicateSignatureFieldException, SignaturesBaseException, DocAssuranceException {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
//Specify the name of the signature field
String fieldName = "SignatureField1";
//Create a PositionRectangle object that specifies
//the signature fields location
PositionRectangle post = new PositionRectangle(193,47,133,12);
//Specify the page number that will contain the signature field
java.lang.Integer pageNum = new java.lang.Integer(1);
//Add a signature field to the PDF document
try {
outDoc = docAssuranceService.addInvisibleSignatureField(
inDoc,
fieldName,
null,
null,
null);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // for an encrypted PDF input, pass unlock options
//save the outDoc
try {
outDoc.copyToFile(outFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* UnlockOptions to be passed to addSignatureField() API to add a signature field in an encrypted pdf document.
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
문서에 서명하는 데 CAdES사양을 사용할 수도 있습니다. 다음 샘플 코드를 사용하여 서명 형식을 CAdES.(으)로 설정합니다.
SigningFormat signingFormat = SigningFormat.CAdES;
sigAppearence.setSigningFormat(signingFormat);
signOptions.setSigAppearence(sigAppearence);
서명 필드 추가 adding-a-signature-field-nbsp
서명 서비스 Java API 또는 서명 웹 서비스 API를 사용하여 서명 필드를 프로그래밍 방식으로 추가할 수 있습니다. PDF 문서에 여러 서명 필드를 추가할 수 있습니다. 그러나 각 서명 필드 이름은 고유해야 합니다.
구문:
public Document addSignatureField(Document inDoc,
String signatureFieldName,
Integer pageNo,
PositionRectangle positionRectangle,
FieldMDPOptionSpec fieldMDPOptionsSpec,
PDFSeedValueOptionSpec seedValueOptionsSpec, UnlockOptions unlockOptions)
입력 매개 변수
다음은 PDF 문서에 서명 필드를 추가하는 샘플 Java 코드입니다.
/*************************************************************************
*
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file from a
*source other than Adobe, then your use, modification, or distribution of it requires the prior
*written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.IOException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PositionRectangle;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
* Digital signatures appear in signature fields, which are form fields that contain a graphic representation of the signature.
* Signature fields can be visible or invisible. Signers can use a pre existing signature field, or a signature field can be
* programmatically added. In either case, the signature field must exist before a PDF document can be signed.
* You can programmatically add a signature field by using the Signature service Java API or Signature web service API.
* You can add more than one signature field to a PDF document; however, each signature field name must be unique.
*
* The following Java code example adds a signature field named SignatureField1 to a PDF document.
*/
@Component
@Service(value=AddSignatureField.class)
public class AddSignatureField {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to an pdf document stored at disk
* @param outputFile - path where the output file has to be saved
* @throws SignaturesBaseException
* @throws DuplicateSignatureFieldException
* @throws PermissionsException
* @throws PDFOperationException
* @throws InvalidArgumentException
* @throws DocAssuranceException
*
*/
public void addSignatureField(String inputFile, String outputFile) throws InvalidArgumentException, PDFOperationException, PermissionsException, DuplicateSignatureFieldException, SignaturesBaseException, DocAssuranceException {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
//Specify the name of the signature field
String fieldName = "SignatureField1";
//Create a PositionRectangle object that specifies
//the signature fields location
PositionRectangle post = new PositionRectangle(193,47,133,12);
//Specify the page number that will contain the signature field
java.lang.Integer pageNum = new java.lang.Integer(1);
//Add a signature field to the PDF document
try {
outDoc = docAssuranceService.addSignatureField(
inDoc,
fieldName,
pageNum,
post,
null,
null,
null);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // for an encrypted PDF input, pass unlock options
//save the outDoc
try {
outDoc.copyToFile(outFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* UnlockOptions to be passed to addSignatureField() API to add a signature field in an encrypted pdf document.
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
문서 타임스탬프 적용 apply-document-timestamp
PAdES 4 사양에 따라 문서에 프로그래밍 방식으로 타임스탬프를 지정할 수 있습니다. 트랜잭션 관련 문서에 CAdES 사양을 사용할 수도 있습니다.
구문: applyDocumentTimeStamp(Document doc, VerificationTime verificationTime, ValidationPreferences dssPrefs, ResourceResolver resourceResolver, UnlockOptions unlockOptions)
입력 매개 변수
다음 코드 샘플은 PAdES 4에 따라 문서에 타임스탬프를 추가합니다.
package com.adobe.signatures.test;
import java.io.File;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.VerificationTime;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferences;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.common.RevocationCheckStyle;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.OCSPPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.TSPPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.TSPPreferencesImpl;
@Component
@Service(value=Test.class)
public class Test {
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @param outputFile - path to the pdf document where the output needs to be stored
* @throws Exception
*/
public void TimeStamp(String inputFile, String outputFile) throws Exception{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
Session adminSession = null;
ResourceResolver resourceResolver = null;
try {
/** resourceResolver with admin privileges to be passed to SignatureServiceAPI and Reader Extensions
the resource resolver for signature options has to be corresponding to the user who has the signing certificate in his granite key store
the resource resolver for signature options has to be corresponding to the user who has the credential for reader extension in his granite key store
here we are using the same resource resolver
*/
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
VerificationTime verificationTime = getVerificationTimeForPades();
ValidationPreferences dssPrefs = getValidationPreferences();
//retrieve specifications for each of the services, you may pass null if you do not want to use that service
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
outDoc = docAssuranceService.applyDocumentTimeStamp(inDoc, verificationTime, dssPrefs, resourceResolver, null);
}
finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
outDoc.copyToFile(outFile);
}
public VerificationTime getVerificationTimeForPades(){
return VerificationTime.SECURE_TIME_ELSE_CURRENT_TIME;
}
/**
* sets ValidationPreferences
*/
private static ValidationPreferences getValidationPreferences(){
ValidationPreferencesImpl prefs = new ValidationPreferencesImpl();
prefs.setPKIPreferences(getPKIPreferences());
//set the unlock options for processing an encrypted pdf document, do not set if the input doc is unprotected
return prefs;
}
/**
* sets PKIPreferences
*/
private static PKIPreferences getPKIPreferences(){
PKIPreferences pkiPref = new PKIPreferencesImpl();
pkiPref.setCRLPreferences(getCRLPreferences());
pkiPref.setPathPreferences(getPathValidationPreferences());
pkiPref.setOCSPPreferences(getOCSPPref());
pkiPref.setTSPPreferences(getTspPref());
return pkiPref;
}
/**
* sets CRL Preferences
*/
private static CRLPreferences getCRLPreferences(){
CRLPreferencesImpl crlPrefs = new CRLPreferencesImpl();
crlPrefs.setRevocationCheck(RevocationCheckStyle.BestEffort);
crlPrefs.setGoOnline(true);
return crlPrefs;
}
/**
*
* sets PathValidationPreferences
*/
private static PathValidationPreferences getPathValidationPreferences(){
PathValidationPreferencesImpl pathPref = new PathValidationPreferencesImpl();
pathPref.setDoValidation(true);
return pathPref;
}
public static TSPPreferences getTspPref(){
TSPPreferencesImpl tspPrefs=new TSPPreferencesImpl();
char pass[]=new char[9];
tspPrefs.setTspServerURL("TSPPrefs_ServerURL");
tspPrefs.setUsername("TSPPrefs_Username");
tspPrefs.setPassword(pass);
tspPrefs.setSize(10240);
return tspPrefs;
}
private static OCSPPreferencesImpl getOCSPPref(){
OCSPPreferencesImpl ocsp = new OCSPPreferencesImpl();
ocsp.setRevocationCheck(RevocationCheckStyle.BestEffort);
return ocsp;
}
}
서명 가져오는 중 getting-signature
서명하거나 인증하려는 PDF 문서에 있는 모든 서명 필드의 이름을 검색할 수 있습니다. PDF 문서의 서명 필드 이름을 잘 모르거나 이름을 확인하려면 이름을 프로그래밍 방식으로 검색하십시오. Signature 서비스에서 서명 필드의 정규화된 이름(예: form1[0].grantApplication[0].page1[0].SignatureField1[0]
)을 반환합니다.
구문: getSignature(Document doc, String signatureFieldName, UnlockOptions unlockOptions)
입력 매개 변수
다음 Java 코드 예제에서는 PDF 문서의 지정된 서명 필드에 대한 서명 정보를 검색합니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PDFSignatureField;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.client.types.PDFSignature;
/**
* You can retrieve the names of all signature fields that are in a PDF document that you want to sign or certify.
* If you are unsure of the signature field names that are in a PDF document or you want to verify the names, you can
* programmatically retrieve them. The Signature service returns the fully qualified name of the signature field, such as
* form1[0].grantApplication[0].page1[0].SignatureField1[0].
*
* The following Java code example retrieves the Signature Info for the given signature field in a PDF document.
*/
@Component
@Service(value=GetSignature.class)
public class GetSignature {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @throws SignaturesBaseException
* @throws DuplicateSignatureFieldException
* @throws PermissionsException
* @throws PDFOperationException
* @throws InvalidArgumentException
*
*/
public void GetSignature(String inputFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
//Retrieve signature data for a given signature field.
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
PDFSignature pdfSignature = docAssuranceService.getSignature(inDoc,"fieldName",null);
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
서명 필드 목록을 가져오는 중 getting-signature-field-list-nbsp
서명하거나 인증하려는 PDF 문서에 있는 모든 서명 필드의 이름을 검색할 수 있습니다. PDF 문서의 서명 필드 이름을 잘 모를 경우 프로그래밍 방식으로 검색하고 확인할 수 있습니다. Signature 서비스에서 서명 필드의 정규화된 이름(예: form1[0].grantApplication[0].page1[0].SignatureField1[0]
)을 반환합니다.
구문: public List <PDFSignatureField> getSignatureFieldList (Document inDoc, UnlockOptions unlockOptions)
입력 매개 변수
inDoc
unlockOptions
다음 Java 코드 예제에서는 PDF 문서의 서명 필드 이름을 검색합니다.
/*************************************************************************
*
*
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file from a
*source other than Adobe, then your use, modification, or distribution of it requires the prior
*written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PDFSignatureField;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
* You can retrieve the names of all signature fields that are in a PDF document that you want to sign or certify.
* If you are unsure of the signature field names that are in a PDF document or you want to verify the names, you can
* programmatically retrieve them. The Signature service returns the fully qualified name of the signature field, such as
* form1[0].grantApplication[0].page1[0].SignatureField1[0].
*
* The following Java code example retrieves the names of signature fields in a PDF document.
*/
@Component
@Service(value=GetSignatureFields.class)
public class GetSignatureFields {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @throws SignaturesBaseException
* @throws DuplicateSignatureFieldException
* @throws PermissionsException
* @throws PDFOperationException
* @throws InvalidArgumentException
*
*/
public void getSignatureFields(String inputFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
//Retrieve the name of the document's signature fields
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
List fieldNames = docAssuranceService.getSignatureFieldList(inDoc,null);
//Obtain the name of each signature field by iterating through the
//List object
Iterator iter = fieldNames.iterator();
int i = 0 ;
String fieldName="";
while (iter.hasNext()) {
PDFSignatureField signatureField = (PDFSignatureField)iter.next();
fieldName = signatureField.getName();
System.out.println("The name of the signature field is " +fieldName);
i++;
}
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
서명 필드 수정 modifying-signature-fields-nbsp
PDF 문서에 있는 서명 필드를 수정할 수 있습니다. 서명 필드를 수정하려면 해당 서명 필드 잠금 사전 값 또는 시드 값 사전 값을 조작해야 합니다.
필드 잠금 사전은 서명 필드에 서명할 때 잠기는 필드 목록을 지정합니다. 잠긴 필드는 사용자가 필드를 편집할 수 없도록 합니다. 시드 값 사전에는 서명이 적용될 때 사용되는 제한 정보가 포함되어 있습니다. 예를 들어 서명을 무효화하지 않고 발생할 수 있는 작업을 제어하는 권한을 변경할 수 있습니다.
기존 서명 필드를 수정하여 변화하는 비즈니스 요구 사항을 반영하도록 PDF 문서를 편집할 수 있습니다. 예를 들어 새 비즈니스 요구 사항을 충족하려면 문서에 서명한 후 모든 문서 필드를 잠가야 합니다.
구문: public Document modifySignatureField(Document inDoc, String signatureFieldName, PDFSignatureFieldProperties pdfSignatureFieldProperties, UnlockOptions unlockOptions)
입력 매개 변수
다음 Java 코드 샘플은 서명이 서명 필드에 적용될 때 형식의 모든 필드를 잠궈 서명 필드를 수정합니다.
/*************************************************************************
*
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file from a
*source other than Adobe, then your use, modification, or distribution of it requires the prior
*written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.FieldMDPAction;
import com.adobe.fd.signatures.client.types.FieldMDPOptionSpec;
import com.adobe.fd.signatures.client.types.MDPPermissions;
import com.adobe.fd.signatures.client.types.PDFSeedValueOptionSpec;
import com.adobe.fd.signatures.client.types.PDFSignatureFieldProperties;
import com.adobe.fd.signatures.client.types.PositionRectangle;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.MissingSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignatureFieldSignedException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesOtherException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
* You can modify signature fields that are in a PDF document by using the Java API and web service API. Modifying a signature field involves
* manipulating its signature field lock dictionary values or seed value dictionary values.
* A field lock dictionary specifies a list of fields that are locked when the signature field is signed. A locked field prevents users from making
* changes to the field. A seed value dictionary contains constraining information that is used at the time the signature is applied.
* For example, you can change permissions that control the actions that can occur without invalidating a signature.
* By modifying an existing signature field, you can change the PDF document to reflect changing business requirements. For example,
* a new business requirement may require locking all document fields after the document is signed.
* This section explains how to modify a signature field by amending both field lock dictionary and seed value dictionary values.
* Changes made to the signature field lock dictionary result in all fields in the PDF document being locked when a signature field is signed.
* Changes made to the seed value dictionary prohibit specific types of changes to the document.
*
* The following Java code example modifies a signature field named SignatureField1 by locking all fields in the form when a signature is applied to the signature field and ensuring that no changes are allowed.
* After the Signature service returns the PDF document that contains the modified signature field
*/
@Component
@Service(value=ModifySignatureField.class)
public class ModifySignatureField {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @param outFile - path where the output file has to be saved
*
*
*/
public void modifySignatureField(String inputFile, String outFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
//Specify the name of the signature field
String fieldName = "SignatureField1";
//Create a PDFSignatureFieldProperties
PDFSignatureFieldProperties fieldProperties = new PDFSignatureFieldProperties();
//Create a PDFSeedValueOptionSpec object that stores
//seed value dictionary information.
PDFSeedValueOptionSpec seedOptionsSpec = new PDFSeedValueOptionSpec();
//Disallow changes to the PDF document. Any change to the document invalidates
//the signature
seedOptionsSpec.setMdpValue(MDPPermissions.NoChanges);
//Create a FieldMDPOptionSpec object that stores
//signature field lock dictionary information.
FieldMDPOptionSpec fieldMDPOptionsSpec = new FieldMDPOptionSpec();
//Lock all fields in the PDF document
fieldMDPOptionsSpec.setAction(FieldMDPAction.ALL);
//Set dictionary information
fieldProperties.setSeedValue(seedOptionsSpec);
fieldProperties.setFieldMDP(fieldMDPOptionsSpec);
//Modify the signature field
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
Document modSignatureField = docAssuranceService.modifySignatureField(inDoc,fieldName,fieldProperties,null);
//save the modSignatureField
modSignatureField.copyToFile(new File(outFile));
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
PDF 문서 인증 certifying-pdf-documents-nbsp
PDF 문서를 인증된 서명이라는 특정 유형의 서명으로 인증하면 문서를 보호할 수 있습니다. 인증된 서명은 다음과 같은 방법으로 디지털 서명과 구별됩니다.
- PDF 문서에 적용된 첫 번째 서명이어야 합니다. 즉, 공인서명이 적용된 경우 해당 문서의 다른 서명 필드에는 서명이 없어야 한다. PDF 문서에는 하나의 인증된 서명만 허용됩니다. PDF 문서에 서명하고 인증하려면 서명하기 전에 인증하십시오. PDF 문서를 인증하면 추가 서명 필드에 디지털 서명할 수 있습니다.
- 문서의 작성자 또는 작성자는 인증된 서명을 무효화하지 않고 문서를 특정 방식으로 수정할 수 있음을 지정할 수 있다. 예를 들어 문서에서 양식 입력 또는 주석 달기를 허용할 수 있습니다. 작성자가 특정 수정이 허용되지 않는다고 지정하면 Acrobat에서 사용자가 이러한 방식으로 문서를 수정할 수 없도록 제한합니다. 이러한 수정이 이루어진 경우 인증된 서명이 유효하지 않습니다. 또한 Acrobat은 사용자가 문서를 열 때 경고를 발행합니다. 인증되지 않은 서명을 사용하면 수정할 수 없으며 일반 편집 작업으로 인해 원래 서명이 무효화되지 않습니다.
- 서명 시 문서의 내용을 모호하게 하거나 오해의 소지가 있는 특정 유형의 내용이 있는지 문서를 스캔합니다. 예를 들어 주석은 인증된 내용을 이해하는 데 중요한 페이지의 일부 텍스트를 가릴 수 있습니다. 이러한 내용에 대한 설명(법적 증명)을 제공할 수 있다.
구문:
secureDocument(Document inDoc, EncryptionOptions encryptionOptions,
SignatureOptions signatureOptions, ReaderExtensionOptions readerExtensionOptions, UnlockOptions unlockOptions)
입력 매개 변수
다음 코드 샘플은 PDF 파일을 기반으로 하는 PDF 문서를 인증합니다.
/*************************************************************************
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file from a
*source other than Adobe, then your use, modification, or distribution of it requires the prior
*written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.IOException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.docassurance.client.api.DocAssuranceServiceOperationTypes;
import com.adobe.fd.docassurance.client.api.SignatureOptions;
import com.adobe.fd.signatures.client.types.MDPPermissions;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.pdf.inputs.CredentialContext;
import com.adobe.fd.signatures.pdf.inputs.DSSPreferences;
import com.adobe.fd.signatures.pdf.inputs.DSSPreferencesImpl;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions.PDFSignatureAppearanceType;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions.TextDirection;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.pki.client.types.common.HashAlgorithm;
import com.adobe.fd.signatures.pki.client.types.common.RevocationCheckStyle;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.GeneralPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferencesImpl;
/**
* You can secure a PDF document by certifying it with a particular type of signature called a certified signature.
* A certified signature is distinguished from a digital signature in these ways:
*
* It must be the first signature applied to the PDF document; that is, at the time the certified signature is applied, any other signature fields in the document must be unsigned.
* Only one certified signature is permitted in a PDF document. If you want to sign and certify a PDF document, you must certify it before signing it.
* After you certify a PDF document, you can digitally sign additional signature fields.
*
* The author or originator of the document can specify that the document can be modified in certain ways without invalidating the certified signature. For example,
* the document may permit filling in forms or commenting. If the author specifies that a certain modification is not permitted, Acrobat restricts users from modifying the document
* in that way. If such modifications are made, such as by using another application, the certified signature is invalid and Acrobat issues a warning when a user opens the document.
* (With non-certified signatures, modifications are not prevented, and normal editing operations do not invalidate the original signature.)
*
* At the time of signing, the document is scanned for specific types of content that could make the contents of a document ambiguous or misleading. For example, an annotation could
* obscure some text on a page that is important for understanding what is being certified. An explanation (legal attestation) can be provided about such content.
* You can programmatically certify PDF documents by using the Signature service Java API or the Signature web service API. When certifying a PDF document, you must reference a security
* credential that exists in the Credential service.
*
* Note: When certifying and signing the same PDF document, if the certify signature is not trusted, a yellow triangle appears next to the first sign signature when you open the PDF document in Acrobat or Adobe Reader.
* The certifying signature must be trusted to avoid this situation.
*
* The following Java code example certifies a PDF document that is based on a PDF file.
*
* PreRequisites - Digital certificate for certifying the document has to be uploaded on AEM Key Store.
*
*/
@Component
@Service(value=Certify.class)
public class Certify {
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
*
* @param inputFile - path to the pdf document stored at JCR node
* @param outputFile - path to the pdf document where the output needs to be stored
* @throws IOException
* @throws RepositoryException
* @throws InvalidArgumentException
* @throws DocAssuranceException
*/
public void certify(String inputFile, String outputFile) throws IOException, RepositoryException, InvalidArgumentException, DocAssuranceException{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
Session adminSession = null;
ResourceResolver resourceResolver = null;
try {
/** resourceResolver to be passed to SignatureServiceAPI and Reader Extensions
the resource resolver for signature options has to be corresponding to the user who has the signing certificate in his granite key store
the resource resolver for signature options has to be corresponding to the user who has the credential for reader extension in his granite key store
here we are using the same resource resolver
*/
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
//retrieve specifications for each of the services, you may pass null if you do not want to use that service
//we are not extending the reader in this case, so passing null
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
try {
outDoc = docAssuranceService.secureDocument(inDoc, null, getCertificationOptions(resourceResolver), null,null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
outDoc.copyToFile(outFile);
}
/**
*
* @param rr resource resolver corresponding to the user with the access to signing credential for the
* given alias "allcertificatesanypolicytest11ee_new" in this case
* @return SignatureOptions
*/
private SignatureOptions getCertificationOptions(ResourceResolver rr){
//create an instance of SignatureOptions
SignatureOptions signatureOptions = SignatureOptions.getInstance();
//set the operation you want to perform - SIGN/CERTIFY
signatureOptions.setOperationType(DocAssuranceServiceOperationTypes.CERTIFY);
//signature field to certify, pass null if invisible signature field
String fieldName = "Signature1" ;
//alias of the private credential uploaded on the Key Store
String alias = "allcertificatesanypolicytest11ee_new";
//Hash Algo to be used to compute digest the PDF document
HashAlgorithm algo = HashAlgorithm.SHA256;
//Reason for signing/certifying
String reason = "Reason";
//location of the signer
String location = "Location";
//contact info of the signer
String contactInfo = "Contact Info";
//DocMDP Permissions associated with certification
MDPPermissions mdpPermissions = MDPPermissions.valueOf("FormChanges");
//Create a PDFSignatureAppearanceOptions object
//and show date information
PDFSignatureAppearenceOptions appOptions = new PDFSignatureAppearenceOptions(
PDFSignatureAppearanceType.NAME, null, 1.0d, null, true, true,
true, true, false, true, true, TextDirection.AUTO);
signatureOptions.setLockCertifyingField(true);
signatureOptions.setSignatureFieldName(fieldName);
signatureOptions.setAlgo(algo);
signatureOptions.setContactInfo(contactInfo);
signatureOptions.setLocation(location);
signatureOptions.setSigAppearence(appOptions);
signatureOptions.setReason(reason);
signatureOptions.setDssPref(getDSSPreferences(rr));
signatureOptions.setCredential(new CredentialContext(alias, rr));
signatureOptions.setMdpPermissions(mdpPermissions);
return signatureOptions;
}
private DSSPreferences getDSSPreferences(ResourceResolver rr){
//sets the DSS Preferences
DSSPreferencesImpl prefs = DSSPreferencesImpl.getInstance();
prefs.setPKIPreferences(getPKIPreferences());
GeneralPreferencesImpl gp = (GeneralPreferencesImpl) prefs.getPKIPreferences().getGeneralPreferences();
gp.setDisableCache(true);
return prefs;
}
private PKIPreferences getPKIPreferences(){
//sets the PKI Preferences
PKIPreferences pkiPref = new PKIPreferencesImpl();
pkiPref.setCRLPreferences(getCRLPreferences());
pkiPref.setPathPreferences(getPathValidationPreferences());
return pkiPref;
}
private CRLPreferences getCRLPreferences(){
//specifies the CRL Preferences
CRLPreferencesImpl crlPrefs = new CRLPreferencesImpl();
crlPrefs.setRevocationCheck(RevocationCheckStyle.CheckIfAvailable);
crlPrefs.setGoOnline(true);
return crlPrefs;
}
private PathValidationPreferences getPathValidationPreferences(){
//sets the path validation preferences
PathValidationPreferencesImpl pathPref = new PathValidationPreferencesImpl();
pathPref.setDoValidation(false);
return pathPref;
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
문서 보안 설정 securing-documents
secureDocument를 사용하면 PDF 문서를 개별적으로 또는 특정 순서에 따라 임의 조합으로 암호화, 서명/인증 및 판독기를 확장할 수 있습니다. 이 기능에 액세스하려면 해당 인수를 전달합니다. null이면, 특정 처리가 필요하지 않다고 가정될 것이다.
암호를 사용하여 PDF 문서 암호화
암호를 사용하여 PDF 문서를 암호화할 때 사용자는 암호를 지정하여 Adobe Reader 또는 Acrobat에서 PDF 문서를 열어야 합니다. 또한 다른 AEM Forms Document Services 작업에서 문서를 사용하기 전에 암호로 암호화된 PDF 문서의 잠금을 해제해야 합니다.
인증서를 사용하여 PDF 문서 암호화
인증서 기반 암호화를 사용하면 공개 키 기술을 사용하여 특정 수신자의 문서를 암호화할 수 있습니다.
다양한 수신자에게 문서에 대한 다양한 권한을 부여할 수 있습니다. 암호화의 많은 측면들은 공개 키 기술에 의해 가능해진다.
알고리즘은 다음 속성을 갖는 키라고 하는 두 개의 큰 숫자를 생성하는 데 사용됩니다.
- 하나의 키는 데이터 집합을 암호화하는 데 사용됩니다. 나중에 다른 키만 사용하여 데이터를 해독할 수 있습니다.
- 하나의 키를 다른 키와 구별하는 것은 불가능하다.
- 키 중 하나가 사용자의 개인 키 역할을 합니다. 사용자만 이 키에 액세스할 수 있습니다.
- 다른 하나의 키는 다른 사용자와 공유할 수 있는 사용자의 공개 키입니다.
공개 키 인증서에는 사용자의 공개 키와 식별 정보가 포함되어 있습니다. X.509 형식은 인증서를 저장하는 데 사용됩니다. 인증서는 일반적으로 인증서의 유효성에 대한 신뢰도를 측정하는 인증된 엔티티인 CA(인증 기관)에서 발급하고 디지털 서명합니다. 인증서에는 만료 날짜가 있으며, 그 이후에는 더 이상 유효하지 않습니다.
또한 CRL(인증서 해지 목록)은 만료일 이전에 해지된 인증서에 대한 정보를 제공합니다. CRL은 인증 기관에 의해 주기적으로 게시됩니다. 네트워크의 OCSP(온라인 인증서 상태 프로토콜)를 통해 인증서의 해지 상태를 검색할 수도 있습니다.
PDF 문서에 사용 권한 적용
Reader 확장 Java 클라이언트 API 및 웹 서비스를 사용하여 PDF 문서에 사용 권한을 적용할 수 있습니다. 사용 권한은 양식에 주석을 추가하거나 양식 필드를 채우고 양식을 저장하는 기능과 같이 Acrobat에서 기본적으로 사용할 수 있지만 Adobe Reader에서는 사용할 수 없는 기능과 관련이 있습니다. 사용 권한이 적용된 PDF 문서를 권한 사용 문서라고 합니다. Adobe Reader에서 권한이 활성화된 문서를 여는 사용자는 특정 문서에 대해 활성화된 작업을 수행할 수 있습니다.
Reader 인증서를 사용하여 PDF 문서를 확장하려면 먼저 인증서를 AEM 키 저장소에 추가해야 합니다.
PDF 문서에 디지털 서명하는 중
디지털 서명을 PDF 문서에 적용하여 보안 수준을 제공할 수 있습니다. 디지털 서명은 자필 서명과 마찬가지로 서명자가 자신을 확인하고 문서에 대해 진술할 수 있는 수단을 제공합니다.
문서에 디지털 서명을 할 때 사용하는 기술은 서명자와 수신자 모두가 서명된 내용에 대해 명확하게 이해하고 서명된 이후 문서가 변경되지 않았음을 확신할 수 있도록 도와줍니다.
PDF 문서는 공개 키 기술을 통해 서명됩니다. 서명자는 공개 키와 개인 키의 두 가지 키를 갖습니다. 개인 키는 서명 시 사용할 수 있어야 하는 사용자의 자격 증명에 저장됩니다.
공개 키는 서명을 확인하기 위해 수신자가 사용할 수 있어야 하는 사용자의 인증서에 저장됩니다. 해지된 인증서에 대한 정보는 CA(인증 기관)에서 배포한 CRL(인증서 해지 목록) 및 OCSP(온라인 인증서 상태 프로토콜) 응답에서 찾을 수 있습니다. 서명 시간은 타임스탬핑 인증 기관이라고 하는 신뢰할 수 있는 소스에서 가져올 수 있습니다.
PDF 문서 인증
PDF 문서를 인증된 서명이라는 특정 유형의 서명으로 인증하면 문서를 보호할 수 있습니다. 인증된 서명은 다음과 같은 방법으로 디지털 서명과 구별됩니다.
PDF 문서에 적용된 첫 번째 서명이어야 합니다. 즉, 인증 서명이 적용될 때에는 문서의 다른 서명 필드에 서명이 없어야 합니다.
PDF 문서에는 하나의 인증된 서명만 허용됩니다. PDF 문서에 서명하고 인증하려면 서명하기 전에 해당 문서를 인증해야 합니다.
PDF 문서를 인증하면 추가 서명 필드에 디지털 서명할 수 있습니다.
문서의 작성자 또는 작성자는 인증된 서명을 무효화하지 않고 문서를 특정 방식으로 수정할 수 있음을 지정할 수 있다.
예를 들어, 문서에서는 양식 작성 또는 댓글 달기를 허용할 수 있습니다. 작성자가 특정 수정이 허용되지 않는다고 지정하는 경우
Acrobat은 사용자가 이러한 방식으로 문서를 수정할 수 없도록 제한합니다. 다른 애플리케이션 사용과 같이 이러한 수정이 이루어진 경우, 인증된 서명이 유효하지 않으며 사용자가 문서를 열 때 Acrobat에서 경고가 표시됩니다. 인증되지 않은 서명을 사용하면 수정할 수 없으며 일반 편집 작업으로 인해 원래 서명이 무효화되지 않습니다.
서명 시 문서의 내용을 모호하게 하거나 오해의 소지가 있는 특정 유형의 내용이 있는지 문서를 스캔합니다.
예를 들어 주석은 인증된 내용을 이해하는 데 중요한 페이지의 일부 텍스트를 가릴 수 있습니다. 이러한 내용에 대한 설명(법적 증명)을 제공할 수 있다.
구문:
secureDocument(Document inDoc,
EncryptionOptions encryptionOptions,
SignatureOptions signatureOptions,
ReaderExtensionOptions readerExtensionOptions,
UnlockOptions unlockOptions)
입력 매개 변수
샘플 1: 이 샘플은 암호 암호화를 수행하는 데 사용되며, 서명 필드 및 PDF 문서 확장 Reader을 인증하는 데 사용됩니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.docassurance.client.api.DocAssuranceServiceOperationTypes;
import com.adobe.fd.docassurance.client.api.EncryptionOptions;
import com.adobe.fd.docassurance.client.api.ReaderExtensionOptions;
import com.adobe.fd.docassurance.client.api.SignatureOptions;
import com.adobe.fd.encryption.client.PasswordEncryptionCompatability;
import com.adobe.fd.encryption.client.PasswordEncryptionOption;
import com.adobe.fd.encryption.client.PasswordEncryptionOptionSpec;
import com.adobe.fd.encryption.client.PasswordEncryptionPermission;
import com.adobe.fd.readerextensions.client.ReaderExtensionsOptionSpec;
import com.adobe.fd.readerextensions.client.UsageRights;
import com.adobe.fd.signatures.client.types.MDPPermissions;
import com.adobe.fd.signatures.pdf.inputs.CredentialContext;
import com.adobe.fd.signatures.pdf.inputs.DSSPreferences;
import com.adobe.fd.signatures.pdf.inputs.DSSPreferencesImpl;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions.PDFSignatureAppearanceType;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions.TextDirection;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.pki.client.types.common.HashAlgorithm;
import com.adobe.fd.signatures.pki.client.types.common.RevocationCheckStyle;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.GeneralPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferencesImpl;
/**
*
* This class provides a sample code to use {@code DocAssuranceService} to carry out
* password encryption, certifying a signature field and reader extending the pdf document.
*
* PreRequisites - Digital certificate for signing the document has to be uploaded on Granite Key Store
* Digital certificate for reader extending the document has to be uploaded on Granite Key Store
*/
@Component
@Service(value=PassEncryptCertifyExtend.class)
public class PassEncryptCertifyExtend {
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @param outputFile - path to the pdf document where the output needs to be stored
* @throws Exception
*/
public void SecureDocument(String inputFile, String outputFile) throws Exception{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
Session adminSession = null;
ResourceResolver resourceResolver = null;
try {
/** resourceResolver with admin privileges to be passed to SignatureServiceAPI and Reader Extensions
the resource resolver for signature options has to be corresponding to the user who has the signing certificate in his granite key store
the resource resolver for signature options has to be corresponding to the user who has the credential for reader extension in his granite key store
here we are using the same resource resolver
*/
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
//retrieve specifications for each of the services, you may pass null if you do not want to use that service
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
outDoc = docAssuranceService.secureDocument(inDoc, getPassEncryptionOptions(), getCertificationOptions(resourceResolver), getReaderExtensionOptions(resourceResolver),null);
}
finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
outDoc.copyToFile(outFile);
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
/**
* @return EncryptionOptions for password encrypting the document.
*
*/
private EncryptionOptions getPassEncryptionOptions(){
//Create an instance of EncryptionOptions
EncryptionOptions encryptionOptions = EncryptionOptions.getInstance();
//Create a PasswordEncryptionOptionSpec object that stores encryption run-time values
PasswordEncryptionOptionSpec passSpec = new PasswordEncryptionOptionSpec();
//Specify the PDF document resource to encrypt
passSpec.setEncryptOption(PasswordEncryptionOption.ALL);
//Specify the permission associated with the password
//These permissions enable data to be extracted from a password
//protected PDF form
List<PasswordEncryptionPermission> encrypPermissions = new ArrayList<PasswordEncryptionPermission>();
encrypPermissions.add(PasswordEncryptionPermission.PASSWORD_EDIT_ADD);
encrypPermissions.add(PasswordEncryptionPermission.PASSWORD_EDIT_MODIFY);
passSpec.setPermissionsRequested(encrypPermissions);
//Specify the Acrobat version
passSpec.setCompatability(PasswordEncryptionCompatability.ACRO_7);
//Specify the password values
passSpec.setDocumentOpenPassword("OpenPassword");
passSpec.setPermissionPassword("PermissionPassword");
//Set the encryption type to Password Encryption
encryptionOptions.setEncryptionType(DocAssuranceServiceOperationTypes.ENCRYPT_WITH_PASSWORD);
encryptionOptions.setPasswordEncryptionOptionSpec(passSpec);
return encryptionOptions;
}
/**
*
* @param resourceResolver corresponding to the user with the access to Reader Extension credential
* for the given alias -"production" in this case
* @return
*/
private ReaderExtensionOptions getReaderExtensionOptions(ResourceResolver resourceResolver){
//Create an instance of ReaderExtensionOptions
ReaderExtensionOptions reOptions = ReaderExtensionOptions.getInstance();
//Create instance for UsageRights to be enabled in the reader
UsageRights uRights = new UsageRights();
//enabling comments in the PDF Reader
uRights.setEnabledComments(true);
//setting ReaderExtensionsOptionSpec in the reOptions
reOptions.setReOptions(new ReaderExtensionsOptionSpec(uRights, "Enable commenting in PDF"));
//alias of the credential to be used for extending the PDF Reader
reOptions.setCredentialAlias("production");
//corresponding to the user with the access to Reader Extension credential
reOptions.setResourceResolver(resourceResolver);
return reOptions;
}
/**
*
* @param rr resource resolver corresponding to the user with the access to signing credential for the
* given alias "allcertificatesanypolicytest11ee_new" in this case
* @return SignatureOptions
*/
private SignatureOptions getCertificationOptions(ResourceResolver rr){
//create an instance of SignatureOptions
SignatureOptions signatureOptions = SignatureOptions.getInstance();
//set the operation you want to perform - SIGN/CERTIFY
signatureOptions.setOperationType(DocAssuranceServiceOperationTypes.CERTIFY);
//signature field to certify, pass null if invisible signature field
String fieldName = "Signature1" ;
//alias of the private credential uploaded on the Key Store
String alias = "allcertificatesanypolicytest11ee_new";
//Hash Algo to be used to compute digest the PDF document
HashAlgorithm algo = HashAlgorithm.SHA384;
//Reason for signing/certifying
String reason = "Test Reason";
//location of the signer
String location = "Test Location";
//contact info of the signer
String contactInfo = "Test Contact";
//DocMDP Permissions associated with certification
MDPPermissions mdpPermissions = MDPPermissions.valueOf("FormChanges");
//Create a PDFSignatureAppearanceOptions object
//and show date information
PDFSignatureAppearenceOptions appOptions = new PDFSignatureAppearenceOptions(
PDFSignatureAppearanceType.NAME, null, 1.0d, null, true, true,
true, true, true, true, true, TextDirection.AUTO);
signatureOptions.setSignatureFieldName(fieldName);
signatureOptions.setAlgo(algo);
signatureOptions.setContactInfo(contactInfo);
signatureOptions.setLocation(location);
signatureOptions.setSigAppearence(appOptions);
signatureOptions.setReason(reason);
signatureOptions.setDssPref(getDSSPreferences(rr));
signatureOptions.setCredential(new CredentialContext(alias, rr));
signatureOptions.setMdpPermissions(mdpPermissions);
return signatureOptions;
}
private DSSPreferences getDSSPreferences(ResourceResolver rr){
//sets the DSS Preferences
DSSPreferencesImpl prefs = DSSPreferencesImpl.getInstance();
prefs.setPKIPreferences(getPKIPreferences());
GeneralPreferencesImpl gp = (GeneralPreferencesImpl) prefs.getPKIPreferences().getGeneralPreferences();
gp.setDisableCache(true);
return prefs;
}
private PKIPreferences getPKIPreferences(){
//sets the PKI Preferences
PKIPreferences pkiPref = new PKIPreferencesImpl();
pkiPref.setCRLPreferences(getCRLPreferences());
pkiPref.setPathPreferences(getPathValidationPreferences());
return pkiPref;
}
private CRLPreferences getCRLPreferences(){
//specifies the CRL Preferences
CRLPreferencesImpl crlPrefs = new CRLPreferencesImpl();
crlPrefs.setRevocationCheck(RevocationCheckStyle.CheckIfAvailable);
crlPrefs.setGoOnline(true);
return crlPrefs;
}
private PathValidationPreferences getPathValidationPreferences(){
//sets the path validation preferences
PathValidationPreferencesImpl pathPref = new PathValidationPreferencesImpl();
pathPref.setDoValidation(false);
return pathPref;
}
}
샘플 2: 이 샘플은 PKI 암호화, 서명 필드 서명 및 PDF 문서 확장 Reader을 수행하는 데 사용됩니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.docassurance.client.api.DocAssuranceServiceOperationTypes;
import com.adobe.fd.docassurance.client.api.EncryptionOptions;
import com.adobe.fd.docassurance.client.api.ReaderExtensionOptions;
import com.adobe.fd.docassurance.client.api.SignatureOptions;
import com.adobe.fd.encryption.client.CertificateEncryptionCompatibility;
import com.adobe.fd.encryption.client.CertificateEncryptionIdentity;
import com.adobe.fd.encryption.client.CertificateEncryptionOption;
import com.adobe.fd.encryption.client.CertificateEncryptionOptionSpec;
import com.adobe.fd.encryption.client.CertificateEncryptionPermissions;
import com.adobe.fd.encryption.client.Recipient;
import com.adobe.fd.readerextensions.client.ReaderExtensionsOptionSpec;
import com.adobe.fd.readerextensions.client.UsageRights;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.pdf.inputs.CredentialContext;
import com.adobe.fd.signatures.pdf.inputs.DSSPreferences;
import com.adobe.fd.signatures.pdf.inputs.DSSPreferencesImpl;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions.PDFSignatureAppearanceType;
import com.adobe.fd.signatures.pdf.inputs.PDFSignatureAppearenceOptions.TextDirection;
import com.adobe.fd.signatures.pki.client.types.common.HashAlgorithm;
import com.adobe.fd.signatures.pki.client.types.common.RevocationCheckStyle;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.GeneralPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferencesImpl;
/**
*
* This class provides a sample code to use {@code DocAssuranceService} to carry out
* certificate encryption, signing a signature field and reader extending the pdf document.
*
* PreRequisites - Digital certificate for encrypting the document has to be uploaded on Granite Trust Store
Digital certificate for signing the document has to be uploaded on Granite Key Store
* Digital certificate for reader extending the document has to be uploaded on Granite Key Store
*/
@Component
@Service(value=PassEncryptSignExtend.class)
public class PassEncryptSignExtend {
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @param outputFile - path to the pdf document where the output needs to be stored
* @throws Exception
*/
public void CertEncryptSignReaderExtend(String inputFile, String outputFile) throws Exception{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
Session adminSession = null;
ResourceResolver resourceResolver = null;
try {
/** resourceResolver with admin privileges to be passed to SignatureServiceAPI and Reader Extensions
the resource resolver for signature options has to be corresponding to the user who has the signing certificate in his granite key store
the resource resolver for signature options has to be corresponding to the user who has the credential for reader extension in his granite key store
here we are using the same resource resolver
*/
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
//retrieve specifications for each of the services, you may pass null if you do not want to use that service
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
outDoc = docAssuranceService.secureDocument(inDoc, getCertEncryptionOptions(), getSignatureOptions(resourceResolver), getReaderExtensionOptions(resourceResolver),null);
}
finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
outDoc.copyToFile(outFile);
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
/**
* @return EncryptionOptions for password encrypting the document.
*
*/
private EncryptionOptions getCertEncryptionOptions(){
//Create an instance of EncryptionOptions
EncryptionOptions encryptionOptions = EncryptionOptions.getInstance();
//Set the encryption type to Certificate Encryption
encryptionOptions.setEncryptionType(DocAssuranceServiceOperationTypes.ENCRYPT_WITH_CERTIFCATE);
//Set the List that stores PKI information
List<CertificateEncryptionIdentity> pkiIdentities = new ArrayList<CertificateEncryptionIdentity>();
//Set the Permission List
List<CertificateEncryptionPermissions> permList = new ArrayList<CertificateEncryptionPermissions>();
permList.add(CertificateEncryptionPermissions.PKI_ALL_PERM) ;
//Create a Recipient object to store certificate information
Recipient recipient = new Recipient();
//Specify the alias of the public certificate present in the trust store that is used to encrypt the document
recipient.setX509Cert("alias");
/*
* An alternative to add a certificate is by providing the alias
* of the certificate stored in AEM trust store.
* recipient.setAlias(alias);
*/
//Create an EncryptionIdentity object
CertificateEncryptionIdentity encryptionId = new CertificateEncryptionIdentity();
encryptionId.setPerms(permList);
encryptionId.setRecipient(recipient);
//Add the EncryptionIdentity to the list
pkiIdentities.add(encryptionId);
//Set encryption run-time options
CertificateEncryptionOptionSpec certOptionsSpec = new CertificateEncryptionOptionSpec();
certOptionsSpec.setOption(CertificateEncryptionOption.ALL);
certOptionsSpec.setCompat(CertificateEncryptionCompatibility.ACRO_9);
//Set the certificate encryption option
encryptionOptions.setCertOptionSpec(certOptionsSpec)
//Set the PKI Identities in encryption Options
encryptionOptions.setPkiIdentities(pkiIdentities);
return encryptionOptions;
}
/**
*
* @param resourceResolver corresponding to the user with the access to Reader Extension credential
* for the given alias -"production" in this case
* @return
*/
private ReaderExtensionOptions getReaderExtensionOptions(ResourceResolver resourceResolver){
//Create an instance of ReaderExtensionOptions
ReaderExtensionOptions reOptions = ReaderExtensionOptions.getInstance();
//Create instance for UsageRights to be enabled in the reader
UsageRights uRights = new UsageRights();
//enabling comments in the PDF Reader
uRights.setEnabledComments(true);
//setting ReaderExtensionsOptionSpec in the reOptions
reOptions.setReOptions(new ReaderExtensionsOptionSpec(uRights, "Enable commenting in PDF"));
//alias of the credential to be used for extending the PDF Reader
reOptions.setCredentialAlias("production");
//corresponding to the user with the access to Reader Extension credential
reOptions.setResourceResolver(resourceResolver);
return reOptions;
}
/**
*
* @param rr resource resolver corresponding to the user with the access to signing credential for the
* given alias "allcertificatesanypolicytest11ee_new" in this case
* @return SignatureOptions
*/
private SignatureOptions getSignatureOptions(ResourceResolver rr){
//create an instance of SignatureOptions
SignatureOptions signatureOptions = SignatureOptions.getInstance();
//set the operation you want to perform - SIGN/CERTIFY
signatureOptions.setOperationType(DocAssuranceServiceOperationTypes.SIGN);
//field to sign
String fieldName = "Signature1" ;
//alias of the private credential uploaded on the Key Store
String alias = "allcertificatesanypolicytest11ee_new";
//Hash Algo to be used to compute digest the PDF document
HashAlgorithm algo = HashAlgorithm.SHA384;
//Reason for signing/certifying
String reason = "Test Reason";
//location of the signer
String location = "Test Location";
//contact info of the signer
String contactInfo = "Test Contact";
//Create a PDFSignatureAppearanceOptions object
//and show date information
PDFSignatureAppearenceOptions appOptions = new PDFSignatureAppearenceOptions(
PDFSignatureAppearanceType.NAME, null, 1.0d, null, true, true,
true, true, true, true, true, TextDirection.AUTO);
signatureOptions.setSignatureFieldName(fieldName);
signatureOptions.setAlgo(algo);
signatureOptions.setContactInfo(contactInfo);
signatureOptions.setLocation(location);
signatureOptions.setSigAppearence(appOptions);
signatureOptions.setReason(reason);
signatureOptions.setDssPref(getDSSPreferences(rr));
signatureOptions.setCredential(new CredentialContext(alias, rr));
return signatureOptions;
}
private DSSPreferences getDSSPreferences(ResourceResolver rr){
//sets the DSS Preferences
DSSPreferencesImpl prefs = DSSPreferencesImpl.getInstance();
prefs.setPKIPreferences(getPKIPreferences());
GeneralPreferencesImpl gp = (GeneralPreferencesImpl) prefs.getPKIPreferences().getGeneralPreferences();
gp.setDisableCache(true);
return prefs;
}
private PKIPreferences getPKIPreferences(){
//sets the PKI Preferences
PKIPreferences pkiPref = new PKIPreferencesImpl();
pkiPref.setCRLPreferences(getCRLPreferences());
pkiPref.setPathPreferences(getPathValidationPreferences());
return pkiPref;
}
private CRLPreferences getCRLPreferences(){
//specifies the CRL Preferences
CRLPreferencesImpl crlPrefs = new CRLPreferencesImpl();
crlPrefs.setRevocationCheck(RevocationCheckStyle.CheckIfAvailable);
crlPrefs.setGoOnline(true);
return crlPrefs;
}
private PathValidationPreferences getPathValidationPreferences(){
//sets the path validation preferences
PathValidationPreferencesImpl pathPref = new PathValidationPreferencesImpl();
pathPref.setDoValidation(false);
return pathPref;
}
}
판독기가 PDF 문서를 확장하는 동안 다음 오류 메시지가 표시되는 경우:
org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.ThreadDeath: null at com.adobe.internal.pdftoolkit.services.javascript.GibsonContextFactory.observeInstructionCount(GibsonContextFactory.java:138)
이는 Reader 확장 서비스가 정의된 시간 제한 간격 내에 문서에 사용된 JavaScript를 실행할 수 없음을 의미합니다.
다음을 사용하여 PDF 문서에서 JavaScript에 대해 정의된 시간 제한 간격을 관리합니다.
ReaderExtensionsOptionSpec optionSpec = new ReaderExtensionsOptionSpec(usageRights, message);
optionSpec.setJsScriptExecutionTimeoutInterval(100);
여기서 100은 JavaScript 실행에 정의된 시간 제한 간격(초)을 나타냅니다. 시간 제한 간격에 적절한 값을 설정합니다.
자격 증명 사용 권한을 가져오는 중 getting-credential-usage-rights
지정된 credentialAlias
에 의해 지정된 자격 증명의 사용 권한 정보를 가져오려면 SecureDocument
API 내에서 이 API를 호출하십시오.
구문: getCredentialUsageRights(String credentialAlias, ResourceResolver resourceResolver)
입력 매개 변수
다음 샘플은 지정된 자격 증명에 대한 사용 권한 정보를 가져옵니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.fd.readerextensions.samples;
import java.io.File;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.docassurance.client.api.ReaderExtensionOptions;
import com.adobe.fd.readerextensions.client.GetUsageRightsResult;
import com.adobe.fd.readerextensions.client.ReaderExtensionsOptionSpec;
import com.adobe.fd.readerextensions.client.UsageRights;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
*
*/
@Component(metatype = true, immediate = true, label = "ReaderExtensionsSampleService")
@Service(value = ReaderExtensionsSampleService.class)
public class ReaderExtensionsSampleService {
@Reference(referenceInterface=DocAssuranceService.class)
private DocAssuranceService docAssuranceService;
@Reference(referenceInterface=ResourceResolverFactory.class)
private ResourceResolverFactory resourceResolverFactory;
public void getCredentialUsageRights() {
try {
GetUsageRightsResult usageRightsResult = docAssuranceService.getCredentialUsageRights("production",
resourceResolverFactory.getAdministrativeResourceResolver(null));
System.out.println("Credential usage Rights are as follows");
System.out.println(usageRightsResult.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
문서 사용 권한을 가져오는 중 getting-document-usage-rights
특정 문서에 대한 사용 권한 정보를 가져오려면 docAssuranceService
API 내에서 이 API를 호출하십시오.
구문: getDocumentUsageRights(Document inDocument, UnlockOptions unlockOptions)
입력 매개 변수
다음 샘플 코드는 문서에 대한 사용 권한 정보를 반환합니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.fd.readerextensions.samples;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.SimpleCredentials;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.docassurance.client.api.ReaderExtensionOptions;
import com.adobe.fd.readerextensions.client.GetUsageRightsResult;
import com.adobe.fd.readerextensions.client.ReaderExtensionsOptionSpec;
import com.adobe.fd.readerextensions.client.UsageRights;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
@Component(metatype = true, immediate = true, label = "ReaderExtensionsSampleService")
@Service(value = ReaderExtensionsSampleService.class)
public class ReaderExtensionsSampleService {
@Reference(referenceInterface=DocAssuranceService.class)
private DocAssuranceService docAssuranceService;
@Reference(referenceInterface=ResourceResolverFactory.class)
private ResourceResolverFactory resourceResolverFactory;
public void getDocumentUsageRights() {
Document inputDocument = null;
try {
//Name of the input file on which usage rights is to be applied.
String inputFileName = "C:/RETest/input/GetUsageRightsInfo/02_fromAcrobat7.0.8_Acro700_UB8_BS_signed_commenting.pdf";
//Document to be input to Doc Assurance Service
inputDocument = new Document(new File(inputFileName));
//Unlock options to unlock the document if some kind of security is set on it.
//Currently set to null because input document has no security.
UnlockOptions unlockOptions = null;
GetUsageRightsResult usageRightsResult = docAssuranceService.getDocumentUsageRights(inputDocument, unlockOptions);
System.out.println("Document usage Rights are as follows");
System.out.println(usageRightsResult.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
// if (inputDocument != null) {
// inputDocument.dispose(); //dispose off the document.
// }
}
}
/**
* Resource resolver of the user in whose keystore Reader Extensions Certificate is installed.
* @param resourceResolverFactory
* @return
* @throws LoginException
*/
public ResourceResolver getResourceResolver() throws LoginException{
Map<String,Object> authInfo = new HashMap<String,Object>();
//Username and password of the user in whose keystore Reader Extensions Certificate is installed
SimpleCredentials credentials = new SimpleCredentials("username"/*UserName*/, "password"/*Password*/.toCharArray());
authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_CREDENTIALS,credentials);
return resourceResolverFactory.getResourceResolver(authInfo);
}
}
사용 권한 제거 removing-usage-rights
docAssuranceService
API 내에서 removeUsageRights
API를 호출하여 문서에 대한 사용 권한을 제거할 수 있습니다.
입력 매개 변수
다음 샘플은 주어진 문서에 대한 사용 권한을 제거합니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.fd.readerextensions.samples;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.SimpleCredentials;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.docassurance.client.api.ReaderExtensionOptions;
import com.adobe.fd.readerextensions.client.GetUsageRightsResult;
import com.adobe.fd.readerextensions.client.ReaderExtensionsOptionSpec;
import com.adobe.fd.readerextensions.client.UsageRights;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
@Component(metatype = true, immediate = true, label = "ReaderExtensionsSampleService")
@Service(value = ReaderExtensionsSampleService.class)
public class ReaderExtensionsSampleService {
@Reference(referenceInterface=DocAssuranceService.class)
private DocAssuranceService docAssuranceService;
@Reference(referenceInterface=ResourceResolverFactory.class)
private ResourceResolverFactory resourceResolverFactory;
public void removeDocumentUsageRights() {
Document inputDocument = null;
Document outDocument = null;
try {
//Name of the input file on which usage rights is to be applied.
String inputFileName = "C:/RETest/input/RemoveUsageRights/01_Ubiquitized_50-267_PDF1.5_UB2_Rights.pdf";
//Name of the output file where result will be saved.
String outputFileName = "C:/RETest/output/samples/removeUsageRightsOutput.pdf";
//Document to be input to Doc Assurance Service
inputDocument = new Document(new File(inputFileName));
//Unlock options to unlock the document if some kind of security is set on it.
//Currently set to null because input document has no security.
UnlockOptions unlockOptions = null;
//Specify null encryption options and signatures options.
//If requirement is also to encrypt and sign the document then, corresponding options can also be specified.
outDocument = docAssuranceService.removeUsageRights(inputDocument, unlockOptions);
File outputdir = new File("C:/RETest/output/samples");
outputdir.mkdirs();
outDocument.copyToFile(new File(outputFileName));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Resource resolver of the user in whose keystore Reader Extensions Certificate is installed.
* @param resourceResolverFactory
* @return
* @throws LoginException
*/
public ResourceResolver getResourceResolver() throws LoginException{
Map<String,Object> authInfo = new HashMap<String,Object>();
//Username and password of the user in whose keystore Reader Extensions Certificate is installed
SimpleCredentials credentials = new SimpleCredentials("username"/*UserName*/, "password"/*Password*/.toCharArray());
authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_CREDENTIALS,credentials);
return resourceResolverFactory.getResourceResolver(authInfo);
}
}
디지털 서명 확인 verifying-digital-signatures
서명된 PDF 문서가 수정되지 않았고 디지털 서명이 유효한지 확인하기 위해 디지털 서명을 확인할 수 있습니다. 디지털 서명을 확인할 때 서명의 상태와 서명자의 신원과 같은 서명의 속성을 확인할 수 있습니다. 디지털 서명을 신뢰하기 전에 확인하는 것이 좋습니다. 디지털 서명을 확인할 때 디지털 서명이 포함된 PDF 문서를 참조합니다.
구문: verify( inDoc, signatureFieldName, revocationCheckStyle, verificationTime, dssPrefs, ResourceResolver resourceResolver)
입력 매개 변수
이 샘플 코드는 DocAssuranceService
을(를) 사용하여 암호화된 PDF 문서의 서명 필드를 확인합니다.
/*************************************************************************
*
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file from a
*source other than Adobe, then your use, modification, or distribution of it requires the prior
*written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.IOException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.IdentityInformation;
import com.adobe.fd.signatures.client.types.IdentityStatus;
import com.adobe.fd.signatures.client.types.PDFSignatureType;
import com.adobe.fd.signatures.client.types.PDFSignatureVerificationInfo;
import com.adobe.fd.signatures.client.types.SignatureProperties;
import com.adobe.fd.signatures.client.types.SignatureStatus;
import com.adobe.fd.signatures.client.types.SignatureType;
import com.adobe.fd.signatures.client.types.VerificationTime;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferences;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.common.RevocationCheckStyle;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.OCSPPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.TSPPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.TSPPreferencesImpl;
/**
*
* This class provides a sample code to use {@code DocAssuranceService} to carry out
* verification of a signature field in an already Encrypted PDF Document
*
* Digital signatures can be verified to ensure that a signed PDF document was not modified and that the digital signature is valid.
* When verifying a digital signature, you can check the signature's status and the signature's properties, such as the signer's identity.
* Before trusting a digital signature, it is recommended that you verify it. When verifying a digital signature, reference a PDF document
* that contains a digital signature.
*
* For unprotected document, you are not required to set UnlockOptions in ValidationPreferences
* PreRequisites - The certificate chain upto the Root Certificate should be uploaded on CQ trust Store
*/
@Component
@Service(value=VerifyFieldEncryptedPDF.class)
public class VerifyFieldEncryptedPDF {
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
*
* @param inputFile - path to an encrypted pdf document stored at JCR node
* @throws IOException
* @throws RepositoryException
* @throws InvalidArgumentException
* @throws DocAssuranceException
*/
public void verifyFieldEncryptedPDF(String inputFile,String fieldName) throws IOException, RepositoryException, InvalidArgumentException, DocAssuranceException{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
Session adminSession = null;
ResourceResolver resourceResolver = null;
try {
//the resource resolver has to be corresponding to the user who has access to CQ Trust Store
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
//Specify the name of the signature field
RevocationCheckStyle revocationCheckStyle = RevocationCheckStyle.AlwaysCheck;
VerificationTime verificationTime = VerificationTime.CURRENT_TIME;
ValidationPreferences dssPrefs = getValidationPreferences();
//Verify the digital signature
PDFSignatureVerificationInfo signInfo = docAssuranceService.verify(
inDoc,
fieldName,
revocationCheckStyle,
verificationTime,
dssPrefs,
resourceResolver);
//Get the Signature Status
SignatureStatus sigStatus = signInfo.getStatus();
String myStatus="";
//Determine the status of the signature
if (sigStatus == SignatureStatus.DynamicFormSignatureUnknown)
myStatus = "The signatures in the dynamic PDF form are unknown";
else if (sigStatus == SignatureStatus.DocumentSignatureUnknown)
myStatus = "The signatures in the PDF document are unknown";
else if (sigStatus == SignatureStatus.CertifiedDynamicFormSignatureTamper)
myStatus = "The signatures in a certified PDF form are valid";
else if (sigStatus == SignatureStatus.SignedDynamicFormSignatureTamper)
myStatus = "The signatures in a signed dynamic PDF form are valid";
else if (sigStatus == SignatureStatus.CertifiedDocumentSignatureTamper)
myStatus = "The signatures in a certified PDF document are valid";
else if (sigStatus == SignatureStatus.SignedDocumentSignatureTamper)
myStatus = "The signatures in a signed PDF document are valid";
else if (sigStatus == SignatureStatus.SignatureFormatError)
myStatus = "The format of a signature in a signed document is invalid";
else if (sigStatus == SignatureStatus.DynamicFormSigNoChanges)
myStatus = "No changes were made to the signed dynamic PDF form";
else if (sigStatus == SignatureStatus.DocumentSigNoChanges)
myStatus = "No changes were made to the signed PDF document";
else if (sigStatus == SignatureStatus.DynamicFormCertificationSigNoChanges)
myStatus = "No changes were made to the certified dynamic PDF form";
else if (sigStatus == SignatureStatus.DocumentCertificationSigNoChanges)
myStatus = "No changes were made to the certified PDF document";
else if (sigStatus == SignatureStatus.DocSigWithChanges)
myStatus = "There were changes to a signed PDF document";
else if (sigStatus == SignatureStatus.CertificationSigWithChanges)
myStatus = "There were changes made to the PDF document.";
//Get the signature type
SignatureType sigType = signInfo.getSignatureType();
String myType = "";
if (sigType.getType() == PDFSignatureType.AUTHORSIG)
myType="Certification";
else if(sigType.getType() == PDFSignatureType.RECIPIENTSIG)
myType="Recipient";
//Get the identity of the signer
IdentityInformation signerId = signInfo.getSigner();
String signerMsg = "";
if (signerId.getStatus() == IdentityStatus.UNKNOWN)
signerMsg = "Identity Unknown";
else if (signerId.getStatus() == IdentityStatus.TRUSTED)
signerMsg = "Identity Trusted";
else if (signerId.getStatus() == IdentityStatus.NOTTRUSTED)
signerMsg = "Identity Not Trusted";
//Get the Signature properties returned by the Signature service
SignatureProperties sigProps = signInfo.getSignatureProps();
String signerName = sigProps.getSignerName();
System.out.println("The status of the signature is: "+myStatus +". The signer identity is "+signerMsg +". The signature type is "+myType +". The name of the signer is "+signerName+".");
}
catch (Exception ee)
{
ee.printStackTrace();
}
finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
}
/**
* sets ValidationPreferences
*/
private static ValidationPreferences getValidationPreferences(){
ValidationPreferencesImpl prefs = new ValidationPreferencesImpl();
prefs.setPKIPreferences(getPKIPreferences());
//set the unlock options for processing an encrypted pdf document, do not set if the input doc is unprotected
prefs.setUnlockOptions(getUnlockOptions());
return prefs;
}
/**
* sets PKIPreferences
*/
private static PKIPreferences getPKIPreferences(){
PKIPreferences pkiPref = new PKIPreferencesImpl();
pkiPref.setCRLPreferences(getCRLPreferences());
pkiPref.setPathPreferences(getPathValidationPreferences());
pkiPref.setOCSPPreferences(getOCSPPref());
pkiPref.setTSPPreferences(getTspPref());
return pkiPref;
}
private static TSPPreferences getTspPref(){
TSPPreferencesImpl tsp = new TSPPreferencesImpl();
tsp.setRevocationCheck(RevocationCheckStyle.BestEffort);
return tsp;
}
private static OCSPPreferencesImpl getOCSPPref(){
OCSPPreferencesImpl ocsp = new OCSPPreferencesImpl();
ocsp.setRevocationCheck(RevocationCheckStyle.BestEffort);
return ocsp;
}
/**
* sets CRL Preferences
*/
private static CRLPreferences getCRLPreferences(){
CRLPreferencesImpl crlPrefs = new CRLPreferencesImpl();
crlPrefs.setRevocationCheck(RevocationCheckStyle.BestEffort);
crlPrefs.setGoOnline(true);
return crlPrefs;
}
/**
*
* sets PathValidationPreferences
*/
private static PathValidationPreferences getPathValidationPreferences(){
PathValidationPreferencesImpl pathPref = new PathValidationPreferencesImpl();
pathPref.setDoValidation(true);
return pathPref;
}
/**
* sets Unlock Options for encrypted PDF
*/
private static UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
여러 디지털 서명 확인 verifying-multiple-digital-signatures
AEM을 사용하면 PDF 문서에서 디지털 서명을 확인할 수 있습니다. PDF 문서에 여러 서명자의 서명이 필요한 비즈니스 프로세스가 적용되는 경우 여러 디지털 서명이 포함될 수 있습니다. 예를 들어, 금융거래는 대출 담당자와 관리자 모두의 서명을 필요로 한다. 서명 서비스 API를 사용하여 PDF 문서 내의 모든 서명을 확인할 수 있습니다. 여러 디지털 서명을 검증할 때 각 서명의 상태와 속성을 확인할 수 있습니다. 디지털 서명을 신뢰하기 전에 Adobe에서 확인하는 것이 좋습니다.
구문: verifyDocument(Document doc, RevocationCheckStyle revocationCheckStyle, VerificationTime verificationTime, ValidationPreferences prefStore, ResourceResolver resourceResolver)
입력 매개 변수
다음 샘플 코드는 DocAssuranceService를 사용하여 이미 암호화된 PDF 문서의 서명 필드를 확인합니다.
/*************************************************************************
*
*
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file from a
*source other than Adobe, then your use, modification, or distribution of it requires the prior
*written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PDFDocumentVerificationInfo;
import com.adobe.fd.signatures.client.types.PDFSignatureType;
import com.adobe.fd.signatures.client.types.PDFSignatureVerificationInfo;
import com.adobe.fd.signatures.client.types.SignatureProperties;
import com.adobe.fd.signatures.client.types.SignatureStatus;
import com.adobe.fd.signatures.client.types.SignatureType;
import com.adobe.fd.signatures.client.types.VerificationTime;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferences;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.common.RevocationCheckStyle;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.CRLPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PKIPreferencesImpl;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferences;
import com.adobe.fd.signatures.pki.client.types.prefs.PathValidationPreferencesImpl;
/**
*
* This class provides a sample code to use {@code DocAssuranceService} to carry out
* verification of all the signature fields in an already Encrypted PDF Document
*
* Assume that a PDF document contains multiple digital signatures as a result of a business process that requires signatures from multiple
* signers. For example, consider a financial transaction that requires both a loan officer's and a manager's signature. You can use the
* Signature service Java API or web service API to verify all signatures within the PDF document. When verifying multiple digital signatures,
* you can check the status and properties of each signature. Before you trust a digital signature, it is recommended that you verify it. It
* is recommended that you are familiar with verifying a single digital signature.
*
* For unprotected document, you are not required to set UnlockOptions in ValidationPreferences
* PreRequisites - The certificate chain upto the Root Certificate should be uploaded on CQ trust Store
*/
@Component
@Service(value=VerifyEncryptedPDFDoc.class)
public class VerifyEncryptedPDFDoc {
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
*
* @param inputFile - path to an encrypted pdf document stored at JCR node
* @throws IOException
* @throws RepositoryException
* @throws InvalidArgumentException
* @throws DocAssuranceException
*/
public void verifyEncryptedPDFDoc(String inputFile) throws IOException, RepositoryException, InvalidArgumentException, DocAssuranceException{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
Session adminSession = null;
ResourceResolver resourceResolver = null;
try {
//the resource resolver has to be corresponding to the user who has access to CQ Trust Store
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
RevocationCheckStyle revocationCheckStyle = RevocationCheckStyle.CheckIfAvailable;
VerificationTime verificationTime = VerificationTime.CURRENT_TIME;
ValidationPreferences dssPrefs = getValidationPreferences();
//Verify the digital signature
PDFDocumentVerificationInfo docInfo = docAssuranceService.verifyDocument(
inDoc,
revocationCheckStyle,
verificationTime,
dssPrefs,
resourceResolver);
//Get a list of all signatures that are in the PDF document
List allSignatures = docInfo.getVerificationInfos();
//Create an Iterator object and iterate through
//the List object
Iterator<PDFSignatureVerificationInfo> iter = allSignatures.iterator();
while (iter.hasNext()) {
PDFSignatureVerificationInfo signInfo = (PDFSignatureVerificationInfo)iter.next();
//Get the Signature Status
SignatureStatus sigStatus = signInfo.getStatus();
String myStatus="";
//Determine the status of the signature
if (sigStatus == SignatureStatus.DynamicFormSignatureUnknown)
myStatus = "The signatures in the dynamic PDF form are unknown";
else if (sigStatus == SignatureStatus.DocumentSignatureUnknown)
myStatus = "The signatures in the PDF document are unknown";
else if (sigStatus == SignatureStatus.CertifiedDynamicFormSignatureTamper)
myStatus = "The signatures in a certified PDF form are valid";
else if (sigStatus == SignatureStatus.SignedDynamicFormSignatureTamper)
myStatus = "The signatures in a signed dynamic PDF form are valid";
else if (sigStatus == SignatureStatus.CertifiedDocumentSignatureTamper)
myStatus = "The signatures in a certified PDF document are valid";
else if (sigStatus == SignatureStatus.SignedDocumentSignatureTamper)
myStatus = "The signatures in a signed PDF document are valid";
else if (sigStatus == SignatureStatus.SignatureFormatError)
myStatus = "The format of a signature in a signed document is invalid";
else if (sigStatus == SignatureStatus.DynamicFormSigNoChanges)
myStatus = "No changes were made to the signed dynamic PDF form";
else if (sigStatus == SignatureStatus.DocumentSigNoChanges)
myStatus = "No changes were made to the signed PDF document";
else if (sigStatus == SignatureStatus.DynamicFormCertificationSigNoChanges)
myStatus = "No changes were made to the certified dynamic PDF form";
else if (sigStatus == SignatureStatus.DocumentCertificationSigNoChanges)
myStatus = "No changes were made to the certified PDF document";
else if (sigStatus == SignatureStatus.DocSigWithChanges)
myStatus = "There were changes to a signed PDF document";
else if (sigStatus == SignatureStatus.CertificationSigWithChanges)
myStatus = "There were changes made to the PDF document.";
//Get the signature type
SignatureType sigType = signInfo.getSignatureType();
String myType = "";
if (sigType.getType() == PDFSignatureType.AUTHORSIG)
myType="Certification";
else if(sigType.getType() == PDFSignatureType.RECIPIENTSIG)
myType="Recipient";
//Get the Signature properties returned by the Signature service
SignatureProperties sigProps = signInfo.getSignatureProps();
String signerName = sigProps.getSignerName();
System.out.println("The status of the signature is: "+myStatus +". The signature type is "+myType +". The name of the signer is "+signerName+".");
}
}
catch (Exception ee)
{
ee.printStackTrace();
}
finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
}
/**
* sets ValidationPreferences
*/
private static ValidationPreferences getValidationPreferences(){
ValidationPreferencesImpl prefs = new ValidationPreferencesImpl();
prefs.setPKIPreferences(getPKIPreferences());
//set the unlock options for processing an encrypted pdf document, do not set if the document is unprotected
prefs.setUnlockOptions(getUnlockOptions());
return prefs;
}
/**
* sets PKIPreferences
*/
private static PKIPreferences getPKIPreferences(){
PKIPreferences pkiPref = new PKIPreferencesImpl();
pkiPref.setCRLPreferences(getCRLPreferences());
pkiPref.setPathPreferences(getPathValidationPreferences());
return pkiPref;
}
/**
* sets CRL Preferences
*/
private static CRLPreferences getCRLPreferences(){
CRLPreferencesImpl crlPrefs = new CRLPreferencesImpl();
crlPrefs.setRevocationCheck(RevocationCheckStyle.CheckIfAvailable);
crlPrefs.setGoOnline(true);
return crlPrefs;
}
/**
*
* sets PathValidationPreferences
*/
private static PathValidationPreferences getPathValidationPreferences(){
PathValidationPreferencesImpl pathPref = new PathValidationPreferencesImpl();
pathPref.setDoValidation(false);
return pathPref;
}
/**
* sets Unlock Options for encrypted PDF
*/
private static UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
디지털 서명 제거 removing-digital-signatures
이전 디지털 서명을 제거한 후에만 서명 필드에 새 디지털 서명을 적용할 수 있습니다. 디지털 서명은 덮어쓸 수 없습니다. 서명이 이미 있는 서명 필드에 디지털 서명을 적용하려고 하면 예외가 발생합니다.
구문: clearSignatureField(Document inDoc, String signatureFieldName, UnlockOptions unlockOptions)
입력 매개 변수
다음 Java 코드 샘플은 서명 필드에서 디지털 서명을 제거합니다.
/*************************************************************************
*
*
-------------------------------------------------------------
*ADOBE SYSTEMS INCORPORATED
*Copyright 2014 Adobe Systems Incorporated
*All Rights Reserved.
*NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
*terms of the Adobe license agreement accompanying it. If you have received this file
*from a source other than Adobe, then your use, modification, or distribution of it requires
*the prior written permission of Adobe.
-------------------------------------------------------------------------------------------------
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.IOException;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceException;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesOtherException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
* Digital signatures must be removed from a signature field before a newer digital signature can be applied.
* A digital signature cannot be overwritten.
* If you attempt to apply a digital signature to a signature field that contains a signature, an exception occurs
*
*The following Java code example removes a digital signature from a signature field named SignatureField1.
*The name of the PDF file that contain the signature field is LoanSigned.pdf
*/
@Component
@Service(value=ClearSignatureField.class)
public class ClearSignatureField {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to an encrypted pdf document stored at disk
* @param outFile - path where the output file has to be saved
* @throws Exception
*/
public void clearSignatureField(String inputFile, String outFile) throws Exception{
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
//Specify the name of the signature field
String fieldName = "SignatureField1";
//Clear the signature field
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
Document outPDF = docAssuranceService.clearSignatureField(inDoc,fieldName,null);
//save the outPDF
outPDF.copyToFile(new File(outFile));
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
인증 서명 필드를 가져오는 중 getting-certifying-signature-field
서명하거나 인증하려는 PDF 문서에 있는 모든 서명 필드의 이름을 검색할 수 있습니다. PDF 문서에 있는 서명 필드 이름을 잘 모르거나 이름을 확인하려는 경우 프로그래밍 방식으로 검색할 수 있습니다. Signature 서비스에서 서명 필드의 정규화된 이름(예: form1[0].grantApplication[0].page1[0].SignatureField1[0]
)을 반환합니다.
구문: getCertifyingSignatureField(Document inDoc, UnlockOptions unlockOptions)
입력 매개 변수
다음 Java 코드 예제는 문서를 인증하는 데 사용된 서명 필드를 검색합니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PDFSignatureField;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
/**
* You can retrieve the names of all signature fields that are in a PDF document that you want to sign or certify.
* If you are unsure of the signature field names that are in a PDF document or you want to verify the names, you can
* programmatically retrieve them. The Signature service returns the fully qualified name of the signature field, such as
* form1[0].grantApplication[0].page1[0].SignatureField1[0].
*
* The following Java code example retrieves the ignature field that was used to certify the document.
*/
@Component
@Service(value=GetCertifyingSignatureField.class)
public class GetCertifyingSignatureField {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @throws SignaturesBaseException
* @throws DuplicateSignatureFieldException
* @throws PermissionsException
* @throws PDFOperationException
* @throws InvalidArgumentException
*
*/
public void getCertifyingSignatureField(String inputFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
//Retrieve signature data for a given signature field.
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
PDFSignatureField pdfSignature = docAssuranceService.getCertifyingSignatureField(inDoc,null);
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
PDF 암호화 유형을 가져오는 중 getting-pdf-encryption-type
서명하거나 인증하려는 PDF 문서에 있는 모든 서명 필드의 이름을 검색할 수 있습니다. PDF 문서에 있는 서명 필드 이름을 잘 모르거나 이름을 확인하려는 경우 프로그래밍 방식으로 검색할 수 있습니다. Signature 서비스에서 서명 필드의 정규화된 이름(예: asform1[0].grantApplication[0].page1[0].SignatureField1[0]
)을 반환합니다.
구문: void getPDFEncryption(Document inDoc)
입력 매개 변수
다음 Java 코드 예제에서는 PDF 문서의 지정된 서명 필드에 대한 서명 정보를 검색합니다.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.docassurance.samples;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.PDFSignatureField;
import com.adobe.fd.signatures.client.types.exceptions.DuplicateSignatureFieldException;
import com.adobe.fd.signatures.client.types.exceptions.InvalidArgumentException;
import com.adobe.fd.signatures.client.types.exceptions.PDFOperationException;
import com.adobe.fd.signatures.client.types.exceptions.PermissionsException;
import com.adobe.fd.signatures.client.types.exceptions.SignaturesBaseException;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.encryption.client.EncryptionTypeResult;
/**
* You can retrieve the names of all signature fields that are in a PDF document that you want to sign or certify.
* If you are unsure of the signature field names that are in a PDF document or you want to verify the names, you can
* programmatically retrieve them. The Signature service returns the fully qualified name of the signature field, such as
* form1[0].grantApplication[0].page1[0].SignatureField1[0].
*
* The following Java code example retrieves the Signature Info for the given signature field in a PDF document.
*/
@Component
@Service(value=GetPDFEncryption.class)
public class GetPDFEncryption {
@Reference
private DocAssuranceService docAssuranceService;
/**
*
* @param inputFile - path to the pdf document stored at disk
* @throws SignaturesBaseException
* @throws DuplicateSignatureFieldException
* @throws PermissionsException
* @throws PDFOperationException
* @throws InvalidArgumentException
*
*/
public void getPDFEncryption(String inputFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
//Retrieve signature data for a given signature field.
//for encrypted document pass Unlock Options - see the method getUnlockOptions() below
EncryptionTypeResult encryptionTypeResult = docAssuranceService.getPDFEncryption(inDoc);
}
/**
* sets Unlock Options for encrypted PDF
*/
private UnlockOptions getUnlockOptions(){
UnlockOptions unlockOptions = new UnlockOptions();
//sets the Open Password for password encrypted PDF
unlockOptions.setPassword("OpenPassword");
//for Certificate Encrypted Document, set the alias of the credential uploaded in the user's key store
//and corresponding resource resolver
return unlockOptions;
}
}
PDF에서 암호 암호화 제거 removing-password-encryption-from-pdf
사용자가 암호를 지정하지 않고도 Adobe Reader 또는 Acrobat에서 PDF 문서를 열 수 있도록 하려면 PDF 문서에서 암호 기반 암호화를 제거합니다. PDF 문서에서 암호 기반 암호화를 제거하면 문서가 더 이상 안전하지 않습니다.
구문: Document removePDFPasswordSecurity (Document inDoc,String password)
입력 매개 변수
다음 코드 샘플은 PDF 문서에서 암호 기반 암호화를 제거합니다.
package com.adobe.docassurance.samples;
import java.io.File;
import java.io.FileNotFoundException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.jcr.api.SlingRepository;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
/**
* The following Java code example removes password-based encryption from a PDF document.
* The master password value used to remove password-based encryption is PermissionPassword
*
*/
@Component(enabled=true,immediate=true)
@Service(value=RemovePasswordEncryption.class)
public class RemovePasswordEncryption {
// Create reference for DocAssuranceService
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
/**
* The below sample code demonstrates removing password encryption from a PDF using AEM EncryptionService.
*
* @param inFilePath path of the input PDF File
* Path Example for Files stored at hardDisk = "C:/temp/test.pdf"
*
* @param outFilePath path where the output PDF File needs to be saved
* Path Example for Files stored at hardDisk = "C:/temp/test_out.pdf"
* @throws Exception
*/
public void removePasswordEncryption(String inputFile, String outputFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
try{
String password = "PermissionPassword"; //master password with which the pdf was encrypted
//in case if the pdf is encrypted only with user password, specify the
//user password
//Remove password-based encryption from the PDF document
outDoc = docAssuranceService.removePDFPasswordSecurity(inDoc,password);
}finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
}
outDoc.copyToFile(outFile);
}
}
인증서 암호화 제거 중 removing-certificate-encryption
사용자가 Adobe Reader 또는 Acrobat에서 PDF 문서를 열 수 있도록 PDF 문서에서 인증서 기반 암호화를 제거할 수 있습니다. 인증서로 암호화된 PDF 문서에서 암호화를 제거하려면 개인 키를 참조합니다. PDF 문서에서 암호화를 제거하면 더 이상 안전하지 않습니다.
구문: removePDFCertificateSecurity(Document inDoc, String alias, ResourceResolver resourceResolver)
입력 매개 변수
다음 Java 코드 샘플은 PDF 문서에서 인증서 기반 암호화를 제거합니다.
package com.adobe.docassurance.samples;
import java.io.File;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
/**
* The following Java code example removes certificate-based encryption from a PDF document
*
*/
@Component(enabled=true,immediate=true)
@Service(value=RemovePKIEncryption.class)
public class RemovePKIEncryption {
// Create reference for docAssuranceServiceInterface
@Reference
private DocAssuranceService docAssuranceService;
@Reference
private SlingRepository slingRepository;
@Reference
private JcrResourceResolverFactory jcrResourceResolverFactory ;
/**
* The below sample code demonstrates encrypting PDF with Password using AEM docAssuranceService.
*
* @param inFilePath path of the input PDF File
* Path Example for Files stored at hardDisk = "C:/temp/test.pdf"
*
* @param outFilePath path where the output PDF File needs to be saved
* Path Example for Files stored at hardDisk = "C:/temp/test_Encrypted.pdf"
*
* @throws Exception
*/
public void removePKIEncryption(String inputFile, String outputFile) throws Exception {
File inFile = new File(inputFile);
Document inDoc = new Document(inFile);
File outFile = new File(outputFile);
Document outDoc = null;
Session adminSession = null;
ResourceResolver resourceResolver = null;
try{
adminSession = slingRepository.loginAdministrative(null);
resourceResolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
//Remove certificate-based encryption from the PDF document
/**
* Here the alias("encryption") of the private credential stored in the keystore of the
* user has been provided with the user's resource resolver
*/
outDoc = docAssuranceService.removePDFCertificateSecurity(inDoc, "encryption",resourceResolver);
}catch(Exception e){
// TODO Auto-generated catch block
}finally{
/**
* always close the PDFDocument object after your processing is done.
*/
if(inDoc != null){
inDoc.close();
}
if(adminSession != null && adminSession.isLive()){
if(resourceResolver != null){
resourceResolver.close();
}
adminSession.logout();
}
}
outDoc.copyToFile(outFile);
}
}
출력 서비스 output-service
출력 서비스는 XDP 파일을 .pdf, .pcl, .zpl 및 .ps 형식으로 렌더링하기 위한 API를 제공합니다. 이 서비스는 다음 API를 지원합니다.
-
generatePDFOutput: 양식 디자인을 네트워크 위치, 로컬 파일 시스템 또는 HTTP 위치에 저장된 데이터와 리터럴 값으로 병합하여 PDF 문서를 생성합니다.
-
generatePDFOutput: 양식 디자인을 응용 프로그램에 저장된 데이터와 병합하여 PDF 문서를 생성합니다.
-
generatePDFOutputBatch: 양식 디자인을 데이터와 병합하여 PDF 문서를 만듭니다. 선택적으로, 는 각 레코드에 대한 메타데이터 파일을 생성하거나 출력을 PDF 파일에 저장합니다.
-
generatePrintedOutput: 네트워크 위치, 로컬 파일 시스템 또는 HTTP 위치에 저장된 양식 디자인 및 데이터 파일에서 PCL, PostScript 또는 ZPL 출력을 리터럴 값으로 생성합니다.
-
generatePrintedOutput: 응용 프로그램에 저장된 양식 디자인 및 데이터 파일에서 PCL, PostScript 및 ZPL 출력을 생성합니다.
generatePDFOutput generatepdfoutput
generatePDFOutput API는 양식 디자인을 데이터와 병합하여 PDF 문서를 생성합니다. 선택적으로, 는 각 레코드에 대한 메타데이터 파일을 생성하거나 출력을 PDF 파일에 저장합니다. 네트워크 위치, 로컬 파일 시스템 또는 HTTP 위치에 저장된 양식 디자인 또는 데이터에 대해 generatePDFOutput API를 리터럴 값으로 사용합니다. 양식 디자인과 XML 데이터가 응용 프로그램에 저장되어 있는 경우 generatePDFOutput API를 사용하십시오.
구문: Document generatePDFOutput(String uriOrFileName, Document data, PDFOutputOptions options);
입력 매개 변수 input-parameters
다음 Java 코드 샘플은 양식 디자인을 XML 파일에 저장된 데이터와 병합하여 PDF 문서를 생성합니다.
@Reference private OutputService outputService;
private File generatePDFOutput(String contentRoot,File inputXML,String templateStr,String acrobatVersion,String tagged,String linearized, String locale) {
String outputFolder="C:/Output";
Document doc=null;
try {
PDFOutputOptions option = new PDFOutputOptions(); option.setContentRoot(contentRoot); if(acrobatVersion.equalsIgnoreCase("Acrobat_10"))
{
option.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_10);
} else if(acrobatVersion.equalsIgnoreCase("Acrobat_10_1")) {
option.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_10_1);
} else if(acrobatVersion.equalsIgnoreCase("Acrobat_11")) { option.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_11);
}
if (tagged.equalsIgnoreCase("true") ) {
option.setTaggedPDF(true );
}
if (linearized.equalsIgnoreCase("true") ) {
option.setTaggedPDF(true );
}
if(locale!=null)
{
option.setLocale(locale);
}
InputStream in = new FileInputStream(inputXML);
doc = outputService.generatePDFOutput(templateStr,new Document(in),option); File toSave = new File(outputFolder+"Output.pdf");
doc.copyToFile(toSave);
return toSave;
} catch (OutputServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
doc.dispose();
}
return null;
}
generatePDFOutput generatepdfoutput-1
generatePDFOutput API는 양식 디자인을 데이터와 병합하여 PDF 문서를 생성합니다. 필요한 경우 각 레코드에 대한 메타데이터 파일을 생성하거나 출력을 PDF 파일에 저장합니다. 양식 디자인이나 응용 프로그램에 저장된 데이터에 대해 generatePrintedOutput API를 사용합니다. 양식 디자인과 XML 데이터가 네트워크 위치, 로컬 또는 HTTP 위치에 리터럴 값으로 저장되어 있는 경우 generatePDFOutput API를 사용하십시오.
구문: Document generatePDFOutput(Document inputdocument, Document data, PDFOutputOptions options)
입력 매개 변수 input-parameter
다음 Java 코드 샘플은 양식 디자인을 XML 파일에 저장된 데이터와 병합하여 PDF 문서를 생성합니다.
@Reference private OutputService outputService;
private File generatePDFOutput2(String contentRoot, File inputXML, File templateStr, String acrobatVersion, String tagged, String linearized, String locale) {
String outputFolder="C:/Output";
Document doc=null;
try {
PDFOutputOptions option = new PDFOutputOptions(); option.setContentRoot(contentRoot);
if(locale!=null)
{
option.setLocale(locale);
}
if(acrobatVersion.equalsIgnoreCase("Acrobat_10"))
{
option.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_10);
} else if(acrobatVersion.equalsIgnoreCase("Acrobat_10_1")) { option.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_10_1);
} else if(acrobatVersion.equalsIgnoreCase("Acrobat_11")) { option.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_11);
}
if (tagged.equalsIgnoreCase("true") ) {
option.setTaggedPDF(true );
}
if (linearized.equalsIgnoreCase("true") ) {
option.setTaggedPDF(true );
}
InputStream inputXMLStream = new FileInputStream(inputXML);
InputStream templateStream = new FileInputStream(templateStr);;
doc = outputService.generatePDFOutput(new Document(templateStream),new Document(inputXMLStream),option);
File toSave = new File(outputFolder,"Output.pdf");
doc.copyToFile(toSave);
return toSave;
} catch (OutputServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
doc.dispose();
}
return null;
}
generatePDFOutputBatch generatepdfoutputbatch
양식 디자인을 데이터와 병합하여 PDF 문서를 만듭니다. 선택적으로, 는 각 레코드에 대한 메타데이터 파일을 생성하거나 출력을 PDF 파일에 저장합니다. 네트워크 위치, 로컬 파일 시스템 또는 HTTP 위치에 저장된 양식 디자인 또는 데이터에 대해 generatePDFOutputBatch API를 리터럴 값으로 사용합니다.
구문: BatchResult generatePDFOutputBatch(Map templates, Map data, PDFOutputOptions options, BatchOptions batchOptions);
입력 매개 변수 input-parameters-1
다음 Java 코드 샘플은 양식 디자인을 XML 파일에 저장된 데이터와 병합하여 PDF 문서를 생성합니다.
private ArrayList generatePDFBatch(String contentRoot,String multipleFiles) {
String outputFolder="C:/Output";
try {
PDFOutputOptions option = new PDFOutputOptions(); option.setContentRoot(contentRoot);
Map templates = new LinkedHashMap();
Map data = new LinkedHashMap();
String template1 = "PurchaseOrder.xdp"; String template2 = "CardApp.xdp"; templates.put(template1.substring(0, template1.indexOf(".xdp")),template1); templates.put(template1.substring(0, template2.indexOf(".xdp")),template2);
File inputXML1 = new File("c:/InputFolder/PurchaseOrder.xml");
File inputXML2 = new File("c:/InputFolder/CardApp.xml");
InputStream in1 = new FileInputStream(inputXML1);
InputStream in2 = new FileInputStream(inputXML2);
data.put(template1.substring(0, template1.indexOf(".xdp")),new Document((in1))); data.put(template1.substring(0, template1.indexOf(".xdp")),new Document((in2))); BatchOptions bo = new BatchOptions(); BatchResult ret=null; if(multipleFiles.equalsIgnoreCase("true"))
{
bo.setGenerateManyFiles(true);
ret = outputService.generatePDFOutputBatch(templates, data, option, bo);
} else {
ret = outputService.generatePDFOutputBatch(templates, data, option, new BatchOptions());
}
ArrayList outputs = new ArrayList();
int counter=0;
if(ret.getMetaDataDoc() !=null ){
File toSave = new File(outputFolder+"Output.xml");
ret.getMetaDataDoc().copyToFile(toSave);
outputs.add(toSave);
List<Document> list = ret.getGeneratedDocs();
for(Document doc:list){
File toSave = new File(outputFolder,"Output"+"_"+counter+".pdf"); doc.copyToFile(toSave); outputs.add(toSave);
counter++;
doc.dispose();
}
return outputs;
} catch (OutputServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
return null;
}
generatePrintedOutput generateprintedoutput
양식 디자인 및 데이터 파일에서 PCL, PostScript 및 ZPL 출력을 생성합니다. 데이터 파일이 양식 디자인과 병합되고 인쇄용으로 서식이 지정됩니다. 출력을 프린터로 직접 보내거나 파일로 저장할 수 있습니다. 양식 디자인이나 응용 프로그램에 저장된 데이터에 대해 generatePrintedOutput API를 사용합니다.
구문: Document generatePrintedOutput(String uriOrFileName, Document data, PrintedOutputOptions);
입력 매개 변수 input-parameters-2
다음 Java 코드 샘플은 양식 디자인 및 데이터에서 PCL, PostScript 및 ZPL 출력을 생성합니다. 출력 형식은 printConfig
매개 변수에 전달된 값에 따라 다릅니다.
@Reference private OutputService outputService;
private File generatePrintedOutput(String contentRoot,File inputXML,String templateStr,String printConfig) {
String outputFolder="C:/Output";
Document doc=null;
try {
PrintedOutputOptions options = new PrintedOutputOptions(); options.setContentRoot(contentRoot);
if(printConfig.equalsIgnoreCase("ps"))
{
options.setPrintConfig(PrintConfig.PS_PLAIN);
}else if(printConfig.equalsIgnoreCase("pcl")) {
options.setPrintConfig(PrintConfig.HP_PCL_5e);
}else if(printConfig.equalsIgnoreCase("zpl")) { options.setPrintConfig(PrintConfig.ZPL300);
}
InputStream in = new FileInputStream(inputXML);
doc = outputService.generatePrintedOutput(templateStr,new Document(in),options);
in.close();
File toSave = new File(outputFolder,"Output"+"."+printConfig); doc.copyToFile(toSave);
return toSave;
} catch (OutputServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}finally{
doc.dispose();
}
return null;
}
generatePrintedOutput generateprintedoutput-1
양식 디자인 및 데이터 파일이 지정된 PCL, PostScript 및 ZPL 출력을 생성합니다. 데이터 파일이 양식 디자인과 병합되고 인쇄용으로 서식이 지정됩니다. 출력을 프린터로 직접 보내거나 파일로 저장할 수 있습니다. 양식 디자인이나 응용 프로그램에 저장된 데이터에 generatePrintedOutput API를 사용합니다.
구문: Document generatePrintedOutput(Document inputdocument, Document data, PrintedOutputOptions);
입력 매개 변수 input-parameters-3
다음 Java 코드 샘플은 양식 디자인 및 데이터에서 PCL, PostScript 및 ZPL 출력을 생성합니다. 출력 형식은 printConfig
매개 변수에 전달된 값에 따라 다릅니다.
@Reference private OutputService outputService;
private File generatePrintedOutput2(File inputXML,File templateStr,String printConfig) {
String outputFolder="C:/Output";
Document doc=null;
try {
PrintedOutputOptions options = new PrintedOutputOptions(); if(printConfig.equalsIgnoreCase("ps"))
{
options.setPrintConfig(PrintConfig.PS_PLAIN);
}else if(printConfig.equalsIgnoreCase("pcl")) { options.setPrintConfig(PrintConfig.HP_PCL_5e);
}else if(printConfig.equalsIgnoreCase("zpl")) { options.setPrintConfig(PrintConfig.ZPL300);
}
InputStream inputXMlStream = new FileInputStream(inputXML);
InputStream templateStream = new FileInputStream(templateStr); doc = outputService.generatePrintedOutput(new Document(templateStream),new Document(inputXMlStream),options);
File toSave = new File(outputFolder,"Output"+"."+printConfig); doc.copyToFile(toSave);
return toSave;
} catch (OutputServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
doc.dispose();
}
return null;
}
generatePrintedOutputBatch generateprintedoutputbatch
양식 디자인을 데이터와 병합하여 PS, PCL 및 ZPL 형식의 문서를 생성합니다. 필요한 경우 각 레코드에 대한 메타데이터 파일을 생성하거나 출력을 PDF 파일에 저장합니다. 네트워크 위치, 로컬 파일 시스템 또는 HTTP 위치에 저장된 양식 디자인 또는 데이터에 대해 generatePrintedOutputBatch API를 리터럴 값으로 사용합니다.
구문:
BatchResult generatePrintedOutputBatch(Map templates, Map data, PrintedOutputOptions options, BatchOptions batchOptions);
입력 매개 변수 input-parameters-4
다음 Java 코드 샘플은 여러 양식 디자인 템플릿과 데이터 파일에서 PCL, PostScript 및 ZPL 출력을 일괄적으로 생성합니다. 출력 형식은 printConfig
매개 변수에 전달된 값에 따라 다릅니다.
@Reference private OutputService outputService;
private ArrayList generatePrintedOutputBatch(String contentRoot,String multipleFiles,String printConfig) {
String outputFolder="C:/Output";
try {
PrintedOutputOptions option = new PrintedOutputOptions(); option.setContentRoot(contentRoot);
Map templates = new LinkedHashMap();
Map data = new LinkedHashMap();
String template1 = "PurchaseOrder.xdp";
String template2 = "CardApp.xdp";
templates.put(template1.substring(0, template1.indexOf(".xdp")),template1); templates.put(template1.substring(0, template2.indexOf(".xdp")),template2);
File inputXML1 = new File("c:/InputFolder/PurchaseOrder.xml");
File inputXML2 = new File("c:/InputFolder/CardApp.xml");
InputStream in1 = new FileInputStream(inputXML1);
InputStream in2 = new FileInputStream(inputXML2); data.put(template1.substring(0, template1.indexOf(".xdp")),new Document((in1)));
data.put(template2.substring(0, template2.indexOf(".xdp")),new Document((in2)));
if(printConfig.equalsIgnoreCase("ps"))
{
option.setPrintConfig(PrintConfig.PS_PLAIN);
} else if(printConfig.equalsIgnoreCase("pcl"))
{
option.setPrintConfig(PrintConfig.HP_PCL_5e);
} else if(printConfig.equalsIgnoreCase("zpl")){
option.setPrintConfig(PrintConfig.ZPL300);
}
option.setContentRoot(contentRoot);
BatchOptions bo = new BatchOptions();
BatchResult ret = outputService.generatePrintedOutputBatch(temp lates, data, option, new BatchOptions());
ArrayList outputs = new ArrayList();
int counter=0;
if(ret.getMetaDataDoc() !=null ){
File toSave = new File(outputFolder,"Output"+".xml"); ret.getMetaDataDoc().copyToFile(toSave);
outputs.add(toSave);
List<Document> list = ret.getGeneratedDocs();
for(Document doc:list){
File toSave = new File(outputFolder,"Output"+"_"+counter+". "+printConfig); doc.copyToFile(toSave);
outputs.add(toSave);
counter++;
doc.dispose();
}
return outputs;
}
catch (OutputServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Forms 서비스 forms-service
Forms 서비스는 대화형 PDF 양식에서 데이터를 가져오고 내보내는 API를 제공합니다. 대화형 PDF 양식은 PDF에서 정보를 표시하고 수집하는 데 사용되는 하나 이상의 필드가 포함된 사용자 문서입니다. 이 서비스는 다음 API를 지원합니다.
- exportData: PDF 양식에서 데이터를 내보냅니다.
- importData: 데이터를 대화형 PDF 양식으로 가져옵니다.
exportData exportdata
대화형 PDF 양식의 양식 데이터를 XML 및 XDP 형식으로 내보냅니다.
구문: Document exportData(Document xdpOrPdf, DataFormat dataFormat)
입력 매개 변수 input-parameters-5
다음 Java 코드 샘플은 대화형 PDF 양식의 양식 데이터를 XML 및 XDP 형식으로 내보냅니다.
샘플 sample
@Reference private FormsService formsService;
private File exportData(String dataFormat, File inDoc) {
String outputFolder="C:/Output";
InputStream in; Document doc=null;
try {
in = new FileInputStream(inDoc);
if(dataFormat.equalsIgnoreCase("xml"))
{
doc=formsService.exportData(new Document(in), DataFormat.XmlData);
}
else if(dataFormat.equalsIgnoreCase("xdp")) {
doc =formsService.exportData(new Document(in), DataFormat.XDP);
}
File toSave = new File(outputFolder,"Output"+"."+dataFormat);
doc.copyToFile(toSave);
return toSave;
} catch (FormsServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
doc.dispose();
}
return null;
}
importData importdata
양식 데이터를 대화형 PDF 양식으로 가져옵니다.
구문: Document importData(Document PDF, Document data)
입력 매개 변수 input-parameters-6
다음 Java 코드 샘플은 양식 데이터를 대화형 PDF 양식으로 가져옵니다.
샘플 sample-1
@Reference private FormsService formsService
private File importData(File inDoc, File inXML)
{
String outputFolder="C:/Output";
Document doc=null;
try {
InputStream in = new FileInputStream(inDoc);
InputStream in2 = new FileInputStream(inXML);
doc=formsService.importData(new Document(in), new Document(in2));
File toSave = new File(outputFolder,"Output.pdf");
doc.copyToFile(toSave);
} catch (FormsServiceException e) {
e.printStackTrace();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
doc.dispose();
}
return null;
}
PDF Generator 서비스 pdfgeneratorservice
PDF Generator 서비스는 기본 파일 형식을 PDF으로 변환하는 API를 제공합니다. 또한 PDF을 다른 파일 형식으로 변환하고 PDF 문서의 크기를 최적화합니다.
GeneratePDF서비스 generatepdfservice
GeneratePDFService는 .doc, .docx, .ppt, .pptx, .xls, .xlsx, .odp, .odt, .ods, .swf(더 이상 사용되지 않음), .jpg, .bmp, .tif, .png, .html 및 기타 여러 파일 형식과 같은 다양한 파일 형식을 PDF으로 변환하는 API를 제공합니다. 또한 PDF을 다양한 파일 형식으로 내보내고 PDF을 최적화할 수 있는 API를 제공합니다. 이 서비스는 다음 API를 지원합니다.
-
createPDF: 지원되는 파일 형식을 PDF 문서로 변환합니다. Microsoft Word, Microsoft PowerPoint, Microsoft Excel 및 Microsoft 프로젝트와 같은 파일 형식을 지원합니다. 이러한 애플리케이션 외에도 모든 서드파티 범용 PDF 생성 애플리케이션 유형을 API에 연결할 수도 있습니다.
-
exportPDF: PDF 문서를 지원되는 파일 형식으로 변환합니다. 메서드는 PDF을 입력으로 받아들이고 PDF 콘텐츠를 지정된 파일 형식 형식으로 내보냅니다. 캡슐화된 PostScript( eps), HTML 3.2( htm, html), CSS 1.0( htm, html), JPEG( jpg, jpeg, jpe), JPEG2000( jpf, jpx, jp2, j2k, j2c, jpc), Microsoft Word Document( doc, docx) Microsoft Excel 통합 문서( xlsx), HTML PowerPoint Presentation( pptx), PNG( png), Microsoft( ps), 리치 텍스트 형식( rtf), 텍스트(Accessible)( txt), 텍스트(Plain) PostScript( tif, tiff), XML 1.0 xml(), TIFF/A-1rgb(s)로 PDF 문서를 내보낼 수 있습니다), PDF/A-1b, PDF/A-2a(sRGB), PDF/A-2b(sRGB), PDF/A-3a(sRGB), PDF PDF/A-3b(sRGB) 형식 PDF 출력에 대해 사용자 지정 Preflight 프로필을 지정할 수도 있습니다.
-
optimizePDF: PDF 문서를 최적화하고 PDF 문서를 한 유형에서 다른 유형으로 변환합니다. 메서드는 PDF 문서를 입력으로 받아들입니다.
-
htmlToPdf2: HTML 페이지를 PDF 문서로 변환합니다. HTML 페이지의 URL을 입력으로 허용합니다.
Microsoft Windows 및 Linux에서 사용 가능한 PDF Generator API pdf-generator-api-available-on-microsoft-windows-and-linux
createPDF createpdf
createPDF API는 지원되는 파일 유형을 PDF 문서로 변환합니다. Microsoft Word, Microsoft PowerPoint, Microsoft Excel 및 Microsoft Project와 같은 다양한 파일 형식을 지원합니다. 이러한 애플리케이션 외에도 모든 서드파티 범용 PDF 생성 애플리케이션 유형을 API에 연결할 수도 있습니다.
변환의 경우 몇 개의 매개 변수만 필수입니다. 입력 문서는 필수 매개 변수입니다. 나중에 보안 권한, PDF 출력 설정 및 메타데이터 정보를 출력 PDF 문서에 적용할 수 있습니다.
createPDF 서비스는 결과가 포함된 java.util.Map을 반환합니다. 지도의 키는 다음과 같습니다.
- ConvertedDoc: 새로 생성된 PDF 문서가 포함되어 있습니다.
- LogDoc: 여기에는 로그 파일이 포함되어 있습니다.
createPDF 서비스에는 다음 예외가 발생합니다.
- ConversionException
- InvalidParameterException
- 파일 형식지원되지 않음Exception
구문: Map createPDF(Document inputDoc, String inputFilename, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, Document xmpDoc) throws InvalidParameterException, ConversionException, FileFormatNotSupportedException;
입력 매개 변수 input-parameters-7
다음 Java 코드는 지원되는 파일 유형의 문서를 PDF 문서로 변환합니다.
@Reference GeneratePDFService generatePdfService;
File createPDF(File inputFile, String inputFilename, String fileTypeSettings, String pdfSettings, String securitySettings, File settingsFile, File xmpFile) throws Exception
{
Transaction tx = OSGiUtils.getTransactionManager().getTransaction();
// Begin transaction
if (tx == null)
OSGiUtils.getTransactionManager().begin();
String outputFolder="C:/Output"
Document convertedDoc = null;
Document inDoc = null;
Document settingsDoc = null;
Document xmpDoc = null;
try
{
inDoc = new Document(inputFile);
if(inputFilename == null || inputFilename.trim().equals("")) {
throw new Exception("Input file name cannot be null");
}
if(inputFileExtension.lastIndexOf('.') == -1) {
throw new Exception("Input file should have an extension");
}
if(settingsFile != null && settingsFile.exists() && settingsFile.isFile())
settingsDoc = new Document(settingsFile);
if(xmpFile != null && xmpFile.exists() && xmpFile.isFile())
xmpDoc = new Document(xmpFile);
Map result = generatePdfService.createPDF(inDoc, inputFilename, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, xmpDoc);
convertedDoc = (Document)result.get("ConvertedDoc");
OSGiUtils.getTransactionManager().commit();
File outputFile = new File(outputFolder,"Output.pdf");
doc.copyToFile(outputFile);
return outputFile;
}
catch (Exception e)
{
if (OSGiUtils.getTransactionManager().getTransaction() != null)
OSGiUtils.getTransactionManager().rollback();
throw e;
}
finally {
if (convertedDoc != null) {
convertedDoc.dispose();
convertedDoc = null;
}
if (inDoc != null) {
inDoc.dispose();
inDoc = null;
}
if (settingsDoc != null) {
settingsDoc.dispose();
settingsDoc = null;
}
if (xmpDoc != null) {
xmpDoc.dispose();
xmpDoc = null;
}
}
}
exportPDF exportpdf
PDF 문서를 지원되는 파일 형식으로 변환합니다. 메서드는 PDF을 입력으로 받아들이고 PDF 콘텐츠를 지정된 파일 형식 형식으로 내보냅니다.
createPDF 서비스는 결과가 포함된 java.util.Map을 반환합니다. 지도의 키는 다음과 같습니다.
- ConvertedDoc: 출력 문서가 포함되어 있습니다.
createPDF 서비스에는 다음 예외가 발생합니다.
- ConversionException
- InvalidParameterException
- 파일 형식지원되지 않음Exception
구문:
Map exportPDF(Document inputDoc, String inputFileName, String formatType, Document settingsDoc) throws ConversionException, InvalidParameterException, FileFormatNotSupportedException;
입력 매개 변수 input-parameters-8
다음 Java 코드 샘플은 PDF 문서를 지정된 파일 형식으로 변환합니다.
(tx == null)
OSGiUtils.getTransactionManager().begin();
String outputFolder="C:/Output"
Document convertedDoc = null;
Document inDoc = null;
Document settingsDoc = null;
try
{
inDoc = new Document(inputFile);
if(inputFileName == null || inputFileName.trim().equals("")) {
throw new Exception("Input file name cannot be null");
}
if(inputFileExtension.lastIndexOf('.') == -1) {
throw new Exception("Input file should have an extension");
}
if(settingsFile != null && settingsFile.exists() && settingsFile.isFile())
settingsDoc = new Document(settingsFile);
Map result = generatePdfService.exportPDF(inDoc, inputFileName, formatType, settingsDoc);
convertedDoc = (Document)result.get("ConvertedDoc");
OSGiUtils.getTransactionManager().commit();
File outputFile = new File(outputFolder,"OutputFile");
doc.copyToFile(outputFile);
return outputFile;
}
catch (Exception e)
{
if (OSGiUtils.getTransactionManager().getTransaction() != null)
OSGiUtils.getTransactionManager().rollback();
throw e;
}
finally {
if (convertedDoc != null) {
convertedDoc.dispose();
convertedDoc = null;
}
if (inDoc != null) {
inDoc.dispose();
inDoc = null;
}
if (settingsDoc != null) {
settingsDoc.dispose();
settingsDoc = null;
}
}
}
optimizePDF optimizepdf
OptimizePDF API는 크기를 줄여 PDF 파일을 최적화합니다. 이 변환의 결과는 원본 버전보다 작을 수 있는 PDF 파일입니다. 또한 이 작업은 PDF 문서를 최적화 매개 변수에 지정된 PDF 버전으로 변환합니다. 최적화된 PDF이 포함된 OptimizePDFResult 개체를 반환합니다.
createPDF 서비스에는 다음 예외가 발생합니다.
- ConversionException
- InvalidParameterException
- 파일 형식지원되지 않음Exception
구문:
OptimizePDFResult optimizePDF(Document inputDoc, String fileTypeSettings, Document settingsDoc) throws ConversionException, InvalidParameterException, FileFormatNotSupportedException;
입력 매개 변수 input-parameters-9
다음 Java 코드 샘플은 크기를 줄여 입력 PDF 파일을 최적화합니다.
@Reference GeneratePDFService generatePdfService;
File optimizePDF(File inputFile, String fileTypeSettings, File settingsFile) throws Exception
{
Transaction tx = OSGiUtils.getTransactionManager().getTransaction();
// Begin transaction
if (tx == null)
OSGiUtils.getTransactionManager().begin();
String outputFolder="C:/Output"
Document convertedDoc = null;
Document inDoc = null;
Document settingsDoc = null;
try
{
inDoc = new Document(inputFile);
if(settingsFile != null && settingsFile.exists() && settingsFile.isFile())
settingsDoc = new Document(settingsFile);
OptimizePDFResult result = generatePdfService.optimizePDF(inDoc, fileTypeSettings, settingsDoc);
convertedDoc = result.getConvertedDocument();
OSGiUtils.getTransactionManager().commit();
File outputFile = new File(outputFolder,"Output.pdf");
doc.copyToFile(outputFile);
return outputFile;
}
catch (Exception e)
{
if (OSGiUtils.getTransactionManager().getTransaction() != null)
OSGiUtils.getTransactionManager().rollback();
throw e;
}
finally {
if (convertedDoc != null) {
convertedDoc.dispose();
convertedDoc = null;
}
if (inDoc != null) {
inDoc.dispose();
inDoc = null;
}
if (settingsDoc != null) {
settingsDoc.dispose();
settingsDoc = null;
}
}
}
htmlToPdf2 htmltopdf
HTML 페이지를 PDF 문서로 변환합니다. HTML 페이지의 URL을 입력으로 허용합니다.
htmlToPdf2 서비스는 HtmlToPdfResult 객체를 반환합니다. result.getConvertedDocument() 를 통해 변환된 PDF을 가져올 수 있습니다.
htmlToPdf2 서비스에는 다음 예외가 발생합니다.
- ConversionException
- InvalidParameterException
- 파일 형식지원되지 않음Exception
구문:
HtmlToPdfResult htmlToPdf2(String inputUrl, String fileTypeSettingsName, String securitySettingsName, Document settingsDoc, Document xmpDoc) throws ConversionException, InvalidParameterException, FileFormatNotSupportedException;
입력 매개 변수 input-parameters-10
다음 Java 코드 샘플은 HTML 페이지를 PDF 문서로 변환합니다.
Reference GeneratePDFService generatePdfService;
File htmlToPdf(String inputUrl, String fileTypeSettingsName, String securitySettingsName, File settingsFile, File xmpFile) throws Exception
{
Transaction tx = OSGiUtils.getTransactionManager().getTransaction();
// Begin transaction
if (tx == null)
OSGiUtils.getTransactionManager().begin();
String outputFolder="C:/Output"
Document convertedDoc = null;
Document settingsDoc = null;
Document xmpDoc = null;
try
{
if(settingsFile != null && settingsFile.exists() && settingsFile.isFile())
settingsDoc = new Document(settingsFile);
if(xmpFile != null && xmpFile.exists() && xmpFile.isFile())
xmpDoc = new Document(xmpFile);
HtmlToPdfResult result = generatePdfService.htmlToPdf2(inputURL, fileTypeSettingsName, securitySettingsName, settingsDoc, xmpDoc);;
convertedDoc = result.getConvertedDocument();
OSGiUtils.getTransactionManager().commit();
File outputFile = new File(outputFolder,"Output.pdf");
doc.copyToFile(outputFile);
return outputFile;
}
catch (Exception e)
{
if (OSGiUtils.getTransactionManager().getTransaction() != null)
OSGiUtils.getTransactionManager().rollback();
throw e;
}
finally {
if (convertedDoc != null) {
convertedDoc.dispose();
convertedDoc = null;
}
if (xmpDoc != null) {
xmpDoc.dispose();
xmpDoc = null;
}
if (settingsDoc != null) {
settingsDoc.dispose();
settingsDoc = null;
}
}
}
DistillerService distillerservice
Distiller 서비스는 PostScript, 캡슐화된 PostScript(EPS) 및 프린터 텍스트 파일(PRN)을 PDF 파일로 변환합니다. Distiller 서비스는 대량의 인쇄 문서를 송장 및 명세서 등의 전자 문서로 변환하는 데 자주 사용됩니다. 문서를 PDF으로 변환하면 기업에서 고객에게 종이 버전과 전자 버전의 문서를 보낼 수 있습니다. 지원되는 파일 형식은 .ps, .eps 및 .prn입니다. 이 서비스는 다음 API를 지원합니다.
createPDF 서비스는 결과가 포함된 java.util.Map을 반환합니다. 지도의 키는 다음과 같습니다.
- ConvertedDoc : 새로 생성된 PDF 문서가 포함되어 있습니다.
- LogDoc : 로그 파일을 포함합니다.
createPDF 서비스에는 다음 예외가 발생합니다.
- ConversionException
- InvalidParameterException
- 파일 형식지원되지 않음Exception
createPDF createpdf-1
지원되는 형식을 PDF 문서로 변환합니다. 이 메서드는 .ps, .eps 및 .prn 형식의 파일을 입력으로 허용합니다. 특정 보안 권한, 출력 설정 및 메타데이터 정보를 출력 PDF 문서에 적용할 수 있습니다.
구문:
Map createPDF(Document inputDoc, String inputFileName, String pdfSettings, String securitySettings, Document settingsDoc, Document xmpDoc) throws ConversionException, InvalidParameterException, FileFormatNotSupportedException;
입력 매개 변수 input-parameters-11
다음 Java 코드 샘플은 유형 PostScript(PS), 캡슐화된 PostScript(EPS) 및 프린터 텍스트 파일(PRN)의 입력 파일을 PDF 파일로 변환합니다.
@Reference DistillerService distillerService;
File createPDF(File inputFile, String inputFilename, String pdfSettings, String securitySettings, File settingsFile, File xmpFile) throws Exception
{
Transaction tx = OSGiUtils.getTransactionManager().getTransaction();
// Begin transaction
if (tx == null)
OSGiUtils.getTransactionManager().begin();
String outputFolder="C:/Output"
Document convertedDoc = null;
Document inDoc = null;
Document settingsDoc = null;
Document xmpDoc = null;
try
{
inDoc = new Document(inputFile);
if(inputFilename == null || inputFilename.trim().equals("")) {
throw new Exception("Input file name cannot be null");
}
if(inputFileExtension.lastIndexOf('.') == -1) {
throw new Exception("Input file should have an extension");
}
if(settingsFile != null && settingsFile.exists() && settingsFile.isFile())
settingsDoc = new Document(settingsFile);
if(xmpFile != null && xmpFile.exists() && xmpFile.isFile())
xmpDoc = new Document(xmpFile);
Map result = distillerService.createPDF(inDoc, inputFilename, pdfSettings, securitySettings, settingsDoc, xmpDoc);
convertedDoc = (Document)result.get("ConvertedDoc");
OSGiUtils.getTransactionManager().commit();
File outputFile = new File(outputFolder,"Output.pdf");
doc.copyToFile(outputFile);
return outputFile;
}
catch (Exception e)
{
if (OSGiUtils.getTransactionManager().getTransaction() != null)
OSGiUtils.getTransactionManager().rollback();
throw e;
}
finally {
if (convertedDoc != null) {
convertedDoc.dispose();
convertedDoc = null;
}
if (inDoc != null) {
inDoc.dispose();
inDoc = null;
}
if (settingsDoc != null) {
settingsDoc.dispose();
settingsDoc = null;
}
if (xmpDoc != null) {
xmpDoc.dispose();
xmpDoc = null;
}
}
}
문서 유틸리티 서비스 doc-utility-services
PDF 문서 자동 태그 지정 auto-tag-api
자동 태그 PDF API는 태그를 추가하여 PDF 문서에 액세스할 수 있도록 하는 데 도움이 되며 텍스트(단락)의 태그 지정 블록 및 글머리 기호 목록을 하나의 연산자로 지원합니다.