Skip to content

Commit 4f9ff4c

Browse files
authored
Merge pull request #129 from aspose-pdf-cloud/pdfcloud-4840-added-snippet-simple-create-pdf
PDFCLOUD-4840: added snippet for simple create PDF
2 parents 0d9f96d + aa9e198 commit 4f9ff4c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
});

0 commit comments

Comments
 (0)