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 #196

Merged
merged 5 commits into from
Jan 23, 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
45 changes: 27 additions & 18 deletions src/pages/apis/pdf-services/accessibility-auto-tag-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,41 @@ public class AutotagPDF {

public static void main(String[] args) {

try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/autotagPDFInput.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));

// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
AutotagPDFOperation autotagPDFOperation = AutotagPDFOperation.createNew();
// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);

// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("autotagPDFInput.pdf");
autotagPDFOperation.setInput(source);
// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());

// Execute the operation
AutotagPDFOutput autotagPDFOutput = autotagPDFOperation.execute(executionContext);
// Creates a new job instance
AutotagPDFJob autotagPDFJob = new AutotagPDFJob(asset);

// Save the tagged PDF output at the specified location
autotagPDFOutput.getTaggedPDF().saveAs("autotagPDFOutput.pdf");
// Submit the job and gets the job result
String location = pdfServices.submit(autotagPDFJob);
PDFServicesResponse<AutotagPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, AutotagPDFResult.class);

} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getTaggedPDF();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);

// Creates an output stream and copy stream asset's content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/autotagPDFOutput.pdf").toPath());
LOGGER.info("Saving asset at output/autotagPDFOutput.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();

} catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
}

}
```

### Python
Expand Down
84 changes: 50 additions & 34 deletions src/pages/apis/pdf-services/combine-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,38 +147,54 @@ namespace CombinePDF
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.combinepdf.CombinePDF

public class CombinePDF {

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

public static void main(String[] args) {
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 and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
CombineFilesOperation combineFilesOperation = CombineFilesOperation.createNew();

// Add operation input from source files.
FileRef combineSource1 = FileRef.createFromLocalFile("src/main/resources/combineFilesInput1.pdf");
FileRef combineSource2 = FileRef.createFromLocalFile("src/main/resources/combineFilesInput2.pdf");
combineFilesOperation.addInput(combineSource1);
combineFilesOperation.addInput(combineSource2);

// Execute the operation.
FileRef result = combineFilesOperation.execute(executionContext);

// Save the result to the specified location.
result.saveAs("output/combineFilesOutput.pdf");

} catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
}
public class CombinePDF {

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

public static void main(String[] args) {
try (InputStream inputStream1 = Files.newInputStream(new File("src/main/resources/combineFilesInput1.pdf").toPath());
InputStream inputStream2 = Files.newInputStream(new File("src/main/resources/combineFilesInput2.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));

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

// Creates an asset(s) from source file(s) and upload
List<StreamAsset> streamAssets = new ArrayList<>();
streamAssets.add(new StreamAsset(inputStream1, PDFServicesMediaType.PDF.getMediaType()));
streamAssets.add(new StreamAsset(inputStream2, PDFServicesMediaType.PDF.getMediaType()));
List<Asset> assets = pdfServices.uploadAssets(streamAssets);

// Create parameters for the job
CombinePDFParams combinePDFParams = CombinePDFParams.combinePDFParamsBuilder()
.addAsset(assets.get(0))
.addAsset(assets.get(1))
.build();

// Creates a new job instance
CombinePDFJob combinePDFJob = new CombinePDFJob(combinePDFParams);

// Submit the job and gets the job result
String location = pdfServices.submit(combinePDFJob);
PDFServicesResponse<CombinePDFResult> pdfServicesResponse = pdfServices.getJobResult(location, CombinePDFResult.class);

// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);

// Creates an output stream and copy stream asset's content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/combineFilesOutput.pdf").toPath());
LOGGER.info("Saving asset at output/combineFilesOutput.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();
} catch (IOException | ServiceApiException | SDKException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
}
```
50 changes: 29 additions & 21 deletions src/pages/apis/pdf-services/compress-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,35 @@ public class CompressPDF {

public static void main(String[] args) {

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 and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
CompressPDFOperation compressPDFOperation = CompressPDFOperation.createNew();

// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/compressPDFInput.pdf");
compressPDFOperation.setInput(source);

// Execute the operation
FileRef result = compressPDFOperation.execute(executionContext);

// Save the result at the specified location
result.saveAs("output/compressPDFOutput.pdf");

try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/compressPDFInput.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));

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

// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());

// Creates a new job instance
CompressPDFJob compressPDFJob = new CompressPDFJob(asset);

// Submit the job and gets the job result
String location = pdfServices.submit(compressPDFJob);
PDFServicesResponse<CompressPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, CompressPDFResult.class);

// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);

// Creating an output stream and copying stream asset content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/compressPDFOutput.pdf").toPath());
LOGGER.info("Saving asset at output/compressPDFOutput.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();
} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
Expand Down
44 changes: 28 additions & 16 deletions src/pages/apis/pdf-services/convert-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,39 @@ public class ExportPDFToDOCX {

public static void main(String[] args) {

try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFInput.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));
// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);

// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());

// Create parameters for the job
ExportPDFParams exportPDFParams = ExportPDFParams.exportPDFParamsBuilder(ExportPDFTargetFormat.DOCX)
.build();
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
ExportPDFOperation exportPdfOperation = ExportPDFOperation.createNew(ExportPDFTargetFormat.DOCX);

// Set operation input from a local PDF file
FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFInput.pdf");
exportPdfOperation.setInput(sourceFileRef);
// Creates a new job instance
ExportPDFJob exportPDFJob = new ExportPDFJob(asset, exportPDFParams);

// Execute the operation.
FileRef result = exportPdfOperation.execute(executionContext);
// Submit the job and gets the job result
String location = pdfServices.submit(exportPDFJob);
PDFServicesResponse<ExportPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFResult.class);

// Save the result to the specified location.
result.saveAs("output/exportPdfOutput.docx");
// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);

} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
// Creates an output stream and copy stream asset's content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/exportPdfOutput.docx").toPath());
LOGGER.info("Saving asset at output/exportPdfOutput.docx");
IOUtils.copy(streamAsset.getInputStream(), outputStream);

} catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
}
Expand Down
58 changes: 32 additions & 26 deletions src/pages/apis/pdf-services/create-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,41 @@ namespace CreatePDFFromDocx
public class CreatePDFFromDOCX {

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

public static void main(String[] args) {

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 and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
CreatePDFOperation createPdfOperation = CreatePDFOperation.createNew();

// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/createPDFInput.docx");
createPdfOperation.setInput(source);

// Execute the operation.
FileRef result = createPdfOperation.execute(executionContext);

// Save the result to the specified location.
result.saveAs("output/createPDFFromDOCX.pdf");

} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing
operation", ex);
try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/createPDFInput.docx").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));

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

// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());

// Creates a new job instance
CreatePDFJob createPDFJob = new CreatePDFJob(asset);

// Submit the job and gets the job result
String location = pdfServices.submit(createPDFJob);
PDFServicesResponse<CreatePDFResult> pdfServicesResponse = pdfServices.getJobResult(location, CreatePDFResult.class);

// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);

// Creates an output stream and copy stream asset's content to it
File.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/createPDFFromDOCX.pdf").toPath());
LOGGER.info("Saving asset at output/createPDFFromDOCX.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();
} catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing the operation", ex);
}
}
}
Expand Down
Loading
Loading