Skip to content

Commit c33b8fc

Browse files
committed
PDF contents updated
1 parent 7b46132 commit c33b8fc

File tree

2 files changed

+297
-481
lines changed

2 files changed

+297
-481
lines changed
Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
3-
title: Open and save PDF files in JavaScript PDF library | Syncfusion
4-
description: Learn to load and save PDFs in Syncfusion JavaScript PDF library using URLs, base64 strings, or byte arrays with server-backed services.
3+
title: Open and save PDF files using JavaScript PDF library | Syncfusion
4+
description: Learn to load and save PDFs in Syncfusion JavaScript PDF library using data as base64 strings or byte arrays.
55
platform: document-processing
66
control: PDF
77
documentation: ug
@@ -12,70 +12,65 @@ domainurl: ##DomainURL##
1212

1313
## Opening an existing PDF document
1414

15-
Open an existing PDF document using the `PdfDocument` class with the specified string data.
15+
Open an existing PDF document using the `PdfDocument` class with the specified PDF data.
1616

17-
```javascript
17+
```typescript
1818
// Load an existing PDF document from string data
19-
let document: PdfDocument = new PdfDocument("Input.pdf");
20-
19+
let document: PdfDocument = new PdfDocument(data);
2120
```
2221

23-
## Opening an existing PDF document from a byte array
22+
The PdfDocument constructor can accept PDF data in either Base64 string or Uint8Array format. Here’s a quick example for both approaches:
2423

25-
Open an existing PDF document using the `PdfDocument` class with the specified byte array.
24+
### Using Base64 String
25+
26+
Open an existing PDF document using the `PdfDocument` class with the specified PDF data as Base64 string.
2627

2728
```javascript
28-
// Load the PDF data from a file
29-
const inputPDFByteArray: Uint8Array = new Uint8Array(fs.readFileSync('Input.pdf'));
30-
// Create a new PdfDocument instance using the byte array
31-
const loadedDocument = new PdfDocument(inputPDFByteArray);
29+
let data: string = 'JVBERi0xLjcNJeLjz9MNCjEyNSAw...........TU3MTQNCiUlRU9GDQo=';
30+
// Load an existing PDF document from data as Base64 string
31+
let document: PdfDocument = new PdfDocument(data);
3232
```
3333

34-
## Opening an Encrypted PDF document
34+
### Using Uint8Array
3535

36-
Open an encrypted PDF document using the `PdfDocument` class by providing the correct password.
36+
Open an existing PDF document using the `PdfDocument` class with the specified PDF data as Uint8Array.
3737

3838
```javascript
39-
// Load an existing PDF document from string data
40-
let document: PdfDocument = new PdfDocument("Input.pdf", "password");
39+
let binaryData: Uint8Array = Uint8Array.from(data);
40+
// Load an existing PDF document from data as Uint8Array
41+
let document: PdfDocument = new PdfDocument(binaryData);
4142
```
4243

43-
## Opening an Encrypted PDF document from a byte array
44+
## Opening an Encrypted PDF document with password
4445

45-
Open an encrypted PDF document from a byte array using the `PdfDocument` class by providing the correct password.
46+
Open an encrypted PDF document using the `PdfDocument` class by providing the correct password.
4647

4748
```javascript
48-
// Load the PDF data from a file
49-
const inputPDFByteArray: Uint8Array = new Uint8Array(fs.readFileSync('Input.pdf'));
50-
// Load an existing PDF document from string data
51-
let document: PdfDocument = new PdfDocument(inputPDFByteArray, "password");
49+
// Load an existing PDF document with password
50+
let document: PdfDocument = new PdfDocument(data, "password");
5251
```
5352

54-
## Saving a PDF document
53+
## Save and download a PDF document in browser environment
5554

56-
Save the manipulated PDF document using the `Save` method of `PdfDocument` class with the specified string data.
55+
Save and download the PDF document using the `save` method of `PdfDocument` class with the specified file name.
5756

5857
```javascript
59-
// Load an existing PDF document from string data
60-
let document: PdfDocument = new PdfDocument("Input.pdf");
61-
//To-Do some manipulation
62-
//To-Do some manipulation
63-
// Save the PDF document
64-
document.save('Output.pdf');
58+
// Load an existing PDF document
59+
let document: PdfDocument = new PdfDocument(data);
60+
// To-Do some manipulation
61+
// Save and download the PDF document to the specified filename.
62+
document.save('output.pdf');
6563
```
6664

67-
## Saving a PDF Document from a byte array
65+
## Saving a PDF document to byte array
6866

69-
Open an existing PDF document using the `PdfDocument` class with the specified byte array.
67+
Save the modified PDF document to the specified byte array using the `save` method available in `PdfDocument` class.
7068

7169
```javascript
72-
// Load the PDF data from a file
73-
const inputPDFByteArray: Uint8Array = new Uint8Array(fs.readFileSync('Input.pdf'));
74-
// Create a new PdfDocument instance using the byte array
75-
const loadedDocument = new PdfDocument(inputPDFByteArray);
70+
// Load an existing PDF document
71+
let document: PdfDocument = new PdfDocument(data);
7672
//To-Do some manipulation
77-
//To-Do some manipulation
78-
// Save the document
73+
// Save and get PDF data as byte array.
7974
let data: Uint8Array = document.save();
8075
```
8176

@@ -84,12 +79,11 @@ let data: Uint8Array = document.save();
8479
After the document manipulation and save operation are completed, you should close the instance of `PdfDocument`, in order to release all the memory consumed by PDF DOM. The following code example illustrates how to destroy a `PdfDocument` instance.
8580

8681
```javascript
87-
// Load an existing PDF document from string data
88-
let document: PdfDocument = new PdfDocument("Input.pdf");
89-
//To-Do some manipulation
82+
// Load an existing PDF document
83+
let document: PdfDocument = new PdfDocument(data);
9084
//To-Do some manipulation
9185
// Save the PDF document
92-
document.save('Output.pdf');
86+
document.save('output.pdf');
9387
// Destroy the document
9488
document.destroy();
9589
```

0 commit comments

Comments
 (0)