PDF Embed API basics

The samples and documentation provide an easy way to jump-start development. The sections below describe how to embed a customized PDF viewer in a web page.

Embed a PDF viewer

Once you've received your client ID, embedding the PDF viewer involves:

  1. Adding a <script> tag to load the PDF Embed API by source url: https://acrobatservices.adobe.com/view-sdk/viewer.js (line 6).
  2. Setting up the rendering area: use a div tag with an ID of adobe-dc-view (line 9).
  3. Initializing the PDF Embed API by passing client ID, and call previewFile with PDF file URL and file name as shown from line 13 to line 18.

As shown below, PDF details are passed in an object which consists of two fields:

This table lists down the various options which can be passed in metaData. <br/>

Variable
Default
Description
fileName
None
The name of the PDF to be rendered. An example of fileName is "Bodea Brochure.pdf". Note that fileName is mandatory.
id
None
Pass the PDF ID when annotation APIs are enabled to uniquely identify the PDF. For more details, see Annotations API overview.
hasReadOnlyAccess
false
Set this flag to true if you want to render the PDF in read-only mode. Commenting is not allowed and existing PDF comments are displayed as read only.

That's it! View the page in a browser to see your fully functional PDF viewer.

<html>
<head>
  <title>Your title</title>
  <meta charset="utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  <script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
</head>
<body>
  <div id="adobe-dc-view"></div>
  <script type="text/javascript">
   document.addEventListener("adobe_dc_view_sdk.ready", function()
   {
      var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
      adobeDCView.previewFile(
     {
         content:  {location: {url: "<Path to your PDF/yourfilename.pdf">}},
         metaData: {fileName: "yourfilename.pdf"}
     });
   });
  </script>
</body>
</html>
<!--Get the samples from https://www.adobe.com/go/pdfembedapi_samples-->
data-slots=text
The timeout for file rendering is 5 minutes. If the file exceeds this limit there will be a Preview Rendering Failed error.

Passing file content

As shown above, you pass PDF data via the content field either as a file URL or file promise. The metaData field with a mandatory filename is required for both methods.

adobeDCView.previewFile({
  content: {location (URL) OR promise (File blob)},
  metaData: {fileName (always required) + optional fields }
})
data-slots=text
If you pass both a file URL and file promise, the promise is used and the URL value is ignored.

File URL

Passing PDF data via a URL is self-explanatory, but note that some scenarios require special handling.

Token-based authentication

When a file URL resides behind token-based authentication and use custom headers, pass both the URL and the headers as follows:

adobeDCView.previewFile({
   content: {
       location: {
          url: <filepath>,
          headers:[{key: ..., value: ...}, ...]
       },
   },
   metaData: {fileName: <filename> }
})

Cookie-based authentication

When a file URL uses cookie-based authentication, set downloadWithCredentials to true when initialising the AdobeDC.View object:

var adobeDCView = new AdobeDC.View({
    ...
    downloadWithCredentials: true,
});

Cross-origin resource sharing

Cross-origin resource sharing (CORS) issues may occur when you pass PDF content as a URL and the PDF Embed API needs to download the file from the provided location in order to render it. To avoid this situation, you can choose one of two methods:

File promise

If the file content is available as an ArrayBuffer (for example, local PDF files), then it can be passed directly as a Promise which should resolve to the ArrayBuffer of the file content.

adobeDCView.previewFile({
    content: { promise: <FILE_PROMISE> }
    metaData: { fileName: <FILE_NAME> }
});

One way to create a file promise is to allow users to choose a local file for upload. In your HTML, you could do the following:

<label for="file-picker"> Choose a PDF file:</label>
<input type="file" id="file-picker" accept="application/pdf">

Once the file uploads, you could use a helper function to read the file and pass it to adobeDCView.previewFile:

function listenForFileUpload() {
  var fileToRead = document.getElementById("file-picker");
  fileToRead.addEventListener("change", function(event) {
     var files = fileToRead.files;
     if (files.length > 0) {
        var reader = new FileReader();
        reader.onloadend = function(e) {
            var filePromise = Promise.resolve(e.target.result);
            // Pass the filePromise and name of the file to the previewFile API
            adobeDCView.previewFile({
                 content: {promise: filePromise}
                 metaData: { fileName: files[0].name }
            })
        };
        reader.readAsArrayBuffer(files[0]);
      }
    }, false);
}

Embed modes

The PDF Embed API's embed modes govern the PDF viewing area's size and position within a web page. Available options allow you to control the viewing experience and layout much like you would an image, video, or any other web content. In order to use any of the available modes, pass the mode name along with other preview configurations in the previewFile API. For example, you could set "FULL_WINDOW", "SIZED_CONTAINER", "IN_LINE" or "LIGHT_BOX" as the embedMode value (line 5):

adobeDCView.previewFile({
   content: { ... },
   metaData: { ... }
      },
  {embedMode: "<FULL_WINDOW, SIZED_CONTAINER, IN_LINE OR LIGHT_BOX>",
   showDownloadPDF: ...,
   showPrintPDF: ...
      }
);
data-slots=text
To view the code in action, see the online demo or run the embed mode samples on your machine.

Embed mode overview

Embed mode
Description
Example
Full window (default mode)
Renders the PDF viewer into the full height and width of the parent element. Best suited for storage and productivity applications.
_images/embedfull.png
Sized container
The sized container mode displays PDFs in a boxed container with landscape orientation. Best suited for presentations.
_images/embedsized.png
In-Line
All PDF pages rendered in line within a web page. Best suited for reading applications.
_images/embedinline.png
Lightbox
Displays PDFs in a focused view. Best suited for content websites, content portals, and email.
_images/lightbox.png

Full window embed mode

This embed mode renders the PDF viewer into the full height and width of the parent element. It is different from sized container in that full window embed mode enables all of the annotation tools as well as other options included in Embed API to be available in the Embed UI. This mode is best suited for storage and productivity applications. Note that this embed mode applies by default, even when no embed mode value is passed. (Full Window Demo)

To use this mode:

data-slots=text
For the complete list of supported preview configurations, see the section Menu and tool options.
<div id="adobe-dc-view"></div>
<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
  document.addEventListener("adobe_dc_view_sdk.ready", function(){
    var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
    adobeDCView.previewFile({
      content:{location: {url: "https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"}},
      metaData:{fileName: "Bodea Brochure.pdf"}
    }, { embedMode: "FULL_WINDOW", defaultViewMode: "FIT_PAGE", showAnnotationTools: true, showDownloadPDF: true });
  });
</script>

Image for full window embed mode

Forms handling

The PDF Embed API supports live form editing by default. End users can add and edit text in text fields and interact with other form objects, including radio buttons, check boxes, lists, and drop downs (select lists). When users fill any form field, the Save button on the top bar is automatically enabled so that they can save their information to the PDF. The PDF Embed API renders forms so that they appear similar to forms viewed in the full Acrobat app:

Image for form-filling in full window embed mode

data-slots=text
Form editing capability is supported only in Full Window embed mode.

Control form editing capability by simply toggling enableFormFilling on and off as needed. While the Embed API enables form editing by default, you can disable the feature by setting it to false.

<div id="adobe-dc-view"></div>
<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
   document.addEventListener("adobe_dc_view_sdk.ready", function () {
      var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
      adobeDCView.previewFile({
         content:{location: {url: "https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"}},
         metaData:{fileName: "Bodea Brochure.pdf"}
      }, { embedMode: "FULL_WINDOW", enableFormFilling: false });
   });
</script>

Disabling form editing un-highlights form fields:

Disabling form editing

Unsupported form fields

In the current version, following form fields are unsupported:

When the API detects unsuppported form fields, a dialog appears on the rendered PDF:

No Support for Form Fields message

Sized container embed mode

The sized container mode displays PDFs in a boxed container with landscape orientation. Each page appears as a slide, so this mode works well for presentations and other workflows that require accurate placement of the PDF content within other content. (Sized Container Demo)

To use this mode:

<div id="adobe-dc-view" style="height: 360px; width: 500px;"></div>
<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
  document.addEventListener("adobe_dc_view_sdk.ready", function(){
    var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
    adobeDCView.previewFile({
      content:{location: {url: "https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"}},
      metaData:{fileName: "Bodea Brochure.pdf"}
    }, { embedMode: "SIZED_CONTAINER", showFullScreen: true });
  });
</script>

Sized Container

Toggling full screen

To display the PDF in full screen view, choose the full screen mode button in the bottom toolbar. In the full screen mode, the top bar contains a traditional exit (X) button which returns full screen mode to normal mode. The full screen mode also displays a right-hand panel which contains various options such as page thumbnails, bookmarks and page navigation options. In mobile browsers, the user will be prompted to view the PDF in full screen mode for optimal reading. You can exit full screen mode in mobile browsers by swiping down.

Full screen button in sized container embed mode

Sized Container full screen button

Exit button in sized container full screen mode

Sized Container full screen view

In-Line embed mode

In-Line mode renders PDF pages inline with other web page content. In this mode, all PDF pages are displayed at once which enables easy and smooth navigation. In this mode you need only specify the width of the embedded viewer in the enclosing div tag since the viewer height is automatically sized for the number of PDF pages. This mode is ideal for whitepapers, brochures, e-books, and other reading applications. (In-Line Demo)

To use this mode:

<div id="adobe-dc-view" style="width: 800px;"></div>
<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
   document.addEventListener("adobe_dc_view_sdk.ready", function(){
     var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
   adobeDCView.previewFile({
     content:{location: {url: "https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"}},
     metaData:{fileName: "Bodea Brochure.pdf"}
 }, { embedMode: "IN_LINE", showPrintPDF: true });
 });
</script>

Inline Search

Lightbox mode renders the PDF in the foreground at top of the page. The background remains visible, but the focus is on the previewed PDF. The top bar provides configurable Close and Back buttons. The Close button appears by default. (Lightbox Demo)

To use this mode:

<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
    document.addEventListener("adobe_dc_view_sdk.ready", function(){
        var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>"});
        adobeDCView.previewFile({
            content:{location: {url: "https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"}},
            metaData:{fileName: "Bodea Brochure.pdf"}
        }, {embedMode: "LIGHT_BOX", exitPDFViewerType: "CLOSE"});
    });
</script>

Top bar with Close button (exitPDFViewerType: "CLOSE")

Image for lightbox embed mode

Top bar with Back button (exitPDFViewerType: "RETURN")

Image for lightbox embed mode with back button

Focus on PDF rendering

Using PDF Embed API, website developers have the flexibility to control if the PDF should take focus when it is rendered within a website.

This is achieved through the variable focusOnRendering which can be passed as a configuration to the previewFile API. This variable accepts a Boolean value.

adobeDCView.previewFile({
  content:{location: {url: "<URL_OF_PDF>"}},
  metaData:{fileName: "<FILE_NAME>"}
}, {embedMode: "<EMBED_MODE>", focusOnRendering: true});

The default value of this configuration variable varies according to the embed mode.

| Embed mode | Default value of focusOnRendering | Default behaviour | | | --------------- | --------------------------------------------------- | ------------------------------------------------------------------ | | Full window | true | Acquires focus when PDF is rendered. | | Sized container | false | Doesn’t acquire focus when PDF is rendered. | Doesn’t acquire focus when PDF is rendered. | | In-Line | false | Doesn’t acquire focus when PDF is rendered. | Doesn’t acquire focus when PDF is rendered. | | Lightbox | true (Cannot be set to false) | Always acquires focus when PDF is rendered. This cannot be changed.|

data-slots=text
The PDF will always acquire focus in Lightbox embed mode since this embed mode is intended to provide a focused view of the PDF by opening the PDF viewer on top of the webpage. This default behaviour in Lightbox embed mode cannot be changed.

The default behaviour of taking focus can be modified for all embed modes (except lightbox).

PDF Linearization

Linearization is an approach to optimize PDFs for faster viewing by displaying the first page as quickly as possible before the entire PDF gets downloaded. Linearized PDFs contain information so that pages can be streamed one at a time via byte range requests from a server. Linearization is extremely useful for displaying large-sized documents as well as displaying documents on slow networks, thus providing an overall faster PDF viewing experience.

PDF Embed API supports the rendering of linearized PDFs which are hosted on servers with byte-range support.

For details, see Enabling byte-streaming on a server.

Display linearized PDFs

In order to display linearized PDFs using PDF Embed API, set the variable enableLinearization to true (default value is false) and pass it as a preview configuration to the previewFile API.

As described in the section Passing file content, the linearized PDF can be passed as a file URL or file Promise.

File URL

Pass the URL of the linearized PDF in the content field and invoke the previewFile API.

<div id="adobe-dc-view"></div>
<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
  document.addEventListener("adobe_dc_view_sdk.ready", function() {
    var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
    var previewFilePromise = adobeDCView.previewFile({
      content:   {location: {url: "<URL_OF_LINEARIZED_PDF>"}},
      metaData:  {fileName: "<FILE_NAME>"}
    },
    {
      enableLinearization: true,
    });
  });
</script>

File Promise

If the file content is available as an ArrayBuffer, then it can be passed directly as a Promise resolving to the ArrayBuffer of the file content.

Pass this file promise in the content field. Along with this, it is mandatory to pass an object called the linearizationInfo in the content field.

The linearizationInfo object will contain the following three functions:

getInfo()

Returns a Promise which,

getInitialBuffer()

Returns a Promise which,

getFileBufferRanges()

Returns a Promise which,

If the ranges array contains more than one object, then there are two ways to fetch the file buffers:

  1. Make separate calls for each range object present in ranges array and return the combined result.
  2. Make a single call with Range header value set to comma separated start-end values for each range object (for example: "bytes=0-1024, 1024-2048").
data-slots=text
  • If you pass both a file URL and file promise for a linearized PDF, the promise is used and the URL value is ignored.
  • If you use file promise, then it is mandatory to pass the linearizationInfo object. The linearizationInfo object should contain all the 3 functions: getInfo(), getInitialBuffer() and getFileBufferRanges().

Note that the website developer can provide their custom implementation of these functions and pass it to the linearizationInfo object.

<div id="adobe-dc-view"></div>
<script src="https://acrobatservices.adobe.com/view-sdk/viewer.js"></script>
<script type="text/javascript">
  document.addEventListener("adobe_dc_view_sdk.ready", function() {
    const linearizationInfoObject = {
      getInfo: () => getInfo(),
      getInitialBuffer: () => getInitialBuffer(),
      getFileBufferRanges: ranges => getFileBufferRanges(ranges)
    };

    var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});
    var previewFilePromise = adobeDCView.previewFile({
      content:   {
        promise: <FILE_PROMISE>,
        linearizationInfo: linearizationInfoObject
      },
      metaData:  {fileName: "<FILE_NAME>"}
    },
    {
      enableLinearization: true,
    });

    function getInfo() {
      /* Write down your own implementation here */
      return new Promise((resolve, reject) => {
        resolve({
          fileSize: <FILE_SIZE>
        });
      });
    }

    function getInitialBuffer() {
      /* Write down your own implementation here */
      return new Promise((resolve, reject) => {
        resolve({
          buffer: <ARRAY_BUFFER>
        });
      });
    }

    function getFileBufferRanges(ranges) {
      /* Write down your own implementation here */
      /* Ranges parameter
         ranges: [{ start: NUMBER, end: NUMBER}, { start: NUMBER, end: NUMBER}, . . .]
      */
      return new Promise((resolve, reject) => {
        resolve({
          bufferList: [
            <ARRAY_BUFFER>,
            <ARRAY_BUFFER>,
             . . .
          ]
        });
      });
    }
  });
</script>
data-slots=text
Find the working code sample here under /More Samples/Linearization

Supported browsers and platforms

Displaying linearized PDFs using PDF Embed API will work in browsers which support SharedArrayBuffer, such as Chrome and Chromium-based Microsoft Edge desktop browsers. In case of other desktop browsers and mobile browsers, it will automatically fall back to the normal behaviour (non-linearized flow) of downloading the entire PDF before file preview.

Other supported functionalities

Enabling byte-streaming on a server

The server where the linearized PDFs are hosted should have support of byte-streaming to be able to send partial file content via HTTP 206 calls.

For example, you can follow these steps to enable byte-streaming in an Apache 2.4 server.

Open httpd.conf and make below changes:

  1. Uncomment this line: LoadModule headers_module modules/mod_headers.so
  2. In your respective <Directory>, set headers
<Directory "${SRVROOT}/htdocs/<__location_of_PDFs_____>">
   <IfModule mod_headers.c>
     # To allow byte-streaming and range support
     Header set Access-Control-Allow-Headers "Range"
   </IfModule>
</Directory> 

Please see this article to know more about Access-Control-Allow-Headers.

Language support

The PDF Embed API supports a number of languages. The default language is English (en-US), but you can select another language by passing the locale code variable when creating the AdobeDC.View object.

var adobeDCView = new AdobeDC.View({
    clientID: "<YOUR_CLIENT_ID>",
    divId: "adobe-dc-view",
    locale: "ja-JP",

Supported languages

Language
Locale Code
Danish
da-DK
Dutch
nl-NL
English (United Kingdom)
en-GB
English (United States)
en-US
Finnish
fi-FI
French
fr-FR
German
de-DE
Italian
it-IT
Japanese
ja-JP
Norwegian
nb-NO
Portuguese
pt-BR
Spanish
es-ES
Swedish
sv-SE
Czech
cs-CZ
Korean
ko-KR
Polish
pl-PL
Russian
ru-RU
Turkish
tr-TR
Chinese
zh-CN
Chinese
zh-TW

Troubleshooting

Troubleshooting a web app and the PDF Embed API is straightforward web development. Use the tools you're familiar with; for example, your IDE or Chrome Developer Tools.

Why is my URL value not used to access the PDF data?

If you pass both a file URL and file promise, the promise is used and the URL value is ignored.

Why do I see the error "Invalid client Id provided"?

Either your client ID is incorrect, or you are using it on a domain other than the one you registered.