Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #201

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 67 additions & 34 deletions src/pages/apis/pdf-services/accessibility-auto-tag-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,75 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/autotag'
// Run the sample:
// node src/autotagpdf/autotag-pdf.js

const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');

try {
// Initial setup, create credentials instance.
const credentials = PDFServicesSdk.Credentials
.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();

// Create an ExecutionContext using credentials and create a new operation instance.
const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
autotagPDF = PDFServicesSdk.AutotagPDF,
autotagPDFOperation = autotagPDF.Operation.createNew();

// Set operation input from a source file.
const input = PDFServicesSdk.FileRef.createFromLocalFile('autotagPDFInput.pdf');
autotagPDFOperation.setInput(input);

// Execute the operation and Save the result to the specified location.
autotagPDFOperation.execute(executionContext)
.then(result => {
result.taggedPDF.saveAsFile('autotagPDFOutput.pdf');
})
.catch(err => {
if(err instanceof PDFServicesSdk.Error.ServiceApiError
|| err instanceof PDFServicesSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation', err);
} else {
console.log('Exception encountered while executing operation', err);
}
const {
ServicePrincipalCredentials,
PDFServices,
MimeType,
AutotagPDFJob,
AutotagPDFResult,
SDKError,
ServiceUsageError,
ServiceApiError,
} = require("@adobe/pdfservices-node-sdk");
const fs = require("fs");

(async () => {
let readStream;
try {
// Initial setup, create credentials instance
const credentials = new ServicePrincipalCredentials({
clientId: process.env.PDF_SERVICES_CLIENT_ID,
clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
});

} catch (err) {
console.log('Exception encountered while executing operation', err);
}
// Creates a PDF Services instance
const pdfServices = new PDFServices({
credentials
});

// Creates an asset(s) from source file(s) and upload
readStream = fs.createReadStream("./autotagPDFInput.pdf");
const inputAsset = await pdfServices.upload({
readStream,
mimeType: MimeType.PDF
});

// Creates a new job instance
const job = new AutotagPDFJob({
inputAsset
});

// Submit the job and get the job result
const pollingURL = await pdfServices.submit({
job
});
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: AutotagPDFResult
});

// Get content from the resulting asset(s)
const resultAsset = pdfServicesResponse.result.taggedPDF;
const streamAsset = await pdfServices.getContent({
asset: resultAsset
});

// Creates an output stream and copy stream asset's content to it
const outputFilePath = "./autotag-tagged.pdf";
console.log(`Saving asset at ${outputFilePath}`);

let writeStream = fs.createWriteStream(outputFilePath);
streamAsset.readStream.pipe(writeStream);
} catch (err) {
if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
console.log("Exception encountered while executing operation", err);
} else {
console.log("Exception encountered while executing operation", err);
}
} finally {
readStream?.destroy();
}
})();
```

#### .Net
Expand Down
115 changes: 82 additions & 33 deletions src/pages/apis/pdf-services/combine-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,89 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/combinep
// Run the sample:
// node src/combinepdf/combine-pdf.js

const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');

try {
// Initial setup, create credentials instance.
const credentials = PDFServicesSdk.Credentials
.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();

// Create an ExecutionContext using credentials and create a new operation instance.
const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
combineFilesOperation = PDFServicesSdk.CombineFiles.Operation.createNew();

// Set operation input from a source file.
const combineSource1 = PDFServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput1.pdf'),
combineSource2 = PDFServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput2.pdf');
combineFilesOperation.addInput(combineSource1);
combineFilesOperation.addInput(combineSource2);

// Execute the operation and Save the result to the specified location.
combineFilesOperation.execute(executionContext)
.then(result => result.saveAsFile('output/combineFilesOutput.pdf'))
.catch(err => {
if (err instanceof PDFServicesSdk.Error.ServiceApiError
|| err instanceof PDFServicesSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation', err);
} else {
console.log('Exception encountered while executing operation', err);
}
const {
ServicePrincipalCredentials,
PDFServices,
MimeType,
CombinePDFJob,
CombinePDFParams,
CombinePDFResult,
SDKError,
ServiceUsageError,
ServiceApiError
} = require("@adobe/pdfservices-node-sdk");
const fs = require("fs");

(async () => {
let readStream1;
let readStream2;
try {
// Initial setup, create credentials instance
const credentials = new ServicePrincipalCredentials({
clientId: process.env.PDF_SERVICES_CLIENT_ID,
clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
});
} catch (err) {
console.log('Exception encountered while executing operation', err);
}

// Creates a PDF Services instance
const pdfServices = new PDFServices({
credentials
});

// Creates an asset(s) from source file(s) and upload
readStream1 = fs.createReadStream("./combineFilesInput1.pdf");
readStream2 = fs.createReadStream("./combineFilesInput2.pdf");
const [inputAsset1, inputAsset2] = await pdfServices.uploadAssets({
streamAssets: [{
readStream: readStream1,
mimeType: MimeType.PDF
}, {
readStream: readStream2,
mimeType: MimeType.PDF
}]
});

// Create parameters for the job
const params = new CombinePDFParams()
.addAsset(inputAsset1)
.addAsset(inputAsset2);

// Create a new job instance
const job = new CombinePDFJob({
params
});

// Submit the job and get the job result
const pollingURL = await pdfServices.submit({
job
});
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: CombinePDFResult
});

// Get content from the resulting asset(s)
const resultAsset = pdfServicesResponse.result.asset;
const streamAsset = await pdfServices.getContent({
asset: resultAsset
});

// Creates an output stream and copy result asset's content to it
const outputFilePath = "./combineFilesOutput.pdf";
console.log(`Saving asset at ${outputFilePath}`);

const outputStream = fs.createWriteStream(outputFilePath);
streamAsset.readStream.pipe(outputStream);
} catch (err) {
if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
console.log("Exception encountered while executing operation", err);
} else {
console.log("Exception encountered while executing operation", err);
}
} finally {
readStream1?.destroy();
readStream2?.destroy();
}
})();
```

#### .Net
Expand Down
100 changes: 68 additions & 32 deletions src/pages/apis/pdf-services/compress-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,75 @@ curl --location --request POST 'https://pdf-services.adobe.io/operation/compress
// Run the sample:
// node src/compresspdf/compress-pdf.js

const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');

try {
// Initial setup, create credentials instance.
const credentials = PDFServicesSdk.Credentials
.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();

// Create an ExecutionContext using credentials and create a new operation instance.
const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
compressPDF = PDFServicesSdk.CompressPDF,
compressPDFOperation = compressPDF.Operation.createNew();

// Set operation input from a source file.
const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/compressPDFInput.pdf');
compressPDFOperation.setInput(input);

// Execute the operation and Save the result to the specified location.
compressPDFOperation.execute(executionContext)
.then(result => result.saveAsFile('output/compressPDFOutput.pdf'))
.catch(err => {
if(err instanceof PDFServicesSdk.Error.ServiceApiError
|| err instanceof PDFServicesSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation', err);
} else {
console.log('Exception encountered while executing operation', err);
}
const {
ServicePrincipalCredentials,
PDFServices,
MimeType,
CompressPDFJob,
CompressPDFResult,
SDKError,
ServiceUsageError,
ServiceApiError
} = require("@adobe/pdfservices-node-sdk");
const fs = require("fs");

(async () => {
let readStream;
try {
// Initial setup, create credentials instance
const credentials = new ServicePrincipalCredentials({
clientId: process.env.PDF_SERVICES_CLIENT_ID,
clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
});
} catch (err) {
console.log('Exception encountered while executing operation', err);
}

// Creates a PDF Services instance
const pdfServices = new PDFServices({
credentials
});

// Creates an asset(s) from source file(s) and upload
readStream = fs.createReadStream("./compressPDFInput.pdf");
const inputAsset = await pdfServices.upload({
readStream,
mimeType: MimeType.PDF
});

// Creates a new job instance
const job = new CompressPDFJob({
inputAsset
});

// Submit the job and get the job result
const pollingURL = await pdfServices.submit({
job
});
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: CompressPDFResult
});

// Get content from the resulting asset(s)
const resultAsset = pdfServicesResponse.result.asset;
const streamAsset = await pdfServices.getContent({
asset: resultAsset
});

// Creates an output stream and copy stream asset's content to it
const outputFilePath = "./compressPDFOutput.pdf";
console.log(`Saving asset at ${outputFilePath}`);

const outputStream = fs.createWriteStream(outputFilePath);
streamAsset.readStream.pipe(outputStream);
} catch (err) {
if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
console.log("Exception encountered while executing operation", err);
} else {
console.log("Exception encountered while executing operation", err);
}
} finally {
readStream?.destroy();
}
})();
```

#### .Net
Expand Down
Loading
Loading