Skip to content

Commit c119f6f

Browse files
authored
Merge pull request #28 from aspose-pdf-cloud/holub
add import statements for attachment handling in Node.js examples
2 parents feae984 + 04e20d6 commit c119f6f

File tree

9 files changed

+934
-2
lines changed

9 files changed

+934
-2
lines changed

pdf/net/attachments/append/_index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ Portable Document Format (PDF) is a type of document created by Adobe back in 19
124124

125125
{{< /blocks/products/pf/agp/about-file-section >}}
126126

127-
{{< /blocks/products/pf/agp/demobox >}}
128127

129128
<!-- aboutfile Ends -->
130129

pdf/net/attachments/extract/_index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ Portable Document Format (PDF) is a type of document created by Adobe back in 19
107107

108108
{{< /blocks/products/pf/agp/about-file-section >}}
109109

110-
{{< /blocks/products/pf/agp/demobox >}}
111110

112111
<!-- aboutfile Ends -->
113112

pdf/nodejs/attachments/_index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ It is easy to get started with Aspose.PDF Cloud Node.js SDK and there is nothing
8080

8181
```js
8282

83+
import credentials from "./credentials.json" with { type: "json" };
84+
import fs from 'node:fs/promises';
85+
import path from 'node:path';
86+
import { PdfApi } from "asposepdfcloud";
87+
import { AttachmentInfo } from "asposepdfcloud/src/models/attachmentInfo.js";
88+
8389
async function getAllAttachments() {
8490
const LOCAL_PATH = "C:\\Samples\\";
8591
const LOCAL_FILE_NAME = "C:\\Samples\\Attachments\\sample_attachment.pdf";

pdf/nodejs/attachments/append/_index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ It is easy to get started with Aspose.PDF Cloud Node.js SDK and there is nothing
7676

7777
```js
7878

79+
import credentials from "./credentials.json" with { type: "json" };
80+
import fs from 'node:fs/promises';
81+
import path from 'node:path';
82+
import { PdfApi } from "asposepdfcloud";
83+
import { AttachmentInfo } from "asposepdfcloud/src/models/attachmentInfo.js";
84+
7985
async function addAttachment() {
8086
const LOCAL_FILE_NAME = "C:\\Samples\\Attachments\\sample_attachment.pdf";
8187
const STORAGE_FILE_NAME = "sample_attachment.pdf";

pdf/nodejs/attachments/extract/_index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ It is easy to get started with Aspose.PDF Cloud Node.js SDK and there is nothing
7777

7878
```js
7979

80+
import credentials from "./credentials.json" with { type: "json" };
81+
import fs from 'node:fs/promises';
82+
import path from 'node:path';
83+
import { PdfApi } from "asposepdfcloud";
84+
import { AttachmentInfo } from "asposepdfcloud/src/models/attachmentInfo.js";
85+
8086
async function getAllAttachments() {
8187
const LOCAL_PATH = "C:\\Samples\\";
8288
const LOCAL_FILE_NAME = "C:\\Samples\\Attachments\\sample_attachment.pdf";

pdf/nodejs/footer/image/_index.md

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
---
2+
title: Add Bookmarks via Cloud Node.js SDK
3+
url: /nodejs/bookmarks/add/
4+
description: Aspose.PDF Cloud allows you to add Bookmarks to a PDF Document. Check the Node.js source code to add Bookmarks into PDF file.
5+
lastmod: "2025-02-20"
6+
---
7+
8+
{{< blocks/products/pf/main-wrap-class isAutogenPage="true">}}
9+
{{< blocks/products/pf/upper-banner h1="Add Bookmarks to PDF document via Node.js Cloud API" h2="Build your own Node.js apps to create Fillable document files using server-side APIs." logoImageSrc="https://products.aspose.cloud/headers/aspose_pdf-for-node.svg" sourceAdditionalConversionTag="" additionalConversionTag="PDF" pfName="" subTitlepfName="" downloadUrl="" fileiconsmall1="HTML" fileiconsmall2="JPG" fileiconsmall3="PDF" fileiconsmall4="XML" fileiconsmall5="DOCX" >}}
10+
11+
{{< blocks/products/pf/main-container pfName="Aspose.PDF Cloud" subTitlepfName="Node.js SDK" >}}
12+
{{< blocks/products/pf/sub-menu logoImageSrc="https://products.aspose.cloud/sdk/aspose_pdf-for-node.svg"
13+
autoGeneratedVersion="true"
14+
liveDemosLink="https://products.aspose.app/pdf/family/" PricingLink="https://purchase.aspose.cloud/pricing" buyLink="" docsLink="https://docs.aspose.cloud/pdf" directDownloadLink="https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js" >}}
15+
16+
{{% blocks/products/pf/agp/content h2="How to add Bookmarks via Node.js SDK" %}}
17+
18+
In order to add Bookmarks to PDF, we'll use
19+
[Aspose.PDF Cloud Node.js SDK](https://products.aspose.cloud/pdf/nodejs/). This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Simply create an account at [Aspose for Cloud](https://dashboard.aspose.cloud/#/apps) and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.
20+
21+
{{% blocks/products/pf/agp/code-block title="Package Manager Console Command" offSpacer="true" %}}
22+
23+
```bash
24+
25+
 
26+
npm install asposepdfcloud --save
27+
 
28+
 
29+
30+
```
31+
32+
{{% /blocks/products/pf/agp/code-block %}}
33+
34+
{{% /blocks/products/pf/agp/content %}}
35+
36+
{{< blocks/products/pf/agp/feature-section isGrey="true" >}}
37+
38+
{{% blocks/products/pf/agp/feature-section-col title="Steps to add Bookmarks via Cloud Node.js" %}}
39+
40+
{{% blocks/products/pf/agp/text %}}
41+
42+
Aspose.PDF Cloud developers can easily add Bookmarks to PDF in just a few lines of code.
43+
44+
{{% /blocks/products/pf/agp/text %}}
45+
46+
1. Create an object to connect to the Pdf.Cloud API
47+
1. Upload your document file
48+
1. Create a new Bookmarks with the required properties
49+
1. Append new Bookmarks to the document using postBookmark() function
50+
1. Perform some action after successful addition
51+
1. Download the result if needed it
52+
53+
{{% /blocks/products/pf/agp/feature-section-col %}}
54+
55+
{{% blocks/products/pf/agp/feature-section-col title="System Requirements" %}}
56+
57+
{{% blocks/products/pf/agp/text %}}
58+
59+
It is easy to get started with Aspose.PDF Cloud Node.js SDK and there is nothing to install. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.
60+
61+
* CPU: 1GHz
62+
* RAM: 512Mb
63+
* Free space on disk: 20Mb
64+
* Any OS Microsoft Windows, Mac OS, Linux x32/x64
65+
* node.js v4.8 or higher
66+
67+
{{% /blocks/products/pf/agp/text %}}
68+
69+
{{% /blocks/products/pf/agp/feature-section-col %}}
70+
71+
{{% blocks/products/pf/agp/code-block title="This sample code shows adding Bookmarks in PDF documents - Node.js" offSpacer="" %}}
72+
73+
```js
74+
75+
import credentials from "./credentials.json" with { type: "json" }; // json-file in this format: { "id": "*****", "key": "*******" }
76+
import fs from 'node:fs/promises';
77+
import path from 'node:path';
78+
import { PdfApi } from "asposepdfcloud";
79+
import { Color } from "asposepdfcloud/src/models/color.js";
80+
import { Link } from "asposepdfcloud/src/models/link.js";
81+
import { Bookmark } from "asposepdfcloud/src/models/bookmark.js";
82+
import { Bookmarks } from "asposepdfcloud/src/models/bookmarks.js";
83+
84+
const configParams = {
85+
LOCAL_FOLDER: "C:\\Samples\\",
86+
PDF_DOCUMENT_NAME: "sample.pdf",
87+
LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
88+
NEW_BOOKMARK_TITLE: "• Productivity improvement",
89+
PARENT_BOOKMARK_FOR_APPEND: "", //The parent bookmark path. Specify an empty string when adding a bookmark to the root.
90+
NEW_BOOKMARK_PAGE_NUMBER: 2,
91+
};
92+
93+
const pdfApi = new PdfApi(credentials.id, credentials.key);
94+
95+
const pdfBookmarks = {
96+
async uploadDocument() {
97+
const pdfFilePath = path.join(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
98+
const pdfFileData = await fs.readFile(pdfFilePath);
99+
await pdfApi.uploadFile(configParams.PDF_DOCUMENT_NAME, pdfFileData);
100+
},
101+
102+
async downloadResult() {
103+
const changedPdfData = await pdfApi.downloadFile(configParams.PDF_DOCUMENT_NAME);
104+
const filePath = path.join(configParams.LOCAL_FOLDER, configParams.LOCAL_RESULT_DOCUMENT_NAME);
105+
await fs.writeFile(filePath, changedPdfData.body);
106+
console.log("Downloaded: " + filePath);
107+
},
108+
109+
async appendBookmarkLink() {
110+
const bookmarkLink = new Link({ rel: "self" });
111+
const bookmarkColor = new Color({ a: 255, r: 0, g: 255, b: 0 });
112+
113+
const newBookmark = new Bookmark();
114+
newBookmark.title = configParams.NEW_BOOKMARK_TITLE;
115+
newBookmark.italic = true;
116+
newBookmark.bold = false;
117+
newBookmark.links = [bookmarkLink];
118+
newBookmark.color = bookmarkColor;
119+
newBookmark.action = "GoTo";
120+
newBookmark.level = 1;
121+
newBookmark.pageDisplayLeft = 83;
122+
newBookmark.pageDisplayTop = 751;
123+
newBookmark.pageDisplayZoom = 2;
124+
newBookmark.pageNumber = configParams.NEW_BOOKMARK_PAGE_NUMBER;
125+
126+
const response = await pdfApi.postBookmark(configParams.PDF_DOCUMENT_NAME, configParams.PARENT_BOOKMARK_FOR_APPEND, [newBookmark]);
127+
const { code, bookmarks } = response.body;
128+
129+
if (code === 200 && bookmarks) {
130+
const addedBookmark = bookmarks.list[bookmarks.list.length - 1];
131+
console.log("Appended bookmark: " + addedBookmark.links[0].href + " => " + addedBookmark.title);
132+
return addedBookmark;
133+
}
134+
},
135+
};
136+
137+
async function main() {
138+
try {
139+
await pdfBookmarks.uploadDocument();
140+
await pdfBookmarks.appendBookmarkLink();
141+
await pdfBookmarks.downloadResult();
142+
} catch (error) {
143+
console.error("Error:", error.message);
144+
}
145+
}
146+
```
147+
148+
{{% /blocks/products/pf/agp/code-block %}}
149+
150+
{{% blocks/products/pf/agp/content h2="Work with the Bookmarks via Node.js SDK" %}}
151+
152+
Adding bookmarks to a PDF significantly improves document usability by enhancing navigation, organization, and accessibility. It is essential for large documents, ensuring users can efficiently find and access relevant content.
153+
Add the Bookmarks into PDF documents with [Aspose.PDF Cloud Node.js SDK](https://products.aspose.cloud/pdf/nodejs/).
154+
155+
**With our Node.js library you can**
156+
157+
+ Add PDF document's header & footer in text or image format.
158+
+ Add tables & stamps (text or image) to PDF documents.
159+
+ Append multiple PDF documents to an existing file.
160+
+ Work with PDF attachments, annotations, & form fields.
161+
+ Apply encryption or decryption to PDF documents & set a password.
162+
+ Delete all stamps & tables from a page or entire PDF document.
163+
+ Delete a specific stamp or table from the PDF document by its ID.
164+
+ Replace single or multiple instances of text on a PDF page or from the entire document.
165+
+ Extensive support for converting PDF documents to various other file formats.
166+
+ Extract various elements of PDF files & make PDF documents optimized.
167+
+ You can try out our [free Apps](https://products.aspose.app/pdf/family/) to test the functionality online.
168+
169+
{{% /blocks/products/pf/agp/content %}}
170+
171+
{{< /blocks/products/pf/agp/feature-section >}}
172+
173+
<!-- aboutfile Starts -->
174+
175+
{{% blocks/products/pf/agp/content h2="About Aspose.PDF Cloud Node.js SDK" %}}
176+
177+
[Aspose.PDF Cloud](https://products.aspose.cloud/pdf) is a true REST API that enables you to perform a wide range of document processing operations including creation, manipulation, conversion and rendering of PDF documents in the cloud.
178+
179+
Our Cloud SDKs are wrappers around REST API in various programming languages, allowing you to process documents in language of your choice quickly and easily, gaining all benefits of strong types and IDE highlights. This repository contains new generation SDKs for Aspose.PDF Cloud and examples.
180+
181+
These SDKs are now fully supported. If you have any questions, see any bugs or have enhancement request, feel free to reach out to us at Free [Support Forums](https://forum.aspose.cloud/c/pdf).
182+
183+
{{% /blocks/products/pf/agp/content %}}
184+
185+
{{< blocks/products/pf/agp/about-file-section >}}
186+
187+
{{< blocks/products/pf/agp/demobox sectionTitle="Aspose.PDF No Code Online App" sectionDescription="For testing our functionality visit the [Live Demos website](https://products.aspose.app/pdf/family/). The live demo has the following benefits" >}}
188+
189+
{{< blocks/products/pf/agp/democard icon="fa-cogs" text=" No need to download or setup anything" >}}
190+
{{< blocks/products/pf/agp/democard icon="fa-edit" text=" No need to write any code" >}}
191+
{{< blocks/products/pf/agp/democard icon="fa-file-text" text="Click button. Your PDF files will be uploaded and will be converted to format." >}}
192+
{{< blocks/products/pf/agp/democard icon="fa-download" text=" Instantly get the download link for the resultant file" >}}
193+
194+
{{< blocks/products/pf/agp/about-file-text fileFormat="PDF" readMoreLink="https://docs.fileformat.com/view/pdf/" >}}
195+
Portable Document Format (PDF) is a type of document created by Adobe back in 1990s. The purpose of this file format was to introduce a standard for representation of documents and other reference material in a format that is independent of application software, hardware as well as Operating System. PDF files can be opened in Adobe Acrobat Reader/Writer as well in most modern browsers like Chrome, Safari, Firefox via extensions/plug-ins. Most of the commercially available software suites also offer conversion of their documents to PDF file format without the requirement of any additional software component. Thus, PDF file format has full capability to contain information like text, images, hyperlinks, form-fields, rich media, digital signatures, attachments, metadata, Geospatial features and 3D objects in it that can become as part of source document.
196+
197+
{{< /blocks/products/pf/agp/about-file-text >}}
198+
199+
{{< /blocks/products/pf/agp/about-file-section >}}
200+
201+
{{< /blocks/products/pf/agp/demobox >}}
202+
203+
{{< blocks/products/pf/support-learning-resources >}}
204+
{{< blocks/products/pf/slr-tab tabTitle="Learning Resources" tabId="resources" >}}
205+
{{< blocks/products/pf/slr-element name="Documentation" href="https://docs.aspose.cloud/pdf" >}}
206+
{{< blocks/products/pf/slr-element name="Source Code" href="https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-nodejs" >}}
207+
{{< blocks/products/pf/slr-element name="API References" href="https://reference.aspose.cloud/pdf/" >}}
208+
{{< /blocks/products/pf/slr-tab >}}
209+
210+
{{< blocks/products/pf/slr-tab tabTitle="Product Support" tabId="support" >}}
211+
{{< blocks/products/pf/slr-element name="Free Support" href="https://forum.aspose.cloud/c/pdf/13" >}}
212+
{{< blocks/products/pf/slr-element name="Paid Support" href="https://helpdesk.aspose.cloud" >}}
213+
{{< blocks/products/pf/slr-element name="Blog" href="https://blog.aspose.cloud/categories/aspose.pdf-cloud-product-family/" >}}
214+
{{< /blocks/products/pf/slr-tab >}}
215+
216+
{{< blocks/products/pf/slr-tab tabTitle="Why Aspose.PDF Cloud for Node.js?" tabId="success-stories" >}}
217+
{{< blocks/products/pf/slr-element name="Customers List" href="https://company.aspose.cloud/customers" >}}
218+
{{< blocks/products/pf/slr-element name="Security" href="https://company.aspose.cloud/legal/security" >}}
219+
{{< /blocks/products/pf/slr-tab >}}
220+
221+
{{< /blocks/products/pf/support-learning-resources >}}
222+
223+
<!-- aboutfile Ends -->
224+
225+
{{< /blocks/products/pf/main-container >}}
226+
227+
{{< /blocks/products/pf/main-wrap-class >}}
228+
229+

0 commit comments

Comments
 (0)