1
- // 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2
- // 2. Create an object to connect to the Pdf.Cloud API
3
- // 3. Upload your document file
4
- // 4. Delete required Link Annotation from the document using deleteLinkAnnotation() function
5
- // 6. Perform some action after successful removing the Link Annotation from document
6
- // All values of variables starting with "YOUR_****" should be replaced by real user values
7
-
8
- import credentials from "./credentials.json" with { type : "json" } ;
1
+ import credentials from "../../../../Credentials/credentials.json" with { type : "json" } ;
9
2
import fs from 'node:fs/promises' ;
10
3
import path from 'node:path' ;
11
- import { PdfApi } from "asposepdfcloud" ;
4
+ import { PdfApi } from "../../../src/api/api.js"
12
5
13
6
const configParams = {
14
7
LOCAL_FOLDER : "C:\\Samples\\" ,
15
8
PDF_DOCUMENT_NAME : "sample.pdf" ,
16
9
LOCAL_RESULT_DOCUMENT_NAME : "output_sample.pdf" ,
17
- PAGE_NUMBER : 1 , // Your document page number...
18
- TABLE_ID : "GE5TCOZSGAYCYNRQGUWDINZVFQ3DGMA" ,
10
+ PAGE_NUMBER : 1 , // Your document page number...
11
+ TABLE_ID : "GE5TCOZSGAYCYNRQGUWDINZVFQ3DGMA" , // Your table id...
19
12
} ;
20
13
21
14
const pdfApi = new PdfApi ( credentials . id , credentials . key ) ;
@@ -25,6 +18,7 @@ const pdfTables = {
25
18
const fileNamePath = path . join ( configParams . LOCAL_FOLDER , configParams . PDF_DOCUMENT_NAME ) ;
26
19
const pdfFileData = await fs . readFile ( fileNamePath ) ;
27
20
await pdfApi . uploadFile ( configParams . PDF_DOCUMENT_NAME , pdfFileData ) ;
21
+ console . log ( "File '" + configParams . PDF_DOCUMENT_NAME + "' successfully uploaded!" ) ;
28
22
} ,
29
23
30
24
async downloadResult ( ) {
@@ -38,14 +32,13 @@ const pdfTables = {
38
32
const resultTabs = await pdfApi . getDocumentTables ( configParams . PDF_DOCUMENT_NAME ) ;
39
33
40
34
if ( resultTabs . body . code == 200 && resultTabs . body . tables ) {
41
- if ( ! Array . isArray ( resultTabs . body . tables . list ) || resultTabs . body . tables . list . length === 0 ) {
42
- console . log ( "Unexpected error : tables is null or empty!!!" ) ;
43
- }
44
- this . showTablesInfo ( resultTabs . body . tables . list , prefix ) ;
45
- return resultTabs . body . tables . list ;
35
+ if ( ! Array . isArray ( resultTabs . body . tables . list ) || resultTabs . body . tables . list . length === 0 )
36
+ console . log ( prefix + " => Unexpected error : tables is null or empty!!!" ) ;
37
+ else
38
+ this . showTablesInfo ( resultTabs . body . tables . list , prefix ) ;
46
39
}
47
40
else
48
- console . error ( " Unexpected error : can't get links !!!") ;
41
+ console . error ( prefix + " => Unexpected error : can't get tables !!!") ;
49
42
} ,
50
43
51
44
async deleteTable ( ) {
@@ -91,6 +84,8 @@ async function main() {
91
84
92
85
await pdfTables . deleteTables ( configParams . PAGE_NUMBER ) ;
93
86
await pdfTables . getAllTables ( "Tables after drop all" ) ;
87
+
88
+ await pdfTables . downloadResult ( ) ;
94
89
} catch ( error ) {
95
90
console . error ( "Error:" , error . message ) ;
96
91
}
0 commit comments