# # Integration

This section will help you to quickly get started with using Foxit PDF SDK for Web to build a simple web PDF viewer and a full-featured PDF viewer with step-by-step instructions provided.

## # Preparations

### # Create a new web project

1. Create a new directory as a project folder, such as "D:/test_web".
2. Copy the " lib", " server", and " external" (if you need to use the font resources) folders, as well as the " package.json" file from Foxit PDF SDK for Web package to "D:/test_web".
3. Copy a PDF file (for example, the demo guide in the "docs" folder) to "D:/test_web".
4. Create a html file (index.html) in the "D:/test_web" folder. Then the directory structure is:

    test_web
        +-- lib          (copy from the Foxit PDF SDK for Web package)
        +-- server       (copy from the Foxit PDF SDK for Web package)
        +-- package.json (copy from the Foxit PDF SDK for Web package)
        +-- index.html

    <html>
    <head>
        <meta charset="utf-8">
        <style>
            .fv__ui-tab-nav li span {
                color: #636363;
            }
            .flex-row {
                display: flex;
                flex-direction: row;
            }
        </style>
        <!-- ignore other unimportant code -->
    </head>
    <body>
    </body>
    </html>

## # Integrate the basic webViewer into your project

This section will describe how to integrate the basic webViewer sample using PDFViewCtrl based on the above created project. Just follow the steps below:

1. Add styles (/lib/PDFViewCtrl.css) to the `<head>` tag of the HTML page:

    <link rel="stylesheet" type="text/css" href="./lib/PDFViewCtrl.css">

2. Import the "PDFViewCtrl.full.js" library found in the "lib" folder:

    <script src="./lib/PDFViewCtrl.full.js"></script>

3. In the HTML `<body>` tag, add the `<div>` elements as the webViewer container:

    <div id="pdf-viewer"></div>

4. Initialize PDFViewer:

    <script>
         var licenseSN = "Your license SN";
         var licenseKey = "Your license Key";
    </script>
    <script>
         var PDFViewer = PDFViewCtrl.PDFViewer;
         var pdfViewer = new PDFViewer({
             libPath: './lib', // the library path of Web SDK.
             jr: {
                 licenseSN: licenseSN,
                 licenseKey: licenseKey,
             }
         });
         pdfViewer.init('#pdf-viewer'); // the div (id="pdf-viewer")
    <script>

Note : The trial values of licenseSN and licenseKey can be found in the examples/license-key.js file of Foxit PDF SDK for Web folder.

5. Open a PDF document:

    // modify the file path as your need.
    fetch('/docs/FoxitPDFSDKforWeb_DemoGuide.pdf').then(function(response) {
        response.arrayBuffer().then(function(buffer) {
            pdfViewer.openPDFByFile(buffer);
        })
    })

The above steps are the key points of integrating the simple demo to your created project using PDFViewCtrl. After finishing it, refresh your browser (<index.html>).

Now, in this simple web PDF viewer, you can zoom in/out the PDF document by right-clicking anywhere on the page to select the zoom in or zoom out options.

The whole content of the index.html is:

    <html>
    <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="./lib/PDFViewCtrl.css">

    <!-- You can delete the following style because it doesn't work in this project -->
        <style>
            .fv__ui-tab-nav li span {
                color: #636363;
            }
            .flex-row {
                display: flex;
                flex-direction: row;
            }
    </style>
        <!-- ignore other unimportant code -->
    </head>
    <body>
        <div id="pdf-viewer"></div>
        <script src="./lib/PDFViewCtrl.full.js"></script>
        <script>
            var licenseSN = "Your license SN";
            var licenseKey = "Your license Key";
        </script>
        <script>
            var PDFViewer = PDFViewCtrl.PDFViewer;
            var pdfViewer = new PDFViewer({
                libPath: './lib', // the library path of Web SDK.
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey,
                }
            });
            pdfViewer.init('#pdf-viewer'); // the div (id="pdf-viewer")

            // modify the file path as your need.
            fetch('/FoxitPDFSDKforWeb_DemoGuide.pdf').then(function (response) {
                response.arrayBuffer().then(function (buffer) {
                    pdfViewer.openPDFByFile(buffer);
                })
            })

        </script>
    </body>
    </html>

## # Integrate the complete webViewer into your project

The previous section introduces how to integrate the basic webViewer sample using PDFViewCtrl, which is just a simple web PDF viewer. In this section, we will show you how to integrate the advanced webViewer using UIExtension base on Preparations. Follow the steps below:

1. Add styles (/lib/UIExtension.css) to the `<head>` tag of the HTML page.

    <link rel="stylesheet" type="text/css" href="./lib/UIExtension.css">

2. Import the "UIExtension.full.js" library found in the "lib" folder:

    <script src="./lib/UIExtension.full.js"></script>

3. In the HTML `<body>` tag, add the `<div>` elements as the webViewer container:

    <div id="pdf-ui"></div>

4. Initialize UIExtension:

    <script>
         var licenseSN = "Your license SN";
         var licenseKey = "Your license Key";
    </script>
    <script>
        var pdfui = new UIExtension.PDFUI({
            viewerOptions: {
                libPath: './lib', // the library path of web sdk.
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey
                }
            },
            renderTo: '#pdf-ui' // the div (id="pdf-ui").
        });
    </script>

Note : The trial values of licenseSN and licenseKey can be found in the examples/license-key.js file of Foxit PDF SDK for Web folder.

5. Open a PDF document:

    // modify the file path as your need.
    fetch('/docs/FoxitPDFSDKforWeb_DemoGuide.pdf').then(function(response) {
        response.arrayBuffer().then(function(buffer) {
            pdfui.openPDFByFile(buffer);
        })
    })

The above steps are the key points of integrating the advanced webViewer to your created project using UIExtension. After finishing it, refresh your browser (<index.html>).

Now, it is a full-featured web PDF viewer, you can view/edit/comment/protect the PDF document as desired.

The whole content of the index.html is:

    <html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="./lib/UIExtension.css">
        <style>
            .fv__ui-tab-nav li span {
                color: #636363;
            }
            .flex-row {
                display: flex;
                flex-direction: row;
            }
        </style>
        <!-- ignore other unimportant code -->
    </head>
    <body>
        <div id="pdf-ui"></div>
        <script src="./lib/UIExtension.full.js"></script>
        <script>
            var licenseSN = "Your license SN";
            var licenseKey = "Your license Key";
        </script>
        <script>
            var pdfui = new UIExtension.PDFUI({
                viewerOptions: {
                    libPath: './lib', // the library path of web sdk.
                    jr: {
                        licenseSN: licenseSN,
                        licenseKey: licenseKey
                    }
                },
                renderTo: '#pdf-ui' // the div (id="pdf-ui").
            });

            // modify the file path as your need.
            fetch('/FoxitPDFSDKforWeb_DemoGuide.pdf').then(function (response) {
                response.arrayBuffer().then(function (buffer) {
                    pdfui.openPDFByFile(buffer);
                })
            })

        </script>
    </body>
    </html>

## # Integration Modes

### # Integrate as a Global Variable

You can integrate the Foxit PDF SDK for Web to your project as a global variable:

    <script src="./lib/PDFViewCtrl.full.js"></script>
    <script>
    var PDFViewer = PDFViewCtrl.PDFViewer;
    var pdfViewer = new PDFViewer(…)
    </script>

For a working example, check out the complete_WebViewer.

### # Integrate as Module

For more integration modes, you may want to check our working examples integrate as module.