Skip to content

Commit e862c9c

Browse files
Update removeTables.js
1 parent 5ad4f2f commit e862c9c

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

UsesCases/Tables/remove/removeTables.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
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" };
92
import fs from 'node:fs/promises';
103
import path from 'node:path';
11-
import { PdfApi } from "asposepdfcloud";
4+
import { PdfApi } from "../../../src/api/api.js"
125

136
const configParams = {
147
LOCAL_FOLDER: "C:\\Samples\\",
158
PDF_DOCUMENT_NAME: "sample.pdf",
169
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...
1912
};
2013

2114
const pdfApi = new PdfApi(credentials.id, credentials.key);
@@ -25,6 +18,7 @@ const pdfTables = {
2518
const fileNamePath = path.join(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
2619
const pdfFileData = await fs.readFile(fileNamePath);
2720
await pdfApi.uploadFile(configParams.PDF_DOCUMENT_NAME, pdfFileData);
21+
console.log("File '" + configParams.PDF_DOCUMENT_NAME + "' successfully uploaded!");
2822
},
2923

3024
async downloadResult () {
@@ -38,14 +32,13 @@ const pdfTables = {
3832
const resultTabs = await pdfApi.getDocumentTables(configParams.PDF_DOCUMENT_NAME);
3933

4034
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);
4639
}
4740
else
48-
console.error("Unexpected error : can't get links!!!");
41+
console.error(prefix + " => Unexpected error : can't get tables!!!");
4942
},
5043

5144
async deleteTable () {
@@ -91,6 +84,8 @@ async function main() {
9184

9285
await pdfTables.deleteTables(configParams.PAGE_NUMBER);
9386
await pdfTables.getAllTables("Tables after drop all");
87+
88+
await pdfTables.downloadResult();
9489
} catch (error) {
9590
console.error("Error:", error.message);
9691
}

0 commit comments

Comments
 (0)