---
title: "Add PDF functionality with PHP"
canonical_url: "https://www.nutrient.io/sdk/web/getting-started/other-frameworks/php/"
md_url: "https://www.nutrient.io/sdk/web/getting-started/other-frameworks/php.md"
last_updated: "2026-06-08T09:14:14.525Z"
description: "Learn how to integrate Nutrient Web SDK into your PHP application. Step-by-step guide for adding PDF viewing, editing, and annotation features."
---

# Add PDF functionality with PHP

Nutrient Web SDK is a JavaScript PDF library for viewing, annotating, and editing PDFs directly in the browser. Use it to add PDF capabilities to any web app.

This guide walks you through the steps to integrate Nutrient into your project. By the end, you’ll be able to render a PDF document in the user interface (UI).

**Test without installing**

You can test the SDK capabilities in our playground.

[Read more](https://nutrient.io/demo/sandbox)

## CDN installation

#### Note: Creating a new project (optional)

If you don’t yet have a PHP project set up, create a new folder with an `index.php` file and run:

```sh

php -S 127.0.0.1:8000

```

**Steps:**

1. To use Nutrient Viewer in your PHP project, include the following in your page to load the library from the CDN:

   ```html

   <script src="https://cdn.cloud.nutrient.io/pspdfkit-web@1.16.1/nutrient-viewer.js"></script>
   ```

   This will make the `NutrientViewer` object available globally in your page so you can initialize the viewer later.

## Rendering a PDF

**Steps:**

1. Add an empty `<div>` element with a defined width and height where Nutrient will be mounted:

   ```html

   <div id="nutrient" style="width: 100%; height: 100vh;"></div>
   ```

2. Add the following script to initialize the Nutrient Viewer:

   ```php

   <script>
     NutrientViewer.load({
       container: "#nutrient",

       document: "https://www.nutrient.io/downloads/nutrient-web-demo.pdf"
     }).then(function(instance) {
       console.log("Nutrient loaded", instance);
     }).catch(function(error) {
       console.error(error.message);
     });
   </script>
   ```

3. Here’s the full example of a complete `index.php` file you can use:

   ```html

   <!DOCTYPE html>
   <html>
     <head>
       <title>My App</title>
       <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     </head>
     <body>
       <div id="nutrient" style="width: 100%; height: 100vh;"></div>

       <script src="https://cdn.cloud.nutrient.io/pspdfkit-web@1.16.1/nutrient-viewer.js"></script>

       <script>
         NutrientViewer.load({
           container: "#nutrient",

           document: "https://www.nutrient.io/downloads/nutrient-web-demo.pdf",
         }).then(function (instance) {
             console.log("Nutrient loaded", instance);
           }).catch(function (error) {
             console.error("Failed to load Nutrient:", error.message);
           });
       </script>
     </body>
   </html>
   ```

4. Start your PHP server:

   ```sh

   php -S 127.0.0.1:8000
   ```

5. Visit `http://127.0.0.1:8000/index.php` in your browser.

For a full walkthrough, refer to our [PHP PDF viewer tutorial](https://www.nutrient.io/blog/how-to-build-a-php-pdf-viewer/).

### Optimizing load performance

If your app doesn't open a PDF immediately — for example, the user navigates to a viewer on a different page — call [`NutrientViewer.preloadWorker()`](https://www.nutrient.io/api/web/functions/NutrientViewer.preloadWorker.html) early in your app to fetch and compile the WebAssembly artifacts in the background. When `NutrientViewer.load()` runs later, it can start rendering without waiting for them.

```js

// Call early — for example, on app init or after login.
NutrientViewer.preloadWorker();

```

Refer to the [performance best practices](https://www.nutrient.io/guides/web/best-practices/performance.md) guide for more optimization techniques.




## Troubleshooting

**Facing issues?**

Visit the troubleshooting guide for solutions to some common errors.

[Read more](https://www.nutrient.io/guides/web/troubleshooting/common-issues.md)
---

## Related pages

- [Add PDF functionality with JavaScript + Vite](/sdk/web/getting-started/other-frameworks/javascript.md)
- [Add PDF functionality with Flutter](/sdk/web/getting-started/other-frameworks/flutter.md)
- [Add PDF functionality with Nuxt](/sdk/web/getting-started/other-frameworks/nuxt.md)
- [Add PDF functionality with ASP.NET](/sdk/web/getting-started/other-frameworks/aspnet.md)
- [Add PDF functionality with Laravel](/sdk/web/getting-started/other-frameworks/laravel.md)
- [Add PDF functionality with PWA](/sdk/web/getting-started/other-frameworks/pwa.md)
- [Add PDF functionality with Svelte](/sdk/web/getting-started/other-frameworks/svelte.md)
- [Add PDF functionality with jQuery](/sdk/web/getting-started/other-frameworks/jquery.md)
- [Add PDF functionality with Electron](/sdk/web/getting-started/other-frameworks/electron.md)
- [Add PDF functionality with Blazor](/sdk/web/getting-started/other-frameworks/blazor.md)
- [Add PDF functionality with Angular](/sdk/web/getting-started/other-frameworks/angular.md)
- [Add PDF viewing and editing to Vue applications](/sdk/web/getting-started/other-frameworks/vue.md)

