|
1 | | -/** |
2 | | - * This sample illustrates how to export a PDF file to a list of JPEG files. |
3 | | - * |
4 | | - * Refer to README.md for instructions on how to run the samples. |
5 | | - */ |
6 | | -component displayname="Export PDF To JPEG List" { |
7 | | - public ExportPDFToJPEGList function init() { |
8 | | - variables.java_Credentials = createObject("java", "com.adobe.pdfservices.operation.auth.Credentials"); |
9 | | - variables.java_ExecutionContext = createObject("java", "com.adobe.pdfservices.operation.ExecutionContext"); |
10 | | - variables.java_CreatePDFOperation = createObject("java", "com.adobe.pdfservices.operation.pdfops.CreatePDFOperation"); |
11 | | - variables.java_FileRef = createObject("java", "com.adobe.pdfservices.operation.io.FileRef"); |
12 | | - variables.java_ExportPDFToImagesOperation = createObject("java", "com.adobe.pdfservices.operation.pdfops.ExportPDFToImagesOperation"); |
13 | | - variables.java_ExportPDFToImagesTargetFormat = createObject("java", "com.adobe.pdfservices.operation.pdfops.options.exportpdftoimages.ExportPDFToImagesTargetFormat"); |
14 | | - |
15 | | - return this; |
16 | | - } |
17 | | - |
18 | | - public void function run() { |
19 | | - try { |
20 | | - // Initial setup, create credentials instance. |
21 | | - var credentials = java_Credentials.serviceAccountCredentialsBuilder() |
22 | | - .fromFile(application.credentialsJSONFile) |
23 | | - .build(); |
24 | | - |
25 | | - // Create an ExecutionContext using credentials and create a new operation instance. |
26 | | - var executionContext = variables.java_ExecutionContext.create(credentials); |
27 | | - var exportPDFToImagesOperation = variables.java_ExportPDFToImagesOperation.createNew( |
28 | | - variables.java_ExportPDFToImagesTargetFormat.JPEG |
29 | | - ); |
30 | | - |
31 | | - // Set operation input from a source file. |
32 | | - var sourceFileRef = variables.java_FileRef.createFromLocalFile( |
33 | | - application.resourcesPath & "/exportPDFToImageInput.pdf" |
34 | | - ); |
35 | | - exportPDFToImagesOperation.setInput(sourceFileRef); |
36 | | - |
37 | | - // Execute the operation. |
38 | | - var results = exportPDFToImagesOperation.execute(executionContext); |
39 | | - |
40 | | - // Save the result to the specified location. |
41 | | - var index = 0; |
42 | | - for (var result in results) { |
43 | | - result.saveAs(application.outputPath & "/exportPDFToImagesOutput_" & index & ".jpeg"); |
44 | | - index++; |
45 | | - } |
46 | | - } |
47 | | - catch(any e) { |
48 | | - writeLog("Exception encountered while executing operation: #e.message#"); |
49 | | - } |
50 | | - } |
51 | | -} |
| 1 | +/** |
| 2 | + * This sample illustrates how to export a PDF file to a list of JPEG files. |
| 3 | + * |
| 4 | + * Refer to README.md for instructions on how to run the samples. |
| 5 | + */ |
| 6 | +component displayname="Export PDF To JPEG" { |
| 7 | + public ExportPDFToJPEG function init() { |
| 8 | + variables.java_Credentials = createObject("java", "com.adobe.pdfservices.operation.auth.Credentials"); |
| 9 | + variables.java_ExecutionContext = createObject("java", "com.adobe.pdfservices.operation.ExecutionContext"); |
| 10 | + variables.java_CreatePDFOperation = createObject("java", "com.adobe.pdfservices.operation.pdfops.CreatePDFOperation"); |
| 11 | + variables.java_FileRef = createObject("java", "com.adobe.pdfservices.operation.io.FileRef"); |
| 12 | + variables.java_ExportPDFToImagesOperation = createObject("java", "com.adobe.pdfservices.operation.pdfops.ExportPDFToImagesOperation"); |
| 13 | + variables.java_ExportPDFToImagesTargetFormat = createObject("java", "com.adobe.pdfservices.operation.pdfops.options.exportpdftoimages.ExportPDFToImagesTargetFormat"); |
| 14 | + |
| 15 | + return this; |
| 16 | + } |
| 17 | + |
| 18 | + public void function run() { |
| 19 | + try { |
| 20 | + // Initial setup, create credentials instance. |
| 21 | + var credentials = java_Credentials.serviceAccountCredentialsBuilder() |
| 22 | + .fromFile(application.credentialsJSONFile) |
| 23 | + .build(); |
| 24 | + |
| 25 | + // Create an ExecutionContext using credentials and create a new operation instance. |
| 26 | + var executionContext = variables.java_ExecutionContext.create(credentials); |
| 27 | + var exportPDFToImagesOperation = variables.java_ExportPDFToImagesOperation.createNew( |
| 28 | + variables.java_ExportPDFToImagesTargetFormat.JPEG |
| 29 | + ); |
| 30 | + |
| 31 | + // Set operation input from a source file. |
| 32 | + var sourceFileRef = variables.java_FileRef.createFromLocalFile( |
| 33 | + application.resourcesPath & "/exportPDFToImageInput.pdf" |
| 34 | + ); |
| 35 | + exportPDFToImagesOperation.setInput(sourceFileRef); |
| 36 | + |
| 37 | + // Execute the operation. |
| 38 | + var results = exportPDFToImagesOperation.execute(executionContext); |
| 39 | + |
| 40 | + // Save the result to the specified location. |
| 41 | + var index = 0; |
| 42 | + for (var result in results) { |
| 43 | + result.saveAs(application.outputPath & "/exportPDFToJPEGOutput_" & index & ".jpeg"); |
| 44 | + index++; |
| 45 | + } |
| 46 | + } |
| 47 | + catch(any e) { |
| 48 | + writeLog("Exception encountered while executing operation: #e.message#"); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments