EmbedPDF

Turn features on and off

Say what people can do in this viewer with features. A feature you name is on or off everywhere at once; one you leave out keeps its default:

{
  features: {
    measurement: true,
    redaction: true,
    'documents.download': false,
  },
}

The Measure and Redact tabs appear, and nothing downloads the file: no Download in the document menu, and no shortcut.

Most features are on from the start. Measuring, redaction, building forms and snapshots wait until you turn them on, because most viewers don’t need them.

Which one to use#

Three questions, three tools, each with its own names:

  • What people can do in this viewer: features, or readOnly. They name features, such as annotations and documents.download, and reach everywhere at once: every button, menu row, tab, panel and shortcut.
  • Where a button goes: the layout. It names buttons, such as tool:highlight and document:print, and changes one place: a bar or a menu. The feature still works everywhere else.
  • What this user may do: the scope. It names permissions, such as doc.download, and reaches everything, your code included: the engine refuses it.

A button shows when its feature is on, it’s in the layout, the scope allows it, and it makes sense right now (Copy needs a selection).

What to write#

Annotating, all of it or one tool:

// No annotating at all
{ features: { annotations: false } }
 
// No highlighter in any bar, and no shortcut
{ features: { 'annotations.highlight': false } }
 
// Only the highlighter, no other annotating
{
  features: {
    annotations: false,
    'annotations.highlight': true,
  },
}
 
// Highlighting from selected text only, not the Annotate bar
{
  layout: (layout) =>
    layout.remove('tool:highlight', { from: 'annotate' }),
}

The features that start off:

// Measuring
{ features: { measurement: true } }
 
// Redaction
{ features: { redaction: true } }
 
// Building forms: the Form tab
{ features: { 'forms.building': true } }
 
// Snapshots
{ features: { snapshots: true } }
 
// All four
{
  features: {
    measurement: true,
    redaction: true,
    'forms.building': true,
    snapshots: true,
  },
}

Downloading, printing and read-only:

// No downloading or printing in this viewer
{
  features: {
    'documents.download': false,
    'documents.print': false,
  },
}
 
// Read-only
{ readOnly: true }
 
// Read-only, but people fill in the form
{ readOnly: { except: ['forms.filling'] } }

To stop a user downloading, from your code too, leave doc.download out of their scope. To put a tool in a bar of your own, take it out of its bar with layout.remove(), or the whole Measure tab with layout.removeBar('measure'), and add it to yours.

Every feature#

All of them start on, except forms.building, redaction, measurement and snapshots. These change the document, and readOnly turns them off:

FeatureWhat it covers
annotations.highlight, .markup (underline, strike out, squiggly), .drawing (ink and ink highlighter), .text (text boxes, callouts, insert and replace text), .notes, .links
shapesSquares, circles, lines, arrows, polygons and polylines
stampsStamps and images
comments.writing (new comments and replies). readOnly turns off only this part, so people still read comments.
forms.filling, .building
signatures.signing, .checking. readOnly turns off only .signing.
redactionMarking redactions and applying them
measurementDistance, perimeter and area, and calibrating the scale
pagesRotating, moving, inserting and deleting pages in the thumbnails panel
attachments.adding (the attachment tool, and attaching and deleting files in the attachments panel). readOnly turns off only this part, so people still see and save the files.
outline.editing (adding, renaming, moving and deleting items). readOnly turns off only this part, so people still follow the outline.

These don’t change the document, and readOnly keeps them on:

FeatureWhat it covers
text.selection, .copy
searchSearching the text
thumbnailsThe thumbnails panel
snapshotsCopying or saving an area of a page as an image
documents.open, .download, .print, .tabs

A feature takes true or false, and so does each part, by its feature’s name and its own: 'annotations.highlight'. The dot makes it a string, so it goes in quotes.

When a feature and one of its parts are both there, the part wins, in any order:

{
  features: {
    annotations: false,
    'annotations.highlight': true,
  },
}

That’s highlighting and nothing else. A part added in a later version follows its feature, so here it stays off. The same goes the other way: forms: true turns on building forms too, while 'forms.building': true adds building to the filling that’s already on.

Extracting pages into a new PDF is a download: it goes with documents.download, so readOnly keeps it for your code (page:extract).

A mode tab disappears by itself when only its bar’s dependent groups, undo, redo and style, are left, so features: { shapes: false } removes the Shapes tab. Annotations, comments and form values already in the document still show; only making and changing them goes.

features and readOnly follow their props: change them while the viewer runs, and the tools disappear or come back without a reload. That’s how a feature can follow a user’s plan:

{ features: { measurement: user.plan === 'pro' } }

Read-only#

{ readOnly: true }

It turns off every feature that changes the document, marked in the table above. People still scroll, zoom, search, select and copy text, read annotations and comments, follow links, download and print, and take snapshots when they’re on. The tools just aren’t there, as in a PDF reader. To tell people why, add the View only label to your layout; it shows while nothing can change the document:

{
  readOnly: true,
  layout: (layout) =>
    layout.add(
      { custom: 'view-only' },
      { to: 'main', before: 'panel:search' },
    ),
}

readOnly comes after features, so measurement: true doesn’t bring the Measure tab back into a read-only viewer. Keep one way of changing the document with except, and use features for what else should go:

{
  readOnly: { except: ['forms.filling'] },
  features: {
    'documents.download': false,
    'documents.print': false,
  },
}

That’s a form people fill in and can’t otherwise change, with no download or print button. Here is readOnly: true with the same features, on a report someone marked up:

Loading live preview…

read-only.tsx
import { PDFViewer, type ViewerConfig } from '@embedpdf/viewer-react';

const report = 'https://www.embedpdf.com/pdfs/report.pdf';

const config: ViewerConfig = {
  readOnly: true,
  features: { 'documents.download': false, 'documents.print': false },
};

export default function App() {
  return <PDFViewer src={report} {...config} style={{ height: '100%' }} />;
}

Try it: the highlight, the underline and the red box around the “Documents opened” row show, and nothing changes them. The menu at the top left has no Download or Print, and search and copy still work.

What a user may do#

features and readOnly decide what the viewer offers. To decide what a user may do, give the document a scope: the list of permissions the engine checks on every call, from a button or from your code.

{
  scope: [
    'doc.open',
    'doc.render',
    'doc.text.select',
    'doc.text.search',
    'doc.annotate.read',
  ],
  identity: { displayName: 'Ada Lovelace' },
}

Without a scope, the user may do what the file allows: everything, unless the PDF restricts itself, such as no printing, as in Acrobat. scope: ['*'] ignores the file’s permission flags. The scope and every permission in it are the headless ones.

What the scope doesn’t allow is hidden, like a feature that’s off: a user without doc.annotate.modify gets no annotation tools and no Annotate tab, and one without doc.render.thumbnail (which doc.render includes) no thumbnails panel. To show those buttons greyed out instead, with the reason in their tooltip, for example to offer an upgrade:

{ notAllowed: 'disable' }

The PDF’s own restrictions#

A PDF can carry restrictions of its own, set by its author with an owner password, such as no printing or no copying. They count when the scope includes 'pdf.permissions', which grants what the file allows:

{ scope: ['pdf.permissions'] }

Permissions add up: a scope that lists 'doc.print' next to 'pdf.permissions' allows printing even when the file says no. To let the file decide, list 'pdf.permissions' and leave its permissions out. The same rule holds on the server, so a document behaves the same on both engines.

Your own code#

  • Commands follow the viewer. A command whose feature is off doesn’t run, from a button or from viewer.commands.execute(), because commands are what the interface does. Your own Snapshot button needs snapshots: true too.
  • Plugins follow the scope. viewer.get('form').importValues(…) works in a read-only viewer, so your app can fill in a form from its own data and show it read-only.

So features and readOnly are about the interface, and scope is about security. Someone who opens the browser’s developer tools can call the plugins too, so whatever a user truly may not do belongs in the scope.

Good to know#

Shortcuts don’t fall through#

A command that’s off or not allowed still catches its keys. Ctrl/Cmd+C on text the user may not copy says so, instead of the browser doing something else with the key.

Your own commands#

A command of yours joins a feature through categories, so features turns it off with it, and a name of your own makes a new feature: categories: ['acme.review'], then features: { 'acme.review': false }. A command that needs a permission says which with requires. See Buttons & commands.

One button, everywhere#

The layout takes a button out of one bar or menu, and its shortcut still works. To take a button out of every bar and menu and its shortcut too, while its feature stays, turn the command off in the commands plugin:

{
  plugins: {
    commands: { disabledCommands: ['zoom:in', 'zoom:out'] },
  },
}

disable, from 3.0#

disable still works, until 4.0: a feature in it counts as false under features, and a button in it as one in disabledCommands. Where both name the same feature, features wins.

Was this page helpful?

Your feedback goes directly to the documentation team.