Skip to content

Commit

Permalink
Update : Code sample - PDF Watermark , Check PDF Accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesh66085 committed Nov 4, 2024
1 parent ff5f434 commit 1f83cd4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 127 deletions.
53 changes: 14 additions & 39 deletions src/pages/apis/pdf-services/check-pdf-accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/accessib
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Placeholder for token}}' \
--data-raw '{
"assetID": "urn:aaid:AS:UE1:54cbf87f-d7f5-4918-8e4b-9f1878678e68",
"pageStart":1,
"pageEnd":5
"assetID": "urn:aaid:AS:UE1:54cbf87f-d7f5-4918-8e4b-9f1878678e68"
}'
```
#### Node js

```js
// Get the samples from https://github.com/adobe/pdfservices-node-sdk-samples
// Run the sample:
// node src/pdfaccessibilitychecker/pdf-accessibility-checker-with-options.js

// node src/pdfaccessibilitychecker/pdf-accessibility-checker.js
const {
ServicePrincipalCredentials,
PDFServices,
Expand Down Expand Up @@ -65,11 +62,8 @@ const fs = require("fs");
mimeType: MimeType.PDF
});

// Create parameters for the job
const params = new PDFAccessibilityCheckerParams({pageStart:1, pageEnd:5});

// Create a new job instance
const job = new PDFAccessibilityCheckerJob({inputAsset, params});
const job = new PDFAccessibilityCheckerJob({inputAsset});

// Submit the job and get the job result
const pollingURL = await pdfServices.submit({job});
Expand Down Expand Up @@ -112,10 +106,9 @@ const fs = require("fs");
```clike
// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples
// Run the sample:
// cd PDFAccessibilityCheckerWithOptions/
// dotnet run PDFAccessibilityCheckerWithOptions.csproj

namespace PDFAccessibilityCheckerWithOptions
// cd PDFAccessibilityChecker/
// dotnet run PDFAccessibilityChecker.csproj
namespace PDFAccessibilityChecker
{
public class Program {
private static readonly ILog log = LogManager.GetLogger(typeof (Program));
Expand All @@ -136,16 +129,8 @@ namespace PDFAccessibilityCheckerWithOptions
using Stream inputStream = File.OpenRead(@"checkerPDFInput.pdf");
IAsset inputDocumentAsset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue());

// Set up PDF Accessibility Checker parameters
PDFAccessibilityCheckerParams pdfAccessibilityCheckerParams = PDFAccessibilityCheckerParams
.PDFAccessibilityCheckerParamsBuilder()
.WithPageStart(1)
.WithPageEnd(5)
.Build();

// Create the PDF Accessibility Checker job instance
PDFAccessibilityCheckerJob pdfAccessibilityCheckerJob =
new PDFAccessibilityCheckerJob(inputDocumentAsset).SetParams(pdfAccessibilityCheckerParams);
PDFAccessibilityCheckerJob pdfAccessibilityCheckerJob = new PDFAccessibilityCheckerJob(inputDocumentAsset);

// Submits the job and gets the job result
String location = pdfServices.Submit(pdfAccessibilityCheckerJob);
Expand Down Expand Up @@ -198,11 +183,10 @@ namespace PDFAccessibilityCheckerWithOptions
```javascript
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.pdfaccessibilitychecker.PDFAccessibilityCheckerWithOptions

public class PDFAccessibilityCheckerWithOptions {
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.pdfaccessibilitychecker.PDFAccessibilityChecker
public class PDFAccessibilityChecker {

private static final Logger LOGGER = LoggerFactory.getLogger(PDFAccessibilityCheckerWithOptions.class);
private static final Logger LOGGER = LoggerFactory.getLogger(PDFAccessibilityChecker.class);

public static void main(String[] args) {

Expand All @@ -220,13 +204,8 @@ public class PDFAccessibilityCheckerWithOptions {
// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());

// Creates parameters for the job
PDFAccessibilityCheckerParams pdfAccessibilityCheckerParams = PDFAccessibilityCheckerParams
.pdfAccessibilityCheckerParamsBuilder().withPageStart(1).withPageEnd(5).build();

// Creates a new job instance
PDFAccessibilityCheckerJob pdfAccessibilityCheckerJob = new PDFAccessibilityCheckerJob(asset)
.setParams(pdfAccessibilityCheckerParams);
PDFAccessibilityCheckerJob pdfAccessibilityCheckerJob = new PDFAccessibilityCheckerJob(asset);

// Submit the job and gets the job result
String location = pdfServices.submit(PDFAccessibilityCheckerJob);
Expand Down Expand Up @@ -288,13 +267,9 @@ class PDFAccessibilityChecker:

# Creates an asset(s) from source file(s) and upload
input_asset = pdf_services.upload(input_stream=input_stream, mime_type=PDFServicesMediaType.PDF)

# Create parameters for the job
pdf_accessibility_checker_params = PDFAccessibilityCheckerParams(page_start=1, page_end=5)


# Creates a new job instance
pdf_accessibility_checker_job = PDFAccessibilityCheckerJob(input_asset=input_asset,
pdf_accessibility_checker_params=pdf_accessibility_checker_params)
pdf_accessibility_checker_job = PDFAccessibilityCheckerJob(input_asset=input_asset)

# Submit the job and gets the job result
location = pdf_services.submit(pdf_accessibility_checker_job)
Expand All @@ -318,7 +293,7 @@ class PDFAccessibilityChecker:
except (ServiceApiException, ServiceUsageException, SdkException) as e:
logging.exception(f'Exception encountered while executing operation: {e}')


if __name__ == "__main__":
PDFAccessibilityChecker()
```
102 changes: 14 additions & 88 deletions src/pages/apis/pdf-services/pdf-watermark.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,7 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/addwater
--header 'Authorization: Bearer {{Placeholder for token}}' \
--data-raw '{
"inputDocumentAssetID": "urn:aaid:AS:UE1:54cbf87f-d7f5-4918-8e4b-9f68",
"watermarkDocumentAssetID": "urn:aaid:AS:UE1:54cbf87f-d7f5-4918-8e4b-9f1878678e68",
"pageRanges": [
{
"start": 2,
"end": 5
},
{
"start": 8,
"end": 10
}
],
"appearance": {
"opacity": 50,
"appearOnForeground": true
}
"watermarkDocumentAssetID": "urn:aaid:AS:UE1:54cbf87f-d7f5-4918-8e4b-9f1878678e68"
}'
```

Expand All @@ -46,7 +32,7 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/addwater
```js
// Get the samples from https://github.com/adobe/pdfservices-node-sdk-samples
// Run the sample:
// node src/pdfwatermark/pdf-watermark-with-options.js
// node src/pdfwatermark/pdf-watermark.js

const {
ServicePrincipalCredentials,
Expand Down Expand Up @@ -86,28 +72,11 @@ const fs = require("fs");
mimeType: MimeType.PDF
}]
});

const pageRangesForWatermark = new PageRanges();

pageRangesForWatermark.addRange(2, 5);
pageRangesForWatermark.addRange(8, 10);

const watermarkAppearance = new WatermarkAppearance({
appearOnForeground: true,
opacity: 50,
});

// Create parameters for the job
const pdfWatermarkParams = new PDFWatermarkParams({
watermarkAppearance: watermarkAppearance,
pageRanges: pageRangesForWatermark
})

// Creates a new job instance
const job = new PDFWatermarkJob({
inputAsset: inputAsset,
watermarkAsset: watermarkAsset,
params: pdfWatermarkParams
watermarkAsset: watermarkAsset
});

// Submit the job and get the job result
Expand Down Expand Up @@ -145,10 +114,10 @@ const fs = require("fs");
```clike
// Get the samples from https://github.com/adobe/PDFServices.NET.SDK.Samples
// Run the sample:
// cd PDFWatermarkWithOptions/
// dotnet run PDFWatermarkWithOptions.csproj
// cd PDFWatermark/
// dotnet run PDFWatermark.csproj

namespace PDFWatermarkWithOptions
namespace PDFWatermark
{
class Program
{
Expand Down Expand Up @@ -177,24 +146,9 @@ namespace PDFWatermarkWithOptions
// Creates a watermark asset from source file(s) and upload
Stream watermarkFileInputStream = File.OpenRead(@"watermark.pdf");
IAsset watermarkDocumentAsset = pdfServices.Upload(watermarkFileInputStream, PDFServicesMediaType.PDF.GetMIMETypeValue());

// Watermark pages of the document
PageRanges pageRangeForPDFWatermark = new PageRanges();

pageRangeForPDFWatermark.AddRange(2, 5);
pageRangeForPDFWatermark.AddRange(8, 10);

// Creates PDF Watermark appearance option
WatermarkAppearance watermarkAppearance = new WatermarkAppearance();
watermarkAppearance.SetOpacity(50);

// Create parameters for the job
PDFWatermarkParams pdfWatermarkParams = PDFWatermarkParams.PDFWatermarkParamsBuilder()
.WithPageRanges(pageRangesForPDFWatermark)
.WithWatermarkAppearance(watermarkAppearance).Build();

// Submits the job and gets the job result
PDFWatermarkJob pdfWatermarkJob = new PDFWatermarkJob(inputDocumentAsset, watermarkDocumentAsset).SetParams(pdfWatermarkParams);
PDFWatermarkJob pdfWatermarkJob = new PDFWatermarkJob(inputDocumentAsset, watermarkDocumentAsset);
String location = pdfServices.Submit(pdfWatermarkJob);

// Get content from the resulting asset(s)
Expand Down Expand Up @@ -248,14 +202,14 @@ namespace PDFWatermarkWithOptions
```javascript
// Get the samples from https://github.com/adobe/pdfservices-java-sdk-samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.pdfwatermark.PDFWatermarkWithOptions
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.pdfwatermark.PDFWatermark

package com.adobe.pdfservices.operation.samples.pdfwatermark;

public class PDFWatermarkWithOptions {
public class PDFWatermark {

// Initialize the logger
private static final Logger LOGGER = LoggerFactory.getLogger(PDFWatermarkWithOptions.class);
private static final Logger LOGGER = LoggerFactory.getLogger(PDFWatermark.class);

public static void main(String[] args) {

Expand All @@ -276,27 +230,9 @@ public class PDFWatermarkWithOptions {
// Creates a new job instance
PDFServices pdfServices = new PDFServices(credentials);

// Watermark pages of the document (as specified by PageRanges).
PageRanges pageRangeForPDFWatermark = new PageRanges();

pageRangeForPDFWatermark.addRange(2, 5);
pageRangeForPDFWatermark.addRange(8, 10);

// Creates PDF Watermark appearance option
WatermarkAppearance watermarkAppearance = new WatermarkAppearance();
watermarkAppearance.setOpacity(50);

// Create parameters for the job
PDFWatermarkParams pdfWatermarkParams = PDFWatermarkParams.pdfWatermarkParamsBuilder()
.withPageRanges(pageRangeForPDFWatermark)
.withWatermarkAppearance(watermarkAppearance)
.build();

// Creates a new job instance
PDFWatermarkJob pdfWatermarkJob = new PDFWatermarkJob(inputDocumentAsset, watermarkDocumentAsset)
.setParams(pdfWatermarkParams);


PDFWatermarkJob pdfWatermarkJob = new PDFWatermarkJob(inputDocumentAsset, watermarkDocumentAsset);

// Submit the job and gets the job result
String location = pdfServices.submit(pdfWatermarkJob);
PDFServicesResponse<PDFWatermarkResult> pdfServicesResponse = pdfServices.getJobResult(location, PDFWatermarkResult.class);
Expand All @@ -323,7 +259,7 @@ public class PDFWatermarkWithOptions {
```python
# Get the samples from https://github.com/adobe/pdfservices-python-sdk-samples
# Run the sample:
# python src/pdfwatermark/watermark_pdf_with_params.py
# python src/pdfwatermark/watermark_pdf.py

# Initialize the logger
logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -351,19 +287,9 @@ class PDFWatermark:
# Creates an asset(s) from source file(s) and upload
input_asset = pdf_services.upload(input_stream=source_file_input_stream, mime_type=PDFServicesMediaType.PDF)
watermark_asset = pdf_services.upload(input_stream=watermark_file_input_stream, mime_type=PDFServicesMediaType.PDF)

watermark_appearance = WatermarkAppearance(appear_on_foreground=True, opacity=50)

page_ranges = PageRanges()
page_ranges.add_range(2, 5)
page_ranges.add_range(8, 10)

# Create parameters for the job
pdf_watermark_params = PDFWatermarkParams(page_ranges=page_ranges, watermark_appearance=watermark_appearance)

# Creates a new job instance
pdf_watermark_job = PDFWatermarkJob(input_asset=input_asset, watermark_asset=watermark_asset,
pdf_watermark_params=pdf_watermark_params)
pdf_watermark_job = PDFWatermarkJob(input_asset=input_asset, watermark_asset=watermark_asset)

# Submit the job and gets the job result
location = pdf_services.submit(pdf_watermark_job)
Expand Down

0 comments on commit 1f83cd4

Please sign in to comment.