Skip to content

Commit 4e9ee32

Browse files
1012499: Added docs for redaction and security
1 parent 211ca55 commit 4e9ee32

3 files changed

Lines changed: 162 additions & 1 deletion

File tree

Document-Processing-toc.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,16 @@
10021002
<li><a href="/document-processing/pdf/pdf-viewer/react/annotation/annotations-in-mobile-view">Annotations in Mobile view</a></li>
10031003
</ul>
10041004
</li>
1005-
<li>Redaction
1005+
<li>Redaction and Security
10061006
<ul>
10071007
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/overview">Overview</a></li>
10081008
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/ui-interaction">UI Interactions</a></li>
10091009
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/programmatic-support">Programmatic Support</a></li>
10101010
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/toolbar">Toolbar</a></li>
10111011
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/mobile-view">Mobile View</a></li>
10121012
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/search-redact">Search Text and Redact</a></li>
1013+
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/prevent-copy-and-print">Prevent copy/print</a></li>
1014+
<li><a href="/document-processing/pdf/pdf-viewer/react/Redaction/secure-pdf-viewing">Secure PDF viewing in react apps</a></li>
10131015
</ul>
10141016
</li>
10151017
<li><a href="/document-processing/pdf/pdf-viewer/react/interaction-mode">Interaction Mode</a></li>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
layout: post
3+
title: Prevent Copy or Print in React PDF Viewer | Syncfusion
4+
description: Learn how to prevent printing and copying in the React PDF Viewer using viewer settings or server-side permission flags.
5+
platform: document-processing
6+
control: PDF Viewer
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Prevent Copy or Print in React PDF Viewer
12+
13+
## Overview
14+
This guide shows how to prevent users from copying text or printing documents in EJ2 React PDF Viewer.
15+
16+
**Outcome:** You will learn server-side and client-side options to restrict copy/print with a complete React example.
17+
18+
## Steps
19+
20+
1. Use a PDF with permissions already set
21+
- Load a PDF that already disallows copy or print functionality itself. The Viewer enforces these permission automatically.
22+
23+
2. Preprocess restrictions in server-side
24+
- Use Syncfusion PDF Library to set permission flags before sending the file to the client. See the server-side example below.
25+
- Disabling print and copy in server-side automatically enforces them in the PDF Viewer.
26+
27+
3. Hide/disable UI elements in the viewer
28+
- Print, download and copy options can be disabled or hidden in the viewer regardless of the PDF's permissions.
29+
- Print and download options can be hidden in the viewer's primary toolbar. See [primary toolbar customization](../toolbar-customization/primary-toolbar).
30+
- Copy option in the context menu can be disabled in the PDF Viewer. See [customize context menu](../context-menu/custom-context-menu).
31+
32+
4. Disable print programmatically in the viewer
33+
- Set [`enablePrint`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#enableprint) to `false` to disable the print UI even if the PDF allows printing.
34+
35+
5. Disable copy via text-selection UI
36+
- Set [`enableTextSelection`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#enabletextselection) to `false` to stop text selection and copying through the viewer UI.
37+
38+
**Example:**
39+
40+
The following is a complete React example that demonstrates disabling printing and text selection in the viewer.
41+
42+
{% tabs %}
43+
{% highlight ts tabtitle="App.tsx" %}
44+
{% raw %}
45+
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer, Inject } from '@syncfusion/ej2-react-pdfviewer';
46+
export default function App() {
47+
return (
48+
<div style={{ height: '100vh' }}>
49+
<PdfViewerComponent
50+
id="pdfViewer"
51+
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
52+
resourceUrl="https://cdn.syncfusion.com/ej2/32.2.5/dist/ej2-pdfviewer-lib"
53+
enablePrint={false} // disables the print UI
54+
enableTextSelection={false} // disables text selection (prevents copy)
55+
enableDownload={false}
56+
style={{ height: '100%' }}>
57+
<Inject services={[Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer]} />
58+
</PdfViewerComponent>
59+
</div>
60+
);
61+
}
62+
{% endraw %}
63+
{% endhighlight %}
64+
{% endtabs %}
65+
66+
**Expected result**:
67+
- The viewer renders the PDF.
68+
- Print button and print-related UI are hidden/disabled.
69+
- Text selection and copy operations from the viewer are disabled.
70+
71+
## Server-side: Enforce restrictions with Syncfusion PDF Library
72+
73+
Process the PDF on the server to set permissions that disallow printing or copying. The viewer will respect these permissions when the PDF is loaded.
74+
75+
{% tabs %}
76+
{% highlight csharp tabtitle="Program.cs" %}
77+
{% raw %}
78+
using Syncfusion.Pdf.Parsing;
79+
using Syncfusion.Pdf.Security;
80+
81+
using FileStream inputStream = new FileStream(
82+
Path.GetFullPath("input.pdf"),
83+
FileMode.Open,
84+
FileAccess.Read
85+
);
86+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);
87+
loadedDocument.Security.Permissions = PdfPermissionsFlags.EditContent | PdfPermissionsFlags.EditAnnotations | PdfPermissionsFlags.FillFields | PdfPermissionsFlags.AssembleDocument | PdfPermissionsFlags.AccessibilityCopyContent;
88+
loadedDocument.Save(Path.GetFullPath(@"output.pdf"));
89+
loadedDocument.Close(true);
90+
{% endraw %}
91+
{% endhighlight %}
92+
{% endtabs %}
93+
94+
Set the [`PdfPermissionsFlags`](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Security.PdfPermissionsFlags.html) appropriately to remove copy/print rights. The example above shows how to set flags.
95+
96+
## Troubleshooting
97+
98+
- If the Print button still appears:
99+
- Confirm [`enablePrint`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#enableprint) is set to `false` on `PdfViewerComponent`.
100+
- If the PDF explicitly allows printing, prefer server-side removal of print permission.
101+
- If text can still be copied:
102+
- Confirm [`enableTextSelection`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer#enabletextselection) is set to `false` and your app isn't adding secondary copy handlers.
103+
104+
## Related topics
105+
106+
- [Redact Sensitive content in PDF](../Redaction/overview)
107+
- [Redaction APIs](../Redaction/programmatic-support)
108+
- [Redaction toolbar](../Redaction/toolbar)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
layout: post
3+
title: Secure PDF Viewing in React Apps using PDF Viewer | Syncfusion
4+
description: Best practices for securing PDF content in React apps using the EJ2 React PDF Viewer and server-side processing.
5+
platform: document-processing
6+
control: PDF Viewer
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Secure PDF Viewing in React Apps
12+
13+
## Overview
14+
15+
This page explains best practices for securing PDF content displayed in React applications using the EJ2 React PDF Viewer and server-side processing. It covers encryption, permission restrictions, redaction, preprocessing, and secure API usage.
16+
17+
## Why Secure Viewing matters
18+
19+
- Protects user privacy and compliance-sensitive data.
20+
- Reduces risk from hidden/metadata content and unauthorized copying or printing.
21+
- Limits liability when distributing PDFs to untrusted clients.
22+
23+
## Common security guidelines
24+
25+
This section outlines common security controls and how they interact with the viewer.
26+
27+
- **Password protection**: Use user/owner passwords on PDFs. The viewer can open password-protected files when the password is provided at load time. Password-based encryption prevents opening without credentials. See [loading password protected PDFs](../document-handling/load-password-pdf)
28+
29+
- **Permission restrictions**: Set PDF permissions (copy, print) using Syncfusion PDF library. The viewer respects these permissions at display time but cannot enforce protections if the client receives an unprotected full file. See [prevent copy and print permissions](./prevent-copy-and-print)
30+
31+
- **Redaction**: Permanently remove text, images, or regions at the document level on the server before delivering the file. Redaction produces a new PDF with the sensitive content removed. See [redacting sensitive content](./overview)
32+
33+
- **Preprocessing and sanitization**: On the server, remove metadata, embedded files, hidden layers, form field values, JavaScript actions, and flatten form fields. Compress and linearize PDFs if needed. See [preprocessing PDFs](../document-handling/preprocess-pdf)
34+
35+
## Design decisions and trade-offs
36+
37+
- Client vs server enforcement: Client-side settings which disable disabling print in the viewer improve user experience but are not a security boundary. True protection requires server-side changes which actually enforces the restrictions (encryption, permissions, redaction).
38+
39+
- Usability vs security: Strong encryption and heavy sanitization can break some workflows (search, form interactivity). Choose operations appropriate to the document lifecycle.
40+
41+
- Redaction permanence: Redaction is irreversible; keep originals securely archived if needed for audit.
42+
43+
## Best practices
44+
45+
- Encrypt PDFs with strong passwords when they must remain unreadable without credentials.
46+
- Apply permission flags for copying/printing via server-side PDF library; treat viewer-side options as UX controls only.
47+
- Perform redaction on the server to permanently remove sensitive content.
48+
- Strip metadata, embedded files, comments, and JavaScript before serving.
49+
- Flatten form fields and sanitize form data when exporting public PDFs.
50+
- Use short-lived, authenticated URLs or a tokenized download endpoint rather than serving files from a public bucket.
51+
- Log access and apply rate limits and CORS policies on APIs that serve PDFs.

0 commit comments

Comments
 (0)