Skip to content

Commit a7b6fd1

Browse files
Merge pull request #2383 from syncfusion-content/EJ2-1014821-print
1014821: Revamped print & download docs in react documentation
2 parents 389d446 + 9f008c1 commit a7b6fd1

File tree

13 files changed

+666
-531
lines changed

13 files changed

+666
-531
lines changed

Document-Processing-toc.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,14 @@
11681168
<li><a href="/document-processing/pdf/pdf-viewer/react/organize-pages/events">Events</a></li>
11691169
</ul>
11701170
</li>
1171-
<li><a href="/document-processing/pdf/pdf-viewer/react/print">Print</a></li>
1171+
<li><a href="/document-processing/pdf/pdf-viewer/react/print/overview">Print</a>
1172+
<ul>
1173+
<li><a href="/document-processing/pdf/pdf-viewer/react/print/print-modes">Print Modes</a></li>
1174+
<li><a href="/document-processing/pdf/pdf-viewer/react/print/print-quality">Print Quality</a></li>
1175+
<li><a href="/document-processing/pdf/pdf-viewer/react/print/enable-print-rotation">Print rotation</a></li>
1176+
<li><a href="/document-processing/pdf/pdf-viewer/react/print/events">Events</a></li>
1177+
</ul>
1178+
</li>
11721179
<li><a href="/document-processing/pdf/pdf-viewer/react/download">Download</a></li>
11731180
<li><a href="/document-processing/pdf/pdf-viewer/react/events">Events</a></li>
11741181
<li><a href="/document-processing/pdf/pdf-viewer/react/text-selection">Text Selection</a></li>

Document-Processing/PDF/PDF-Viewer/react/download.md

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
---
22
layout: post
3-
title: Download in React Pdfviewer component | Syncfusion
3+
title: Download edited PDF in React PDF Viewer | Syncfusion
44
description: Learn here all about Download in Syncfusion React Pdfviewer component of Syncfusion Essential JS 2 and more.
55
control: PDF Viewer
66
platform: document-processing
77
documentation: ug
88
domainurl: ##DomainURL##
99
---
10-
# Download in React PDF Viewer component
1110

12-
The PDF Viewer component supports downloading the loaded PDF file. Enable or disable the download using the example below.
11+
# Download edited PDF in React PDF Viewer
12+
13+
The React PDF Viewer allows users to download the currently loaded PDF, including any annotations, form‑field edits, ink drawings, comments, or page reorganizations. Downloading produces a local PDF file containing all applied changes. This guide shows ways to download a PDF displayed in the PDF Viewer: using the built-in toolbar, and programmatically after editing.
14+
15+
## Download the PDF Using the Toolbar
16+
17+
The viewer's toolbar can include a download button when the [`Toolbar`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbar) service is injected. When enabled, users can click the toolbar download icon to save the currently loaded PDF.
18+
19+
**Notes:**
20+
21+
- Ensure [`Toolbar`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbar) is included in the `Inject` services for [`PdfViewerComponent`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer) and `DownloadOption` is included in [`toolbarItems`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbarsettingsmodel#toolbaritems).
22+
- See the [toolbar items documentation](./toolbar-customization/primary-toolbar#3-show-or-hide-primary-toolbar-items) for customizing or hiding the default download icon.
1323

1424
![Download button in PDF Viewer](./images/download.png)
1525

16-
Invoke the download action using the following example.
26+
## Download an Edited PDF Programmatically
1727

18-
N> The examples obtain the viewer instance and call `download()`. Prefer using the component `ref` to access the viewer instance when available rather than direct DOM lookup.
28+
You can invoke the viewer's [`download()`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#download) method to trigger a download programmatically. The examples below show a standalone setup and a server-backed setup to trigger download action.
1929

2030
{% tabs %}
2131
{% highlight js tabtitle="Standalone" %}
@@ -94,7 +104,75 @@ root.render(<App />);
94104
{% endhighlight %}
95105
{% endtabs %}
96106

107+
## Download a PDF with Flattened Annotations
108+
109+
You can intercept the viewer's [`downloadStart`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#downloadstart) event, cancel the default download, obtain the document as a `Blob` via [`saveAsBlob()`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#saveasblob), and flatten annotations before saving the resulting PDF.
110+
111+
{% tabs %}
112+
{% highlight ts tabtitle="App.tsx" %}
113+
{% raw %}
114+
import {
115+
PdfViewerComponent, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,
116+
ThumbnailView, BookmarkView, TextSelection, TextSearch, FormFields, FormDesigner,
117+
PageOrganizer, Inject, Print, DownloadStartEventArgs
118+
} from '@syncfusion/ej2-react-pdfviewer';
119+
import { PdfDocument } from '@syncfusion/ej2-pdf';
120+
import { RefObject, useRef } from 'react';
121+
122+
export default function App() {
123+
const viewerRef: RefObject<PdfViewerComponent> = useRef(null);
124+
125+
const blobToBase64 = async (blob: Blob): Promise<string> => {
126+
return new Promise((resolve, reject) => {
127+
const reader = new FileReader();
128+
reader.onerror = () => reject(reader.error);
129+
reader.onload = () => {
130+
const dataUrl: string = reader.result as string;
131+
const data: string = dataUrl.split(',')[1];
132+
resolve(data);
133+
};
134+
reader.readAsDataURL(blob);
135+
});
136+
}
137+
138+
const flattenPDF = (data: string) => {
139+
let document: PdfDocument = new PdfDocument(data);
140+
document.flatten = true
141+
document.save(`${viewerRef.current.fileName}.pdf`);
142+
document.destroy();
143+
}
144+
145+
const handleFlattening = async () => {
146+
const blob: Blob = await viewerRef.current.saveAsBlob();
147+
const data: string = await blobToBase64(blob);
148+
flattenPDF(data);
149+
}
150+
151+
const onDownloadStart = async (args: DownloadStartEventArgs) => {
152+
args.cancel = true;
153+
handleFlattening();
154+
};
155+
156+
return (
157+
<div style={{ height: '640px' }}>
158+
<PdfViewerComponent
159+
id="pdf-viewer"
160+
ref={viewerRef}
161+
documentPath="https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf"
162+
resourceUrl="https://cdn.syncfusion.com/ej2/32.2.5/dist/ej2-pdfviewer-lib"
163+
downloadStart={onDownloadStart}
164+
>
165+
<Inject services={[Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView,
166+
BookmarkView, TextSelection, TextSearch, FormFields, FormDesigner, PageOrganizer, Print]} />
167+
</PdfViewerComponent>
168+
</div>
169+
);
170+
}
171+
{% endraw %}
172+
{% endhighlight %}
173+
{% endtabs %}
174+
97175
## See also
98176

99-
* [Toolbar items](./toolbar)
100-
* [Feature Modules](./feature-module)
177+
- [Toolbar items](./toolbar)
178+
- [Feature Modules](./feature-module)

Document-Processing/PDF/PDF-Viewer/react/forms/flatten-form-fields.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Flattening PDF forms converts interactive fields such as textboxes, dropdowns, c
2121

2222
## Flatten forms before downloading PDF
2323

24-
1. Add a ref to the `PdfViewerComponent` so you can access viewer APIs from event handlers.
25-
2. Intercept the download flow using `downloadStart` and cancel the default flow.
26-
3. Retrieve the viewer's blob via `saveAsBlob()` and convert the blob to base64.
24+
1. Add a ref to the [`PdfViewerComponent`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer) so you can access viewer APIs from event handlers.
25+
2. Intercept the download flow using [`downloadStart`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#downloadstart) and cancel the default flow.
26+
3. Retrieve the viewer's blob via [`saveAsBlob()`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#saveasblob) and convert the blob to base64.
2727
4. Use `PdfDocument` from Syncfusion PDF Library to open the document, set `field.flatten = true` for each form field, then save.
28-
5. For the flattening the form fields when downloading through *Save As* option in Page Organizer, repeat steps 2–4 by using `pageOrganizerSaveAs` event.
28+
5. For the flattening the form fields when downloading through *Save As* option in Page Organizer, repeat steps 2–4 by using [`pageOrganizerSaveAs`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#pageorganizersaveas) event.
2929

3030
## Complete example
3131

@@ -111,8 +111,8 @@ export default function App() {
111111

112112
## Troubleshooting
113113

114-
- If viewerRef is null, ensure `ref={viewerRef}` is present and the component has mounted before invoking `saveAsBlob()`.
115-
- Missing `resourceUrl`: If viewer resources are not reachable, set `resourceUrl` to the correct CDN or local path for the ej2-pdfviewer-lib.
114+
- If viewerRef is null, ensure `ref={viewerRef}` is present and the component has mounted before invoking [`saveAsBlob()`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#saveasblob).
115+
- Missing [`resourceUrl`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#resourceurl): If viewer resources are not reachable, set [`resourceUrl`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#resourceurl) to the correct CDN or local path for the ej2-pdfviewer-lib.
116116

117117
## Related topics
118118

Document-Processing/PDF/PDF-Viewer/react/forms/submit-form-data.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ The React PDF Viewer allows submitting filled form data like text fields, checkb
2525

2626
1. Enable form designer in the viewer
2727

28-
- Inject `FormFields` and `FormDesigner` services into the viewer so form APIs are available.
28+
- Inject `FormFields` and [`FormDesigner`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/formdesigner) services into the viewer so form APIs are available.
2929

3030
2. Export form data from the viewer
3131

32-
- Use `viewer.exportFormFieldsAsObject()` to obtain the filled values as JSON.
32+
- Use [`viewer.exportFormFieldsAsObject()`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#exportformfieldsasobject) to obtain the filled values as JSON.
3333

3434
3. POST the exported JSON to your back end
3535

@@ -103,10 +103,10 @@ export default function SubmitFormExample() {
103103

104104
## Troubleshooting
105105

106-
- **No form values returned**: Ensure the PDF has interactive fields and the viewer has finished loading before calling `exportFormFieldsAsObject()`.
106+
- **No form values returned**: Ensure the PDF has interactive fields and the viewer has finished loading before calling [`exportFormFieldsAsObject()`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#exportformfieldsasobject).
107107
- **CORS errors**: Enable CORS on the server or serve both frontend and back end from the same origin during testing.
108108
- **Server rejects payload**: Confirm the server expects `application/json` and validates shape of the object.
109-
- **WASM or resource errors**: Ensure `resourceUrl` points to the correct Syncfusion PDF Viewer library files.
109+
- **WASM or resource errors**: Ensure [`resourceUrl`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#resourceurl) points to the correct Syncfusion PDF Viewer library files.
110110

111111
## Use cases
112112

0 commit comments

Comments
 (0)