File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ import credentials from "../../../Credentials/credentials.json" with { type : "json" } ; // json-file in this format: { "id": "*****", "key": "*******" }
2
+ import fs from 'node:fs/promises' ;
3
+ import path from 'node:path' ;
4
+ import { PdfApi } from "../../src/api/api.js" ;
5
+
6
+ const loccalFolder = "C:\\Samples\\" ;
7
+ const pdfDocument = "output_sample.pdf" ;
8
+
9
+ // Create PDF Rest API object
10
+ const pdfApi = new PdfApi ( credentials . id , credentials . key ) ;
11
+
12
+ // Create empty Pdf
13
+ const pdfResponse = await pdfApi . putCreateDocument ( pdfDocument , null , null )
14
+ . then ( async ( ) => {
15
+ console . log ( "Document #" + pdfDocument + " successfully created." ) ;
16
+
17
+ // Download empty Pdf document to local folder
18
+ await pdfApi . downloadFile ( pdfDocument )
19
+ . then ( async ( data ) => {
20
+ const filePath = path . join ( loccalFolder , pdfDocument ) ;
21
+ await fs . writeFile ( filePath , data . body ) ;
22
+ console . log ( "Downloaded: " + filePath ) ;
23
+ } ) ;
24
+ } )
25
+ . except ( ( error ) => {
26
+ // Catch any exceptions
27
+ console . log ( "Failed to create empty DPDF dcument '" + pdfDocument + "' !" )
28
+ console . error ( "Error:" , error . message ) ;
29
+ } ) ;
You can’t perform that action at this time.
0 commit comments