Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/vaarundev_dotnet4.0…
Browse files Browse the repository at this point in the history
….0' into faqs_dotnet4
  • Loading branch information
mahour committed Jul 12, 2024
2 parents 8995b6d + 976787e commit 4dc1bb8
Show file tree
Hide file tree
Showing 51 changed files with 3,850 additions and 2,584 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
GATSBY_FEDS_PRIVACY_ID: ${{ secrets.AIO_FEDS_PRIVACY_ID }}
NODE_OPTIONS: "--max_old_space_size=8192"
- name: Deploy
uses: icaraps/static-website-deploy@master
uses: AdobeDocs/static-website-deploy@master
with:
enabled-static-website: 'true'
source: 'public'
Expand Down Expand Up @@ -253,7 +253,7 @@ jobs:
GATSBY_FEDS_PRIVACY_ID: ${{ secrets.AIO_FEDS_PRIVACY_ID }}
NODE_OPTIONS: "--max_old_space_size=8192"
- name: Deploy
uses: icaraps/static-website-deploy@master
uses: AdobeDocs/static-website-deploy@master
with:
enabled-static-website: 'true'
source: 'public'
Expand Down
6 changes: 4 additions & 2 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ export const onRouteUpdate = ({ location, prevLocation }) => {
) {
pageHeadTittle = "PDF Electronic Seal API Prerequisites";
}
}else if (window.location.pathname.indexOf("overview/") >= 0) {
} else if (
window.location.pathname.indexOf("overview/") >= 0
) {
pageHeadTittle = "Overview Introduction";
}
}
if (pageHeadTittle != null) {
document
.querySelector("footer")
Expand Down
4 changes: 4 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ module.exports = {
{
title: 'PDF Electronic Seal',
path: 'overview/pdf-services-api/howtos/electronic-seal-api.md'
},
{
title: 'PDF Watermark',
path: 'overview/pdf-services-api/howtos/pdf-watermark-api.md'
}
]
}
Expand Down
319 changes: 174 additions & 145 deletions src/pages/overview/document-generation-api/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentMergeResult> pdfServicesResponse =
pdfServices.GetJobResult<DocumentMergeResult>(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
Expand Down Expand Up @@ -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\": \"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{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\": \"<b>Quantity</b>:{{quantity}}, <b>Description</b>:{{description}}, <b>Amount</b>:{{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<DocumentMergeResult> pdfServicesResponse =
pdfServices.GetJobResult<DocumentMergeResult>(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
Expand Down
Loading

0 comments on commit 4dc1bb8

Please sign in to comment.