Skip to content

Commit f377cb0

Browse files
Add files via upload
1 parent 609392d commit f377cb0

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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. Retrieve required Bookmark from the document using getBookmark() function
5+
// 6. Perform some action after successful retrieving the Bookmark from document
6+
// All values of variables starting with "YOUR_****" should be replaced by real user values
7+
8+
import credentials from "../../../../Credentials/credentials.json" with { type: "json" };
9+
import fs from "node:fs/promises";
10+
import path from "node:path";
11+
import { PdfApi } from "../../../src/api/api.js";
12+
13+
const configParams = {
14+
LOCAL_FOLDER: "C:\\Samples\\",
15+
PDF_DOCUMENT_NAME: "sample.pdf",
16+
BOOKMARK_PATH: "/5",
17+
};
18+
19+
const pdfApi = new PdfApi(credentials.id, credentials.key);
20+
21+
const pdfBookmarks = {
22+
async uploadDocument() {
23+
const pdfFilePath = path.join(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
24+
const pdfFileData = await fs.readFile(pdfFilePath);
25+
await pdfApi.uploadFile(configParams.PDF_DOCUMENT_NAME, pdfFileData);
26+
},
27+
28+
async getBookmarkByPath() {
29+
const resultBookmark = await pdfApi.getBookmark(configParams.PDF_DOCUMENT_NAME, configParams.BOOKMARK_PATH);
30+
const { code, bookmark } = resultBookmark.body;
31+
32+
console.log(`Found bookmark title: ${bookmark.title}`);
33+
return bookmark;
34+
},
35+
36+
};
37+
38+
async function main() {
39+
try {
40+
await pdfBookmarks.uploadDocument();
41+
await pdfBookmarks.getBookmarkByPath();
42+
} catch (error) {
43+
console.error("Error:", error.message);
44+
}
45+
}
46+
47+
main();

0 commit comments

Comments
 (0)