From 3c9be641a0b061fcae6f76455e930e53be54f028 Mon Sep 17 00:00:00 2001 From: Varun Kumar Date: Thu, 27 Jun 2024 12:34:48 +0530 Subject: [PATCH] Merge and Eseal How tos --- .../document-generation-api/gettingstarted.md | 319 ++++++++++-------- .../howtos/electronic-seal-api.md | 240 +++++++------ 2 files changed, 306 insertions(+), 253 deletions(-) diff --git a/src/pages/overview/document-generation-api/gettingstarted.md b/src/pages/overview/document-generation-api/gettingstarted.md index d29de4f2d..51fb3591d 100644 --- a/src/pages/overview/document-generation-api/gettingstarted.md +++ b/src/pages/overview/document-generation-api/gettingstarted.md @@ -213,74 +213,88 @@ Please refer the [API usage guide](../pdf-services-api/howtos/api-usage.md) to u // cd MergeDocumentToPDF/ // dotnet run MergeDocumentToPDF.csproj - namespace MergeDocumentToPDF - { - class Program - { - private static readonly ILog log = LogManager.GetLogger(typeof(Program)); - - static void Main() - { - //Configure the logging. - ConfigureLogging(); - try - { - // Initial setup, create credentials instance. - Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder() - .WithClientId("PDF_SERVICES_CLIENT_ID") - .WithClientSecret("PDF_SERVICES_CLIENT_SECRET") - .Build(); - - // Create an ExecutionContext using credentials. - ExecutionContext executionContext = ExecutionContext.Create(credentials); - - // Setup input data for the document merge process. - JObject jsonDataForMerge = JObject.Parse("{\"customerName\": \"Kane Miller\",\"customerVisits\": 100}"); - - // Create a new DocumentMerge Options instance. - DocumentMergeOptions documentMergeOptions = new DocumentMergeOptions(jsonDataForMerge, OutputFormat.PDF); - - // Create a new DocumentMerge Operation instance with the DocumentMerge Options instance. - DocumentMergeOperation documentMergeOperation = DocumentMergeOperation.CreateNew(documentMergeOptions); - - // Set the operation input document template from a source file. - documentMergeOperation.SetInput(FileRef.CreateFromLocalFile(@"documentMergeTemplate.docx")); - - // Execute the operation. - FileRef result = documentMergeOperation.Execute(executionContext); - - // Save the result to the specified location. - result.SaveAs(Directory.GetCurrentDirectory() + "/output/documentMergeOutput.pdf"); - } - catch (ServiceUsageException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (ServiceApiException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (SDKException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (IOException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (Exception ex) - { - log.Error("Exception encountered while executing operation", ex); - } - } - - static void ConfigureLogging() - { - ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); - XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); - } - } - } + +namespace MergeDocumentToPDF +{ + class Program + { + private static readonly ILog log = LogManager.GetLogger(typeof(Program)); + + static void Main() + { + //Configure the logging + ConfigureLogging(); + try + { + // Initial setup, create credentials instance + ICredentials credentials = new ServicePrincipalCredentials( + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"), + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET")); + + // Creates a PDF Services instance + PDFServices pdfServices = new PDFServices(credentials); + + // Creates an asset from source file and upload + using Stream inputStream = File.OpenRead(@"documentMergeTemplate.docx"); + IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.DOCX.GetMIMETypeValue()); + + // Setup input data for the document merge process + JObject jsonDataForMerge = JObject.Parse("{\"customerName\": \"Kane Miller\",\"customerVisits\": 100}"); + + // Create parameters for the job + DocumentMergeParams documentMergeParams = DocumentMergeParams.DocumentMergeParamsBuilder() + .WithJsonDataForMerge(jsonDataForMerge) + .WithOutputFormat(OutputFormat.PDF) + .Build(); + + // Creates a new job instance + DocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams); + + // Submits the job and gets the job result + String location = pdfServices.Submit(documentMergeJob); + PDFServicesResponse pdfServicesResponse = + pdfServices.GetJobResult(location, typeof(DocumentMergeResult)); + + // Get content from the resulting asset(s) + IAsset resultAsset = pdfServicesResponse.Result.Asset; + StreamAsset streamAsset = pdfServices.GetContent(resultAsset); + + // Creating output streams and copying stream asset's content to it + String outputFilePath = "/output/documentMergeOutput.pdf"; + new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create(); + Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath); + streamAsset.Stream.CopyTo(outputStream); + outputStream.Close(); + } + catch (ServiceUsageException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (ServiceApiException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (SDKException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (IOException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (Exception ex) + { + log.Error("Exception encountered while executing operation", ex); + } + } + + static void ConfigureLogging() + { + ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); + XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); + } + } +} ``` ##### Node JS @@ -634,92 +648,107 @@ Please refer the [API usage guide](../pdf-services-api/howtos/api-usage.md) to u ```javascript // Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples // Run the sample: -// cd MergeDocumentToDocx/ +// cd MergeDocumentToDocxFragments/ // dotnet run MergeDocumentToDocxFragments.csproj - namespace MergeDocumentToDocxFragments + +namespace MergeDocumentToDocxFragments +{ + class Program { - class Program + private static readonly ILog log = LogManager.GetLogger(typeof(Program)); + + static void Main() { - private static readonly ILog log = LogManager.GetLogger(typeof(Program)); - - static void Main() + //Configure the logging + ConfigureLogging(); + try { - //Configure the logging - ConfigureLogging(); - try - { - // Initial setup, create credentials instance. - Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder() - .WithClientId("PDF_SERVICES_CLIENT_ID") - .WithClientSecret("PDF_SERVICES_CLIENT_SECRET") - .Build(); - - // Create an ExecutionContext using credentials. - ExecutionContext executionContext = ExecutionContext.Create(credentials); - - // Setup input data for the document merge process - var content = File.ReadAllText(@"orderDetail.json"); - JObject jsonDataForMerge = JObject.Parse(content); - - // Fragment one - JObject obj1 = JObject.Parse("{\"orderDetails\": \"Quantity:{{quantity}}, Description:{{description}}, Amount:{{amount}}\"}"); - - // Fragment two - JObject obj2 = JObject.Parse("{\"customerDetails\": \"{{customerName}}, Visits: {{customerVisits}}\"}"); - - // Fragment Object - Fragments fragments = new Fragments(); - - // Adding Fragments to the Fragment object - fragments.AddFragment(obj1); - fragments.AddFragment(obj2); - - - - // Create a new DocumentMerge Options instance with fragment - DocumentMergeOptions documentMergeOptions = new DocumentMergeOptions(jsonDataForMerge, OutputFormat.DOCX, fragments); - - // Create a new DocumentMerge Operation instance with the DocumentMerge Options instance - DocumentMergeOperation documentMergeOperation = DocumentMergeOperation.CreateNew(documentMergeOptions); - - // Set the operation input document template from a source file. - documentMergeOperation.SetInput(FileRef.CreateFromLocalFile(@"orderDetailTemplate.docx")); - - // Execute the operation. - FileRef result = documentMergeOperation.Execute(executionContext); - - // Save the result to the specified location - result.SaveAs(Directory.GetCurrentDirectory() + "/output/orderDetailOutput.docx"); - } - catch (ServiceUsageException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (ServiceApiException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (SDKException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (IOException ex) - { - log.Error("Exception encountered while executing operation", ex); - } - catch (Exception ex) - { - log.Error("Exception encountered while executing operation", ex); - } + // Initial setup, create credentials instance + ICredentials credentials = new ServicePrincipalCredentials( + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"), + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET")); + + // Creates a PDF Services instance + PDFServices pdfServices = new PDFServices(credentials); + + // Creates an asset from source file and upload + using Stream inputStream = File.OpenRead(@"orderDetailTemplate.docx"); + IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.DOCX.GetMIMETypeValue()); + + // Setup input data for the document merge process + String content = File.ReadAllText(@"orderDetail.json"); + JObject jsonDataForMerge = JObject.Parse(content); + + // Fragment one + JObject obj1 = + JObject.Parse( + "{\"orderDetails\": \"Quantity:{{quantity}}, Description:{{description}}, Amount:{{amount}}\"}"); + + // Fragment two + JObject obj2 = JObject.Parse("{\"customerDetails\": \"{{customerName}}, Visits: {{customerVisits}}\"}"); + + // Fragment Object + Fragments fragments = new Fragments(); + + // Adding Fragments to the Fragment object + fragments.AddFragment(obj1); + fragments.AddFragment(obj2); + + // Create parameters for the job + DocumentMergeParams documentMergeParams = DocumentMergeParams.DocumentMergeParamsBuilder() + .WithJsonDataForMerge(jsonDataForMerge) + .WithOutputFormat(OutputFormat.DOCX) + .WithFragments(fragments) + .Build(); + + // Creates a new job instance + DocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams); + + // Submits the job and gets the job result + String location = pdfServices.Submit(documentMergeJob); + PDFServicesResponse pdfServicesResponse = + pdfServices.GetJobResult(location, typeof(DocumentMergeResult)); + + // Get content from the resulting asset(s) + IAsset resultAsset = pdfServicesResponse.Result.Asset; + StreamAsset streamAsset = pdfServices.GetContent(resultAsset); + + // Creating output streams and copying stream asset's content to it + String outputFilePath = "/output/orderDetailOutput.docx"; + new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create(); + Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath); + streamAsset.Stream.CopyTo(outputStream); + outputStream.Close(); } - - static void ConfigureLogging() + catch (ServiceUsageException ex) { - ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); - XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); + log.Error("Exception encountered while executing operation", ex); } + catch (ServiceApiException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (SDKException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (IOException ex) + { + log.Error("Exception encountered while executing operation", ex); + } + catch (Exception ex) + { + log.Error("Exception encountered while executing operation", ex); + } + } + + static void ConfigureLogging() + { + ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); + XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); } } +} ``` ##### Node JS diff --git a/src/pages/overview/pdf-electronic-seal-api/howtos/electronic-seal-api.md b/src/pages/overview/pdf-electronic-seal-api/howtos/electronic-seal-api.md index 4357bfb93..4c46bca67 100644 --- a/src/pages/overview/pdf-electronic-seal-api/howtos/electronic-seal-api.md +++ b/src/pages/overview/pdf-electronic-seal-api/howtos/electronic-seal-api.md @@ -285,6 +285,7 @@ namespace ElectronicSeal { // Initialize the logger. private static readonly ILog log = LogManager.GetLogger(typeof(Program)); + static void Main() { //Configure the logging @@ -292,79 +293,91 @@ namespace ElectronicSeal try { - // Initial setup, create credentials instance. - Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder() - .WithClientId("PDF_SERVICES_CLIENT_ID") - .WithClientSecret("PDF_SERVICES_CLIENT_SECRET") - .Build(); + // Initial setup, create credentials instance + ICredentials credentials = new ServicePrincipalCredentials( + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"), + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET")); - // Create an ExecutionContext using credentials. - ExecutionContext executionContext = ExecutionContext.Create(credentials); + // Creates a PDF Services instance + PDFServices pdfServices = new PDFServices(credentials); - //Set the input document to perform the sealing operation - FileRef sourceFile = FileRef.CreateFromLocalFile(@"SampleInvoice.pdf"); + // Creates an asset(s) from source file(s) and upload + using Stream inputStream = File.OpenRead(@"SampleInvoice.pdf"); + using Stream inputStreamSealImage = File.OpenRead(@"sampleSealImage.png"); + IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue()); + IAsset sealImageAsset = + pdfServices.Upload(inputStreamSealImage, PDFServicesMediaType.PNG.GetMIMETypeValue()); - //Set the background seal image for signature , if required. - FileRef sealImageFile = FileRef.CreateFromLocalFile(@"sampleSealImage.png"); + // Set the document level permission to be applied for output document + DocumentLevelPermission documentLevelPermission = DocumentLevelPermission.FORM_FILLING; - //Set the Seal Field Name to be created in input PDF document. - string sealFieldName = "Signature1"; + // Sets the Seal Field Name to be created in input PDF document. + String sealFieldName = "Signature1"; - //Set the page number in input document for applying seal. + // Sets the page number in input document for applying seal. int sealPageNumber = 1; - //Set if seal should be visible or invisible. + // Sets if seal should be visible or invisible. bool sealVisible = true; - //Create FieldLocation instance and set the coordinates for applying signature + // Creates FieldLocation instance and set the coordinates for applying signature FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200); - //Create FieldOptions instance with required details. - FieldOptions sealFieldOptions = new FieldOptions.Builder(sealFieldName) - .SetVisible(sealVisible) - .SetFieldLocation(fieldLocation) - .SetPageNumber(sealPageNumber) - .Build(); + // Create FieldOptions instance with required details. + FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName) + .SetVisible(sealVisible) + .SetFieldLocation(fieldLocation) + .SetPageNumber(sealPageNumber) + .Build(); - //Set the name of TSP Provider being used. - string providerName = ""; + // Sets the name of TSP Provider being used. + String providerName = ""; - //Set the access token to be used to access TSP provider hosted APIs. - string accessToken = ""; + // Sets the access token to be used to access TSP provider hosted APIs. + String accessToken = ""; - //Set the credential ID. - string credentialID = ""; + // Sets the credential ID. + String credentialID = ""; - //Set the PIN generated while creating credentials. - string pin = ""; + // Sets the PIN generated while creating credentials. + String pin = ""; + // Creates CSCAuthContext instance using access token and token type. CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer"); - //Create CertificateCredentials instance with required certificate details. + // Create CertificateCredentials instance with required certificate details. CertificateCredentials certificateCredentials = CertificateCredentials.CSCCredentialBuilder() - .WithProviderName(providerName) - .WithCredentialID(credentialID) - .WithPin(pin) - .WithCSCAuthContext(cscAuthContext) - .Build(); - - //Create SealingOptions instance with all the sealing parameters. - SealOptions sealOptions = new SealOptions.Builder(certificateCredentials, fieldOptions).build(); - - //Create the PDFElectronicSealOperation instance using the PDFElectronicSealOptions instance - PDFElectronicSealOperation pdfElectronicSealOperation = PDFElectronicSealOperation.CreateNew(sealOptions); - - //Set the input source file for PDFElectronicSealOperation instance - pdfElectronicSealOperation.SetInput(sourceFile); - - //Set the optional input seal image for PDFElectronicSealOperation instance - pdfElectronicSealOperation.SetSealImage(sealImageFile); - - //Execute the operation - FileRef result = pdfElectronicSealOperation.Execute(executionContext); + .WithProviderName(providerName) + .WithCredentialID(credentialID) + .WithPin(pin) + .WithCSCAuthContext(cscAuthContext) + .Build(); - // Save the output at specified location. - result.SaveAs(output/sealedOutput.pdf); + // Create parameters for the job + PDFElectronicSealParams pdfElectronicSealParams = + PDFElectronicSealParams.PDFElectronicSealParamsBuilder(certificateCredentials, fieldOptions) + .WithDocumentLevelPermission(documentLevelPermission) + .Build(); + + // Creates a new job instance + PDFElectronicSealJob pdfElectronicSealJob = new PDFElectronicSealJob(asset, pdfElectronicSealParams); + pdfElectronicSealJob.SetSealImageAsset(sealImageAsset); + + // Submits the job and gets the job result + String location = pdfServices.Submit(pdfElectronicSealJob); + PDFServicesResponse pdfServicesResponse = + pdfServices.GetJobResult(location, typeof(PDFElectronicSealResult)); + + // Get content from the resulting asset(s) + IAsset resultAsset = pdfServicesResponse.Result.Asset; + StreamAsset streamAsset = pdfServices.GetContent(resultAsset); + + // Creating output streams and copying stream asset's content to it + String outputFilePath = "/output/sealedOutput.pdf"; + new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create(); + Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath); + streamAsset.Stream.CopyTo(outputStream); + outputStream.Close(); } catch (ServiceUsageException ex) { @@ -386,8 +399,8 @@ namespace ElectronicSeal { log.Error("Exception encountered while executing operation", ex); } - } + static void ConfigureLogging() { ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); @@ -829,10 +842,11 @@ public class ElectronicSealWithAppearanceOptions { namespace ElectronicSealWithAppearanceOptions { - class Program + class Program { // Initialize the logger. private static readonly ILog log = LogManager.GetLogger(typeof(Program)); + static void Main() { //Configure the logging @@ -840,23 +854,22 @@ namespace ElectronicSealWithAppearanceOptions try { - // Initial setup, create credentials instance. - Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder() - .WithClientId("PDF_SERVICES_CLIENT_ID") - .WithClientSecret("PDF_SERVICES_CLIENT_SECRET") - .Build(); - - - // Create an ExecutionContext using credentials. - ExecutionContext executionContext = ExecutionContext.Create(credentials); - - //Set the input document to perform the sealing operation - FileRef sourceFile = FileRef.CreateFromLocalFile(@"SampleInvoice.pdf"); - - //Set the background seal image for signature , if required. - FileRef sealImageFile = FileRef.CreateFromLocalFile(@"sampleSealImage.png"); - - //Create AppearanceOptions and add the required signature appearance items + // Initial setup, create credentials instance + ICredentials credentials = new ServicePrincipalCredentials( + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"), + Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET")); + + // Creates a PDF Services instance + PDFServices pdfServices = new PDFServices(credentials); + + // Creates an asset(s) from source file(s) and upload + using Stream inputStream = File.OpenRead(@"SampleInvoice.pdf"); + using Stream inputStreamSealImage = File.OpenRead(@"sampleSealImage.png"); + IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue()); + IAsset sealImageAsset = + pdfServices.Upload(inputStreamSealImage, PDFServicesMediaType.PNG.GetMIMETypeValue()); + + // Create AppearanceOptions and add the required signature display items to it AppearanceOptions appearanceOptions = new AppearanceOptions(); appearanceOptions.AddItem(AppearanceItem.NAME); appearanceOptions.AddItem(AppearanceItem.LABELS); @@ -864,66 +877,77 @@ namespace ElectronicSealWithAppearanceOptions appearanceOptions.AddItem(AppearanceItem.SEAL_IMAGE); appearanceOptions.AddItem(AppearanceItem.DISTINGUISHED_NAME); - //Set the Seal Field Name to be created in input PDF document. - string sealFieldName = "Signature1"; + // Set the document level permission to be applied for output document + DocumentLevelPermission documentLevelPermission = DocumentLevelPermission.FORM_FILLING; - //Set the page number in input document for applying seal. + // Sets the Seal Field Name to be created in input PDF document. + String sealFieldName = "Signature1"; + + // Sets the page number in input document for applying seal. int sealPageNumber = 1; - //Set if seal should be visible or invisible. + // Sets if seal should be visible or invisible. bool sealVisible = true; - //Create FieldLocation instance and set the coordinates for applying signature + // Creates FieldLocation instance and set the coordinates for applying signature FieldLocation fieldLocation = new FieldLocation(150, 250, 350, 200); - - //Create FieldOptions instance with required details. + + // Create FieldOptions instance with required details. FieldOptions fieldOptions = new FieldOptions.Builder(sealFieldName) .SetVisible(sealVisible) .SetFieldLocation(fieldLocation) .SetPageNumber(sealPageNumber) .Build(); - //Set the name of TSP Provider being used. - string providerName = ""; + // Sets the name of TSP Provider being used. + String providerName = ""; - //Set the access token to be used to access TSP provider hosted APIs. - string accessToken = ""; + // Sets the access token to be used to access TSP provider hosted APIs. + String accessToken = ""; - //Set the credential ID. - string credentialID = ""; + // Sets the credential ID. + String credentialID = ""; - //Set the PIN generated while creating credentials. - string pin = ""; + // Sets the PIN generated while creating credentials. + String pin = ""; + // Creates CSCAuthContext instance using access token and token type. CSCAuthContext cscAuthContext = new CSCAuthContext(accessToken, "Bearer"); - //Create CertificateCredentials instance with required certificate details. + // Create CertificateCredentials instance with required certificate details. CertificateCredentials certificateCredentials = CertificateCredentials.CSCCredentialBuilder() .WithProviderName(providerName) .WithCredentialID(credentialID) .WithPin(pin) .WithCSCAuthContext(cscAuthContext) .Build(); - - - //Create SealingOptions instance with all the sealing parameters. - SealOptions sealOptions = new SealOptions.Builder(certificateCredentials, fieldOptions) - .WithAppearanceOptions(appearanceOptions).Build(); - - //Create the PDFElectronicSealOperation instance using the SealOptions instance - PDFElectronicSealOperation pdfElectronicSealOperation = PDFElectronicSealOperation.CreateNew(sealOptions); - - //Set the input source file for PDFElectronicSealOperation instance - pdfElectronicSealOperation.SetInput(sourceFile); - //Set the optional input seal image for PDFElectronicSealOperation instance - pdfElectronicSealOperation.SetSealImage(sealImageFile); - - //Execute the operation - FileRef result = pdfElectronicSealOperation.Execute(executionContext); - - // Save the output at specified location. - result.SaveAs(output/sealedOutput.pdf); + // Create parameters for the job + PDFElectronicSealParams pdfElectronicSealParams = + PDFElectronicSealParams.PDFElectronicSealParamsBuilder(certificateCredentials, fieldOptions) + .WithDocumentLevelPermission(documentLevelPermission) + .WithAppearanceOptions(appearanceOptions) + .Build(); + + // Creates a new job instance + PDFElectronicSealJob pdfElectronicSealJob = new PDFElectronicSealJob(asset, pdfElectronicSealParams); + pdfElectronicSealJob.SetSealImageAsset(sealImageAsset); + + // Submits the job and gets the job result + String location = pdfServices.Submit(pdfElectronicSealJob); + PDFServicesResponse pdfServicesResponse = + pdfServices.GetJobResult(location, typeof(PDFElectronicSealResult)); + + // Get content from the resulting asset(s) + IAsset resultAsset = pdfServicesResponse.Result.Asset; + StreamAsset streamAsset = pdfServices.GetContent(resultAsset); + + // Creating output streams and copying stream asset's content to it + String outputFilePath = "/output/sealedOutput.pdf"; + new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create(); + Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath); + streamAsset.Stream.CopyTo(outputStream); + outputStream.Close(); } catch (ServiceUsageException ex) { @@ -945,8 +969,8 @@ namespace ElectronicSealWithAppearanceOptions { log.Error("Exception encountered while executing operation", ex); } - } + static void ConfigureLogging() { ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());