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+ export { configParams , pdfApi , ParserHelper } ;
7+
8+ const configParams = {
9+ LOCAL_FOLDER : "C:\\Samples\\" ,
10+ PDF_DOCUMENT_NAME : "sample.pdf" ,
11+ REMOTE_FOLDER : 'TempPdfCloud' ,
12+
13+ XML_OUTPUT_FILE : "output_sample.xml" ,
14+ FDF_OUTPUT_FILE : "output_sample.fdf" ,
15+
16+ PAGE_NUMBER : 1 ,
17+
18+ } ;
19+
20+ const pdfApi = new PdfApi ( credentials . id , credentials . key ) ;
21+
22+ const ParserHelper = {
23+ async uploadFile ( fileName , localFolder , tempFolder ) {
24+ const fileNamePath = path . join ( localFolder , fileName ) ;
25+ const fileData = await fs . readFile ( fileNamePath ) ;
26+ const storagePath = path . join ( tempFolder , fileName ) ;
27+ await pdfApi . uploadFile ( storagePath , fileData )
28+ . then ( ( ) => console . log ( "File: '" + fileName + "' successfully uploaded." ) ) ;
29+ } ,
30+
31+ async uploadDocument ( document , localFolder , tempFolder ) {
32+ await this . uploadFile ( document , localFolder , tempFolder )
33+ } ,
34+
35+ async downloadResult ( document , localFolder , tempFolder , prefix ) {
36+ const fileName = path . join ( tempFolder , document ) ;
37+ const changedPdfData = await pdfApi . downloadFile ( fileName ) ;
38+ const filePath = path . join ( localFolder , prefix + document ) ;
39+ await fs . writeFile ( filePath , changedPdfData . body ) ;
40+ console . log ( "Downloaded: " + filePath ) ;
41+ } ,
42+ } ;
0 commit comments