PDF Electronic Seal API
API Parameters
Signature Format (signatureFormat)
Specifies a supported digital signature format:
- PADES : This is the latest and improved signature format which is more strict, concrete, and secure. For details, see ISO 32000-2 and ETSI EN 319 142-1.
- PKCS7 : This signature format is less stringent than PADES since it permits more PDF changes without invalidating the digital signature. This is the default signature format. For details, see ISO 32000-1.
Document Level Permission (documentLevelPermission)
Specifies the DocMDP (i.e. Document Modification Detection and Prevention) permissions. These permissions are applied to the output electronically sealed document.
- NO_CHANGES_ALLOWED : No changes to the document are permitted. Any change to the document will invalidate the signature.
- FORM_FILLING : Allowed changes are filling in forms, instantiating page templates, and performing approval signatures. This is also the default document level permission, if not specified by the user.
- FORM_FILLING_AND_ANNOTATIONS : In addition to above, annotation creation, deletion, and modification are also allowed.
Long Term Validation (LTV) information of Timestamp Certificates (if using Trusted Timestamping) is embedded in the PDF document only if Document Level Permission is set as FORM_FILLING or FORM_FILLING_AND_ANNOTATIONS.
TSP Credential Information (cscCredentialOptions) : Required
TSP parameters encapsulate the sealer's certificate credential as well as the associated authentication and authorization data.
TSP Name (providerName) : Required : Specifies the name of the Trust Service Provider used to generate the certificate. Presently, only TSPs supporting the OAuth 2.0 client credential authorization flow are supported. The table below provides the provider name mapping for each supported Trust Service Provider.
TSP Credential Id (credentialId) : Required : Specifies the Digital ID stored with the TSP that should be used for sealing.
TSP Authorization Context (authorizationContext) : Required : Encapsulates the authorization data required to communicate with the TSPs.
- Access Token (accessToken) : Required : Specifies the access token used to authorize access to the CSC provider hosted APIs.
- Token Type (tokenType): Specifies the type of access token. Default value is "Bearer".
TSP Credential Authorization Parameter (credentialAuthParameters) : Required : Encapsulates the credential authorization information required to authorize access to their digital certificate.
- PIN (pin) : Required : Specifies the PIN associated with TSP provided credential ID.
TSA Information (tsaOptions) :
TSA parameters encapsulate the timestamping URL and credentials.
TSA URL (url) : Required : Specifies the TSA URL to be used for getting timestamp token.
TSA Credential Authorization Parameter (credentialAuthParameters) : Encapsulates the credential information required to authenticate the TSA URL.
- TSA Username (username) : Specify the username for authenticating TSA URL.
- TSA Password (password) : Specify the password for authenticating TSA URL.
Seal Field Parameters (sealFieldOptions) : Required
The seal field parameters are required to create a new signature field or use an existing signature field.
Field Name (fieldName) : Required : Specifies the signature field's name. This must be a non-empty string. If signature field with this field name already exists, that field is used. else a signature field with this name will be created.
Visible (visible): Specifies whether the signature field should be visible or hidden. The default value of
true
creates a visible seal.Page Number (pageNumber) : Required : Specifies the page number to which the signature field should be attached. Page numbers are 1-based. It is only required if the signature field needs to be visible and, it does not exist in the pdf document. If this is provided along with the signature field then the page number should be same on which signature field is present in the document, else an error is thrown. This parameter will be ignored in case of invisible signature field.
Location (location) : Required : Specifies the coordinates of the seal appearance's bounding box in default PDF user space units. The location is only required if the signature field does not exist in the pdf document. If this is provided along with the existing signature field, then it is ignored. This parameter will also be ignored for invisible signature field.
- Left (left) : Required : The left x-coordinate
- Bottom (bottom) : Required : The bottom y-coordinate
- Right (right) : Required : The right x-coordinate
- Top (top) : Required : The top y-coordinate
To add the signature field explicitly, see how to place a signature field in a PDF.
Seal Appearance Parameters (sealAppearanceOptions)
Specifies seal field appearance parameters. These are an enumerated set of display items: NAME, DATE, DISTINGUISHED_NAME, LABELS and SEAL_IMAGE.
Display Options (displayOptions): Specifies the information to display in the seal. NAME and LABELS are the default values.
- NAME: Specifies that the certificate owner's name should be displayed.
- DATE: Specifies that the sealing date/time should be displayed. This value should not be mistaken for a signed timestamp from a timestamp authority.
- DISTINGUISHED_NAME: Specifies that the distinguished name information from the digital certificate should be displayed.
- LABELS: Specifies that text labels should be displayed.
- SEAL_IMAGE: Specifies the seal image should be displayed. If SEAL_IMAGE is given in appearance parameters and seal image is not passed in the request, the default Acrobat trefoil image is used.
Example JSON
Copied to your clipboard1{2 "signatureFormat": "PADES",3 "documentLevelPermission": "FORM_FILLING",4 "cscCredentialOptions": {5 "authorizationContext": {6 "accessToken": "<ACCESS_TOKEN>",7 "tokenType": "Bearer"8 },9 "credentialAuthParameters": {10 "pin": "<PIN>"11 },12 "providerName": "<PROVIDER_NAME>",13 "credentialId": "<CREDENTIAL_ID>"14 },15 "tsaOptions": {16 "url": "<TIMESTAMP_URL>",17 "credentialAuthParameters": {18 "username": "<USERNAME>",19 "password": "<PASSWORD>"20 }21 },22 "sealFieldOptions": {23 "pageNumber": 1,24 "fieldName": "Signature1",25 "visible": true,26 "location": {27 "left" : 150,28 "top": 250,29 "bottom": 350,30 "right": 20031 }32 },33 "sealAppearanceOptions": {34 "displayOptions": [35 "NAME",36 "DATE",37 "LABELS",38 "DISTINGUISHED_NAME",39 "SEAL_IMAGE"40 ]41 }42}
Support of Trusted Timestamping and Document Level Permissions is only available through REST APIs and Java SDK. Other SDKs will support these features in future versions.
API limitations
- Input PDF size: Input PDF files up to a maximum of 100 MB are supported.
- Seal Image size: Seal Image files up to a maximum of 5 MB are supported.
- Seal Image formats: Supported Seal Image formats are JPEG(image/jpeg), PNG(image/png) and PDF(application/pdf).
- Password-protected Files: Encrypted or Password-protected PDFs are not supported for applying electronic seal.
- Signed/Sealed Files: Any PDF which is already signed, certified or sealed cannot be used for applying electronic seal.
- Input PDF version: Input PDF with version less than 1.3 are not supported.
- Usage Rights File: Input PDF having usage rights are not supported.
REST API
See our public API Reference for PDF Electronic Seal API.
Apply Electronic Seal with default appearance on PDF
The sample below performs electronic seal operation with default appearance on a given PDF.
Please refer to the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.electronicseal.ElectronicSeal45package com.adobe.pdfservices.operation.samples.electronicseal;67public class ElectronicSeal {89 // Initialize the logger.10 private static final Logger LOGGER = LoggerFactory.getLogger(ElectronicSeal.class);1112 public static void main(String[] args) {13 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/sampleInvoice.pdf").toPath());14 InputStream inputStreamSealImage = Files.newInputStream(new File("src/main/resources/sampleSealImage.png").toPath())) {15 // Initial setup, create credentials instance16 Credentials credentials = new ServicePrincipalCredentials(17 System.getenv("PDF_SERVICES_CLIENT_ID"),18 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1920 // Creates a PDF Services instance21 PDFServices pdfServices = new PDFServices(credentials);2223 // Creates an asset(s) from source file(s) and upload24 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());25 Asset sealImageAsset = pdfServices.upload(inputStreamSealImage, PDFServicesMediaType.PNG.getMediaType());2627 // Set the document level permission to be applied for output document28 DocumentLevelPermission documentLevelPermission = DocumentLevelPermission.FORM_FILLING;2930 // Sets the Seal Field Name to be created in input PDF document.31 String sealFieldName = "Signature1";3233 // Sets the page number in input document for applying seal.34 Integer sealPageNumber = 1;3536 // Sets if seal should be visible or invisible.37 Boolean sealVisible = true;3839 // Creates FieldLocation instance and set the coordinates for applying signature40 FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200);4142 // Create FieldOptions instance with required details.43 FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName)44 .setFieldLocation(fieldLocation)45 .setPageNumber(sealPageNumber)46 .setVisible(sealVisible)47 .build();4849 // Sets the name of TSP Provider being used.50 String providerName = "<PROVIDER_NAME>";5152 // Sets the access token to be used to access TSP provider hosted APIs.53 String accessToken = "<ACCESS_TOKEN>";5455 // Sets the credential ID.56 String credentialID = "<CREDENTIAL_ID>";5758 // Sets the PIN generated while creating credentials.59 String pin = "<PIN>";6061 // Creates CSCAuthContext instance using access token and token type.62 CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer");6364 // Create CertificateCredentials instance with required certificate details.65 CertificateCredentials certificateCredentials = CertificateCredentials.cscCredentialBuilder()66 .withProviderName(providerName)67 .withCredentialID(credentialID)68 .withPin(pin)69 .withCSCAuthContext(cscAuthContext)70 .build();7172 // Create parameters for the job73 PDFElectronicSealParams pdfElectronicSealParams = PDFElectronicSealParams74 .pdfElectronicSealParamsBuilder(certificateCredentials, fieldOptions)75 .withDocumentLevelPermission(documentLevelPermission)76 .build();7778 // Creates a new job instance79 PDFElectronicSealJob pdfElectronicSealJob = new PDFElectronicSealJob(asset, pdfElectronicSealParams);8081 // Sets the optional input seal image for PDFElectronicSealOperation instance82 pdfElectronicSealJob.setSealImageAsset(sealImageAsset);8384 // Submit the job and gets the job result85 String location = pdfServices.submit(pdfElectronicSealJob);86 PDFServicesResponse<PDFElectronicSealResult> pdfServicesResponse = pdfServices.getJobResult(location, PDFElectronicSealResult.class);8788 // Get content from the resulting asset(s)89 Asset resultAsset = pdfServicesResponse.getResult().getAsset();90 StreamAsset streamAsset = pdfServices.getContent(resultAsset);9192 // Creates an output stream and copy stream asset's content to it93 Files.createDirectories(Paths.get("output/"));94 OutputStream outputStream = Files.newOutputStream(new File("output/sealedOutput.pdf").toPath());95 LOGGER.info("Saving asset at output/sealedOutput.pdf");96 IOUtils.copy(streamAsset.getInputStream(), outputStream);97 outputStream.close();98 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {99 LOGGER.error("Exception encountered while executing operation", ex);100 }101 }102}103
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ElectronicSeal/4// dotnet run ElectronicSeal.csproj56namespace ElectronicSeal7{8 class Program9 {10 // Initialize the logger.11 private static readonly ILog log = LogManager.GetLogger(typeof(Program));12 static void Main()13 {14 //Configure the logging15 ConfigureLogging();1617 try18 {19 // Initial setup, create credentials instance.20 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()21 .WithClientId("PDF_SERVICES_CLIENT_ID")22 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")23 .Build();2425 // Create an ExecutionContext using credentials.26 ExecutionContext executionContext = ExecutionContext.Create(credentials);2728 //Set the input document to perform the sealing operation29 FileRef sourceFile = FileRef.CreateFromLocalFile(@"SampleInvoice.pdf");3031 //Set the background seal image for signature , if required.32 FileRef sealImageFile = FileRef.CreateFromLocalFile(@"sampleSealImage.png");3334 //Set the Seal Field Name to be created in input PDF document.35 string sealFieldName = "Signature1";3637 //Set the page number in input document for applying seal.38 int sealPageNumber = 1;3940 //Set if seal should be visible or invisible.41 bool sealVisible = true;4243 //Create FieldLocation instance and set the coordinates for applying signature44 FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200);4546 //Create FieldOptions instance with required details.47 FieldOptions sealFieldOptions = new FieldOptions.Builder(sealFieldName)48 .SetVisible(sealVisible)49 .SetFieldLocation(fieldLocation)50 .SetPageNumber(sealPageNumber)51 .Build();5253 //Set the name of TSP Provider being used.54 string providerName = "<PROVIDER_NAME>";5556 //Set the access token to be used to access TSP provider hosted APIs.57 string accessToken = "<ACCESS_TOKEN>";5859 //Set the credential ID.60 string credentialID = "<CREDENTIAL_ID>";6162 //Set the PIN generated while creating credentials.63 string pin = "<PIN>";6465 CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer");6667 //Create CertificateCredentials instance with required certificate details.68 CertificateCredentials certificateCredentials = CertificateCredentials.CSCCredentialBuilder()69 .WithProviderName(providerName)70 .WithCredentialID(credentialID)71 .WithPin(pin)72 .WithCSCAuthContext(cscAuthContext)73 .Build();7475 //Create SealingOptions instance with all the sealing parameters.76 SealOptions sealOptions = new SealOptions.Builder(certificateCredentials, fieldOptions).build();7778 //Create the PDFElectronicSealOperation instance using the PDFElectronicSealOptions instance79 PDFElectronicSealOperation pdfElectronicSealOperation = PDFElectronicSealOperation.CreateNew(sealOptions);8081 //Set the input source file for PDFElectronicSealOperation instance82 pdfElectronicSealOperation.SetInput(sourceFile);8384 //Set the optional input seal image for PDFElectronicSealOperation instance85 pdfElectronicSealOperation.SetSealImage(sealImageFile);8687 //Execute the operation88 FileRef result = pdfElectronicSealOperation.Execute(executionContext);8990 // Save the output at specified location.91 result.SaveAs(output/sealedOutput.pdf);92 }93 catch (ServiceUsageException ex)94 {95 log.Error("Exception encountered while executing operation", ex);96 }97 catch (ServiceApiException ex)98 {99 log.Error("Exception encountered while executing operation", ex);100 }101 catch (SDKException ex)102 {103 log.Error("Exception encountered while executing operation", ex);104 }105 catch (IOException ex)106 {107 log.Error("Exception encountered while executing operation", ex);108 }109 catch (Exception ex)110 {111 log.Error("Exception encountered while executing operation", ex);112 }113114 }115 static void ConfigureLogging()116 {117 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());118 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));119 }120 }121}
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/electronicseal/electronic-seal.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 DocumentLevelPermission,10 FieldLocation,11 FieldOptions,12 CSCAuthContext,13 CSCCredential,14 PDFElectronicSealParams,15 PDFElectronicSealJob,16 PDFElectronicSealResult,17 SDKError,18 ServiceUsageError,19 ServiceApiError20} = require("@adobe/pdfservices-node-sdk");21const fs = require("fs");2223(async () => {24 let sourceFileReadStream;25 let sealImageReadStream;26 try {27 // Initial setup, create credentials instance28 const credentials = new ServicePrincipalCredentials({29 clientId: process.env.PDF_SERVICES_CLIENT_ID,30 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET31 });3233 // Creates a PDF Services instance34 const pdfServices = new PDFServices({credentials});3536 // Creates an asset(s) from source file(s) and upload37 sourceFileReadStream = fs.createReadStream("./sampleInvoice.pdf")38 sealImageReadStream = fs.createReadStream("./sampleSealImage.png");39 const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({40 streamAssets: [{41 readStream: sourceFileReadStream,42 mimeType: MimeType.PDF43 }, {44 readStream: sealImageReadStream,45 mimeType: MimeType.PNG46 }]47 });4849 // Set the document level permission to be applied for output document50 const documentLevelPermission = DocumentLevelPermission.FORM_FILLING;5152 // Set the Seal Field Name to be created in input PDF document53 const sealFieldName = "Signature1";5455 // Set the page number in input document for applying seal56 const sealPageNumber = 1;5758 // Set if seal should be visible or invisible59 const sealVisible = true;6061 // Create FieldLocation instance and set the coordinates for applying signature62 const fieldLocation = new FieldLocation({63 left: 150,64 top: 250,65 right: 350,66 bottom: 20067 });6869 // Create FieldOptions instance with required details70 const sealFieldOptions = new FieldOptions({71 visible: sealVisible,72 location: fieldLocation,73 fieldName: sealFieldName,74 pageNumber: sealPageNumber,75 });7677 // Set the name of TSP Provider being used78 const providerName = "<PROVIDER_NAME>";7980 // Set the access token to be used to access TSP provider hosted APIs81 const accessToken = "<ACCESS_TOKEN>";8283 // Set the credential ID84 const credentialId = "<CREDENTIAL_ID>";8586 // Set the PIN generated while creating credentials87 const pin = "<PIN>";8889 // Create CSCAuthContext instance using access token and token type90 const authorizationContext = new CSCAuthContext({91 accessToken,92 tokenType: "Bearer"93 });9495 // Create CertificateCredentials instance with required certificate details96 const certificateCredentials = new CSCCredential({97 providerName,98 credentialId,99 pin,100 authorizationContext,101 });102103 // Create parameters for the job104 const params = new PDFElectronicSealParams({105 certificateCredentials,106 sealFieldOptions,107 documentLevelPermission,108 });109110 // Creates a new job instance111 const job = new PDFElectronicSealJob({112 inputAsset: sourceFileAsset,113 sealImageAsset,114 params,115 });116117 // Submit the job and get the job result118 const pollingURL = await pdfServices.submit({job});119 const pdfServicesResponse = await pdfServices.getJobResult({120 pollingURL,121 resultType: PDFElectronicSealResult122 });123124 // Get content from the resulting asset(s)125 const resultAsset = pdfServicesResponse.result.asset;126 const streamAsset = await pdfServices.getContent({asset: resultAsset});127128 // Creates a write stream and copy stream asset's content to it129 const outputFilePath = "./sealedOutput.pdf";130 console.log(`Saving asset at ${outputFilePath}`);131132 const writeStream = fs.createWriteStream(outputFilePath);133 streamAsset.readStream.pipe(writeStream);134 } catch (err) {135 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {136 console.log("Exception encountered while executing operation", err);137 } else {138 console.log("Exception encountered while executing operation", err);139 }140 } finally {141 sourceFileReadStream?.destroy();142 sealImageReadStream?.destroy();143 }144})();
Copied to your clipboard1curl --location --request POST 'https://pdf-services.adobe.io/operation/electronicseal' \2--header 'x-api-key: {{Placeholder for client_id}}' \3--header 'Content-Type: application/json' \4--header 'Authorization: Bearer {{Placeholder for token}}' \5--data-raw '{6 "inputDocumentAssetID": "urn:aaid:AS:UE1:23c30ee0-2c4d-xxxx-xxxx-087832fca718",7 "sealImageAssetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-xxxx-xxxx-087832fca718",8 "sealOptions": {9 "signatureFormat": "PKCS7",10 "documentLevelPermission": "FORM_FILLING",11 "cscCredentialOptions": {12 "credentialId": "<CREDENTIAL_ID>",13 "providerName": "<PROVIDER_NAME>",14 "authorizationContext": {15 "tokenType": "Bearer",16 "accessToken": "<ACCESS_TOKEN>"17 },18 "credentialAuthParameters": {19 "pin": "<PIN>"20 }21 },22 "sealFieldOptions": {23 "location": {24 "left": 150,25 "top": 250,26 "right": 350,27 "bottom": 20028 },29 "fieldName": "Signature1",30 "pageNumber": 131 }32 }33}'
Apply Electronic Seal with customized appearance on PDF
The sample below performs electronic seal operation with customized appearance on a given PDF.
Please refer to the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://github.com/adobe/pdfservices-java-sdk-samples/tree/beta2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.electronicseal.ElectronicSealWithAppearanceOptions45package com.adobe.pdfservices.operation.samples.electronicseal;67public class ElectronicSealWithAppearanceOptions {89 // Initialize the logger.10 private static final Logger LOGGER = LoggerFactory.getLogger(ElectronicSealWithAppearanceOptions.class);1112 public static void main(String[] args) {13 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/sampleInvoice.pdf").toPath());14 InputStream inputStreamSealImage = Files.newInputStream(new File("src/main/resources/sampleSealImage.png").toPath())) {15 // Initial setup, create credentials instance16 Credentials credentials = new ServicePrincipalCredentials(17 System.getenv("PDF_SERVICES_CLIENT_ID"),18 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1920 // Creates a PDF Services instance21 PDFServices pdfServices = new PDFServices(credentials);2223 // Creates an asset(s) from source file(s) and upload24 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());25 Asset sealImageAsset = pdfServices.upload(inputStreamSealImage, PDFServicesMediaType.PNG.getMediaType());2627 // Set the document level permission to be applied for output document28 DocumentLevelPermission documentLevelPermission = DocumentLevelPermission.FORM_FILLING;2930 // Create AppearanceOptions and add the required signature display items to it31 AppearanceOptions appearanceOptions = new AppearanceOptions();32 appearanceOptions.addItem(AppearanceItem.NAME);33 appearanceOptions.addItem(AppearanceItem.LABELS);34 appearanceOptions.addItem(AppearanceItem.DATE);35 appearanceOptions.addItem(AppearanceItem.SEAL_IMAGE);36 appearanceOptions.addItem(AppearanceItem.DISTINGUISHED_NAME);373839 // Sets the Seal Field Name to be created in input PDF document.40 String sealFieldName = "Signature1";4142 // Sets the page number in input document for applying seal.43 Integer sealPageNumber = 1;4445 // Sets if seal should be visible or invisible.46 Boolean sealVisible = true;4748 // CreatesFieldLocation instance and set the coordinates for applying signature49 FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200);5051 // Create FieldOptions instance with required details.52 FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName)53 .setFieldLocation(fieldLocation)54 .setPageNumber(sealPageNumber)55 .setVisible(sealVisible)56 .build();5758 // Sets the name of TSP Provider being used.59 String providerName = "<PROVIDER_NAME>";6061 // Sets the access token to be used to access TSP provider hosted APIs.62 String accessToken = "<ACCESS_TOKEN>";6364 // Sets the credential ID.65 String credentialID = "<CREDENTIAL_ID>";6667 // Sets the PIN generated while creating credentials.68 String pin = "<PIN>";6970 // Creates CSCAuthContext instance using access token and token type.71 CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer");7273 // Create CertificateCredentials instance with required certificate details.74 CertificateCredentials certificateCredentials = CertificateCredentials.cscCredentialBuilder()75 .withProviderName(providerName)76 .withCredentialID(credentialID)77 .withPin(pin)78 .withCSCAuthContext(cscAuthContext)79 .build();8081 // Create parameters for the job82 PDFElectronicSealParams pdfElectronicSealParams = PDFElectronicSealParams83 .pdfElectronicSealParamsBuilder(certificateCredentials, fieldOptions)84 .withDocumentLevelPermission(documentLevelPermission)85 .withAppearanceOptions(appearanceOptions)86 .build();8788 // Creates a new job instance89 PDFElectronicSealJob pdfElectronicSealJob = new PDFElectronicSealJob(asset, pdfElectronicSealParams);90 pdfElectronicSealJob.setSealImageAsset(sealImageAsset);9192 // Submit the job and gets the job result93 String location = pdfServices.submit(pdfElectronicSealJob);94 PDFServicesResponse<PDFElectronicSealResult> pdfServicesResponse = pdfServices.getJobResult(location, PDFElectronicSealResult.class);9596 // Get content from the resulting asset(s)97 Asset resultAsset = pdfServicesResponse.getResult().getAsset();98 StreamAsset streamAsset = pdfServices.getContent(resultAsset);99100 // Creates an output stream and copy stream asset's content to it101 Files.createDirectories(Paths.get("output/"));102 OutputStream outputStream = Files.newOutputStream(new File("output/sealedOutput.pdf").toPath());103 LOGGER.info("Saving asset at output/sealedOutput.pdf");104 IOUtils.copy(streamAsset.getInputStream(), outputStream);105 outputStream.close();106 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {107 LOGGER.error("Exception encountered while executing operation", ex);108 }109 }110}111
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ElectronicSealWithAppearanceOptions/4// dotnet run ElectronicSealWithAppearanceOptions.csproj56namespace ElectronicSealWithAppearanceOptions7{8 class Program9 {10 // Initialize the logger.11 private static readonly ILog log = LogManager.GetLogger(typeof(Program));12 static void Main()13 {14 //Configure the logging15 ConfigureLogging();1617 try18 {19 // Initial setup, create credentials instance.20 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()21 .WithClientId("PDF_SERVICES_CLIENT_ID")22 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")23 .Build();242526 // Create an ExecutionContext using credentials.27 ExecutionContext executionContext = ExecutionContext.Create(credentials);2829 //Set the input document to perform the sealing operation30 FileRef sourceFile = FileRef.CreateFromLocalFile(@"SampleInvoice.pdf");3132 //Set the background seal image for signature , if required.33 FileRef sealImageFile = FileRef.CreateFromLocalFile(@"sampleSealImage.png");3435 //Create AppearanceOptions and add the required signature appearance items36 AppearanceOptions appearanceOptions = new AppearanceOptions();37 appearanceOptions.AddItem(AppearanceItem.NAME);38 appearanceOptions.AddItem(AppearanceItem.LABELS);39 appearanceOptions.AddItem(AppearanceItem.DATE);40 appearanceOptions.AddItem(AppearanceItem.SEAL_IMAGE);41 appearanceOptions.AddItem(AppearanceItem.DISTINGUISHED_NAME);4243 //Set the Seal Field Name to be created in input PDF document.44 string sealFieldName = "Signature1";4546 //Set the page number in input document for applying seal.47 int sealPageNumber = 1;4849 //Set if seal should be visible or invisible.50 bool sealVisible = true;5152 //Create FieldLocation instance and set the coordinates for applying signature53 FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200);5455 //Create FieldOptions instance with required details.56 FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName)57 .SetVisible(sealVisible)58 .SetFieldLocation(fieldLocation)59 .SetPageNumber(sealPageNumber)60 .Build();6162 //Set the name of TSP Provider being used.63 string providerName = "<PROVIDER_NAME>";6465 //Set the access token to be used to access TSP provider hosted APIs.66 string accessToken = "<ACCESS_TOKEN>";6768 //Set the credential ID.69 string credentialID = "<CREDENTIAL_ID>";7071 //Set the PIN generated while creating credentials.72 string pin = "<PIN>";7374 CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer");7576 //Create CertificateCredentials instance with required certificate details.77 CertificateCredentials certificateCredentials = CertificateCredentials.CSCCredentialBuilder()78 .WithProviderName(providerName)79 .WithCredentialID(credentialID)80 .WithPin(pin)81 .WithCSCAuthContext(cscAuthContext)82 .Build();838485 //Create SealingOptions instance with all the sealing parameters.86 SealOptions sealOptions = new SealOptions.Builder(certificateCredentials, fieldOptions)87 .WithAppearanceOptions(appearanceOptions).Build();8889 //Create the PDFElectronicSealOperation instance using the SealOptions instance90 PDFElectronicSealOperation pdfElectronicSealOperation = PDFElectronicSealOperation.CreateNew(sealOptions);9192 //Set the input source file for PDFElectronicSealOperation instance93 pdfElectronicSealOperation.SetInput(sourceFile);9495 //Set the optional input seal image for PDFElectronicSealOperation instance96 pdfElectronicSealOperation.SetSealImage(sealImageFile);9798 //Execute the operation99 FileRef result = pdfElectronicSealOperation.Execute(executionContext);100101 // Save the output at specified location.102 result.SaveAs(output/sealedOutput.pdf);103 }104 catch (ServiceUsageException ex)105 {106 log.Error("Exception encountered while executing operation", ex);107 }108 catch (ServiceApiException ex)109 {110 log.Error("Exception encountered while executing operation", ex);111 }112 catch (SDKException ex)113 {114 log.Error("Exception encountered while executing operation", ex);115 }116 catch (IOException ex)117 {118 log.Error("Exception encountered while executing operation", ex);119 }120 catch (Exception ex)121 {122 log.Error("Exception encountered while executing operation", ex);123 }124125 }126 static void ConfigureLogging()127 {128 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());129 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));130 }131 }132}
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/electronicseal/electronic-seal-with-appearance-options.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 FieldLocation,10 FieldOptions,11 CSCAuthContext,12 CSCCredential,13 PDFElectronicSealParams,14 PDFElectronicSealJob,15 PDFElectronicSealResult,16 AppearanceOptions,17 AppearanceItem,18 SDKError,19 ServiceUsageError,20 ServiceApiError, DocumentLevelPermission21} = require("@adobe/pdfservices-node-sdk");22const fs = require("fs");2324(async () => {2526 let sourceFileReadStream;27 let sealImageReadStream;28 try {29 // Initial setup, create credentials instance30 const credentials = new ServicePrincipalCredentials({31 clientId: process.env.PDF_SERVICES_CLIENT_ID,32 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET33 });3435 // Creates a PDF Services instance36 const pdfServices = new PDFServices({credentials});3738 // Creates an asset(s) from source file(s) and upload39 sourceFileReadStream = fs.createReadStream("./sampleInvoice.pdf")40 sealImageReadStream = fs.createReadStream("./sampleSealImage.png");41 const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({42 streamAssets: [{43 readStream: sourceFileReadStream,44 mimeType: MimeType.PDF45 }, {46 readStream: sealImageReadStream,47 mimeType: MimeType.PNG48 }]49 });5051 // Set the document level permission to be applied for output document52 const documentLevelPermission = DocumentLevelPermission.FORM_FILLING;5354 // Create AppearanceOptions and add the required signature appearance items55 const sealAppearanceOptions = new AppearanceOptions({56 items: [57 AppearanceItem.DATE,58 AppearanceItem.SEAL_IMAGE,59 AppearanceItem.NAME,60 AppearanceItem.LABELS,61 AppearanceItem.DISTINGUISHED_NAME62 ]63 });6465 // Set the Seal Field Name to be created in input PDF document66 const sealFieldName = "Signature1";6768 // Set the page number in input document for applying seal69 const sealPageNumber = 1;7071 // Set if seal should be visible or invisible72 const sealVisible = true;7374 // Create FieldLocation instance and set the coordinates for applying signature75 const fieldLocation = new FieldLocation({76 left: 150,77 top: 250,78 right: 350,79 bottom: 20080 });8182 // Create FieldOptions instance with required details83 const sealFieldOptions = new FieldOptions({84 visible: sealVisible,85 location: fieldLocation,86 fieldName: sealFieldName,87 pageNumber: sealPageNumber,88 });8990 // Set the name of TSP Provider being used91 const providerName = "<PROVIDER_NAME>";9293 // Set the access token to be used to access TSP provider hosted APIs94 const accessToken = "<ACCESS_TOKEN>";9596 // Set the credential ID97 const credentialId = "<CREDENTIAL_ID>";9899 // Set the PIN generated while creating credentials100 const pin = "<PIN>";101102 // Create CSCAuthContext instance using access token and token type103 const authorizationContext = new CSCAuthContext({104 accessToken,105 tokenType: "Bearer"106 });107108 // Create CertificateCredentials instance with required certificate details109 const certificateCredentials = new CSCCredential({110 providerName,111 credentialId,112 pin,113 authorizationContext,114 });115116 // Create parameters for the job117 const params = new PDFElectronicSealParams({118 documentLevelPermission119 certificateCredentials,120 sealFieldOptions,121 sealAppearanceOptions122 });123124 // Creates a new job instance125 const job = new PDFElectronicSealJob({126 inputAsset: sourceFileAsset,127 sealImageAsset,128 params,129 });130131 // Submit the job and get the job result132 const pollingURL = await pdfServices.submit({job});133 const pdfServicesResponse = await pdfServices.getJobResult({134 pollingURL,135 resultType: PDFElectronicSealResult136 });137138 // Get content from the resulting asset(s)139 const resultAsset = pdfServicesResponse.result.asset;140 const streamAsset = await pdfServices.getContent({asset: resultAsset});141142 // Creates a write stream and copy stream asset's content to it143 const outputFilePath = "./sealedOutput.pdf";144 console.log(`Saving asset at ${outputFilePath}`);145146 const writeStream = fs.createWriteStream(outputFilePath);147 streamAsset.readStream.pipe(writeStream);148 } catch (err) {149 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {150 console.log("Exception encountered while executing operation", err);151 } else {152 console.log("Exception encountered while executing operation", err);153 }154 } finally {155 sourceFileReadStream?.destroy();156 sealImageReadStream?.destroy();157 }158})();
Copied to your clipboard1curl --location --request POST 'https://pdf-services.adobe.io/operation/electronicseal' \2--header 'x-api-key: {{Placeholder for client_id}}' \3--header 'Content-Type: application/json' \4--header 'Authorization: Bearer {{Placeholder for token}}' \5--data-raw '{6 "inputDocumentAssetID": "urn:aaid:AS:UE1:23c30ee0-2c4d-xxxx-xxxx-087832fca718",7 "sealImageAssetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-xxxx-xxxx-087832fca718",8 "sealOptions": {9 "signatureFormat": "PKCS7",10 "documentLevelPermission": "FORM_FILLING",11 "cscCredentialOptions": {12 "credentialId": "<CREDENTIAL_ID>",13 "providerName": "<PROVIDER_NAME>",14 "authorizationContext": {15 "tokenType": "Bearer",16 "accessToken": "<ACCESS_TOKEN>"17 },18 "credentialAuthParameters": {19 "pin": "<PIN>"20 }21 },22 "sealFieldOptions": {23 "location": {24 "left": 150,25 "top": 250,26 "right": 350,27 "bottom": 20028 },29 "fieldName": "Signature1",30 "pageNumber": 131 },32 "sealAppearanceOptions": {33 "displayOptions": [34 "NAME",35 "DATE",36 "DISTINGUISHED_NAME",37 "LABELS",38 "SEAL_IMAGE"39 ]40 }41 }42}'
Apply Electronic Seal with trusted timestamp on PDF
The sample below performs electronic seal operation with a trusted timestamp on given PDF.
Please refer to the API usage guide to understand how to use our APIs.
Copied to your clipboard1// Get the samples from https://github.com/adobe/pdfservices-java-sdk-samples/tree/beta2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.electronicseal.ElectronicSealWithAppearanceOptions45package com.adobe.pdfservices.operation.samples.electronicseal;67public class ElectronicSealWithTimeStampAuthority {89 // Initialize the logger.10 private static final Logger LOGGER = LoggerFactory.getLogger(ElectronicSealWithTimeStampAuthority.class);1112 public static void main(String[] args) {13 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/sampleInvoice.pdf").toPath());14 InputStream inputStreamSealImage = Files.newInputStream(new File("src/main/resources/sampleSealImage.png").toPath())) {1516 // Initial setup, create credentials instance17 Credentials credentials = new ServicePrincipalCredentials(18 System.getenv("PDF_SERVICES_CLIENT_ID"),19 System.getenv("PDF_SERVICES_CLIENT_SECRET"));2021 // Creates a PDF Services instance22 PDFServices pdfServices = new PDFServices(credentials);2324 // Creates an asset(s) from source file(s) and upload25 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());26 Asset sealImageAsset = pdfServices.upload(inputStreamSealImage, PDFServicesMediaType.PNG.getMediaType());2728 // Set the document level permission to be applied for output document29 DocumentLevelPermission documentLevelPermission = DocumentLevelPermission.FORM_FILLING;3031 // Sets the Seal Field Name to be created in input PDF document.32 String sealFieldName = "Signature1";3334 // Sets the page number in input document for applying seal.35 Integer sealPageNumber = 1;3637 // Sets if seal should be visible or invisible.38 Boolean sealVisible = true;3940 //Creates FieldLocation instance and set the coordinates for applying signature41 FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200);4243 //Create FieldOptions instance with required details.44 FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName)45 .setFieldLocation(fieldLocation)46 .setPageNumber(sealPageNumber)47 .setVisible(sealVisible)48 .build();4950 // Sets the name of TSP Provider being used.51 String providerName = "<PROVIDER_NAME>";5253 // Sets the access token to be used to access TSP provider hosted APIs.54 String accessToken = "<ACCESS_TOKEN>";5556 // Sets the credential ID.57 String credentialID = "<CREDENTIAL_ID>";5859 // Sets the PIN generated while creating credentials.60 String pin = "<PIN>";6162 //Creates CSCAuthContext instance using access token and token type.63 CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer");6465 //Create CertificateCredentials instance with required certificate details.66 CertificateCredentials certificateCredentials = CertificateCredentials.cscCredentialBuilder()67 .withProviderName(providerName)68 .withCredentialID(credentialID)69 .withPin(pin)70 .withCSCAuthContext(cscAuthContext)71 .build();7273 //Create TSABasicAuthCredentials using username and password74 TSABasicAuthCredentials tsaBasicAuthCredentials = new TSABasicAuthCredentials("<USERNAME>", "<PASSWORD>");7576 // Set the Time Stamp Authority Options using url and TSA Auth credentials77 TSAOptions tsaOptions = new RFC3161TSAOptions("<TIMESTAMP_URL>", tsaBasicAuthCredentials);7879 // Create parameters for the job80 PDFElectronicSealParams pdfElectronicSealParams = PDFElectronicSealParams.pdfElectronicSealParamsBuilder(certificateCredentials, fieldOptions)81 .withDocumentLevelPermission(documentLevelPermission)82 .withTSAOptions(tsaOptions)83 .build();8485 // Creates a new job instance86 PDFElectronicSealJob pdfElectronicSealJob = new PDFElectronicSealJob(asset, pdfElectronicSealParams);8788 // Sets the optional input seal image for PDFElectronicSealOperation instance89 pdfElectronicSealJob.setSealImageAsset(sealImageAsset);9091 // Submit the job and gets the job result92 String location = pdfServices.submit(pdfElectronicSealJob);93 PDFServicesResponse<PDFElectronicSealResult> pdfServicesResponse = pdfServices.getJobResult(location, PDFElectronicSealResult.class);9495 // Get content from the resulting asset(s)96 Asset resultAsset = pdfServicesResponse.getResult().getAsset();97 StreamAsset streamAsset = pdfServices.getContent(resultAsset);9899 // Creates an output stream and copy stream asset's content to it100 Files.createDirectories(Paths.get("output/"));101 OutputStream outputStream = Files.newOutputStream(new File("output/sealedOutput.pdf").toPath());102 LOGGER.info("Saving asset at output/sealedOutput.pdf");103 IOUtils.copy(streamAsset.getInputStream(), outputStream);104 outputStream.close();105 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {106 LOGGER.error("Exception encountered while executing operation", ex);107 }108 }109}110
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/electronicseal/electronic-seal-with-stamp-authority.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 FieldLocation,10 FieldOptions,11 CSCAuthContext,12 CSCCredential,13 PDFElectronicSealParams,14 PDFElectronicSealJob,15 PDFElectronicSealResult,16 DocumentLevelPermission,17 TSABasicAuthCredentials,18 RFC3161TSAOptions,19 SDKError,20 ServiceUsageError,21 ServiceApiError,22} = require("@adobe/pdfservices-node-sdk");23const fs = require("fs");2425(async () => {2627 let sourceFileReadStream;28 let sealImageReadStream;29 try {30 // Initial setup, create credentials instance31 const credentials = new ServicePrincipalCredentials({32 clientId: process.env.PDF_SERVICES_CLIENT_ID,33 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET34 });3536 // Creates a PDF Services instance37 const pdfServices = new PDFServices({credentials});3839 // Creates an asset(s) from source file(s) and upload40 sourceFileReadStream = fs.createReadStream("./sampleInvoice.pdf")41 sealImageReadStream = fs.createReadStream("./sampleSealImage.png");42 const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({43 streamAssets: [{44 readStream: sourceFileReadStream,45 mimeType: MimeType.PDF46 }, {47 readStream: sealImageReadStream,48 mimeType: MimeType.PNG49 }]50 });5152 // Set the document level permission to be applied for output document53 const documentLevelPermission = DocumentLevelPermission.FORM_FILLING;5455 // Set the Seal Field Name to be created in input PDF document56 const sealFieldName = "Signature1";5758 // Set the page number in input document for applying seal59 const sealPageNumber = 1;6061 // Set if seal should be visible or invisible62 const sealVisible = true;6364 // Create FieldLocation instance and set the coordinates for applying signature65 const fieldLocation = new FieldLocation({66 left: 150,67 top: 250,68 right: 350,69 bottom: 20070 });7172 // Create FieldOptions instance with required details73 const sealFieldOptions = new FieldOptions({74 visible: sealVisible,75 location: fieldLocation,76 fieldName: sealFieldName,77 pageNumber: sealPageNumber,78 });7980 // Set the name of TSP Provider being used81 const providerName = "<PROVIDER_NAME>";8283 // Set the access token to be used to access TSP provider hosted APIs84 const accessToken = "<ACCESS_TOKEN>";8586 // Set the credential ID87 const credentialId = "<CREDENTIAL_ID>";8889 // Set the PIN generated while creating credentials90 const pin = "<PIN>";9192 // Create CSCAuthContext instance using access token and token type93 const authorizationContext = new CSCAuthContext({94 accessToken,95 tokenType: "Bearer"96 });9798 // Create CertificateCredentials instance with required certificate details99 const certificateCredentials = new CSCCredential({100 providerName,101 credentialId,102 pin,103 authorizationContext,104 });105106 // Create TSABasicAuthCredentials using username and password107 const tsaBasicAuthCredentials = new TSABasicAuthCredentials({108 username: "<USERNAME>",109 password: "<PASSWORD>"110 });111112 // Set the Time Stamp Authority Options using url and TSA Auth credentials113 const tsaOptions = new RFC3161TSAOptions({114 url: "<TIMESTAMP_URL>",115 credentialAuthParameters: tsaBasicAuthCredentials116 });117118 // Create parameters for the job119 const params = new PDFElectronicSealParams({120 documentLevelPermission,121 certificateCredentials,122 sealFieldOptions,123 tsaOptions124 });125126 // Creates a new job instance127 const job = new PDFElectronicSealJob({128 inputAsset: sourceFileAsset,129 sealImageAsset,130 params,131 });132133 // Submit the job and get the job result134 const pollingURL = await pdfServices.submit({job});135 const pdfServicesResponse = await pdfServices.getJobResult({136 pollingURL,137 resultType: PDFElectronicSealResult138 });139140 // Get content from the resulting asset(s)141 const resultAsset = pdfServicesResponse.result.asset;142 const streamAsset = await pdfServices.getContent({asset: resultAsset});143144 // Creates a write stream and copy stream asset's content to it145 const outputFilePath = "./sealedOutput.pdf";146 console.log(`Saving asset at ${outputFilePath}`);147148 const writeStream = fs.createWriteStream(outputFilePath);149 streamAsset.readStream.pipe(writeStream);150 } catch (err) {151 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {152 console.log("Exception encountered while executing operation", err);153 } else {154 console.log("Exception encountered while executing operation", err);155 }156 } finally {157 sourceFileReadStream?.destroy();158 sealImageReadStream?.destroy();159 }160})();
Copied to your clipboard1curl --location --request POST 'https://pdf-services.adobe.io/operation/electronicseal' \2--header 'x-api-key: {{Placeholder for client_id}}' \3--header 'Content-Type: application/json' \4--header 'Authorization: Bearer {{Placeholder for token}}' \5--data-raw '{6 "inputDocumentAssetID": "urn:aaid:AS:UE1:23c30ee0-2c4d-xxxx-xxxx-087832fca718",7 "sealImageAssetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-xxxx-xxxx-087832fca718",8 "sealOptions": {9 "signatureFormat": "PKCS7",10 "documentLevelPermission": "FORM_FILLING",11 "cscCredentialOptions": {12 "credentialId": "<CREDENTIAL_ID>",13 "providerName": "<PROVIDER_NAME>",14 "authorizationContext": {15 "tokenType": "Bearer",16 "accessToken": "<ACCESS_TOKEN>"17 },18 "credentialAuthParameters": {19 "pin": "<PIN>"20 }21 },22 "tsaOptions": {23 "url" : "<TIMESTAMP_URL>",24 "credentialAuthParameters": {25 "username" : "<USERNAME>",26 "password" : "<PASSWORD>"27 },28 "sealFieldOptions": {29 "location": {30 "left": 150,31 "top": 250,32 "right": 350,33 "bottom": 20034 },35 "fieldName": "Signature1",36 "pageNumber": 137 },38 "sealAppearanceOptions": {39 "displayOptions": [40 "NAME",41 "DATE",42 "DISTINGUISHED_NAME",43 "LABELS",44 "SEAL_IMAGE"45 ]46 }47 }48}'