jjalvarezl/pdfjs-viewer-bundle

This bundle provides an integration of pdf.js from mozilla with Symfony 4 framework and customizable parameters on server side.

Installs: 37 719

Dependents: 0

Suggesters: 0

Security: 0

Stars: 10

Watchers: 0

Forks: 13

Open Issues: 7

Language:JavaScript

Type:symfony-bundle

v3.0.0 2018-03-01 18:43 UTC

This package is not auto-updated.

Last update: 2024-12-17 10:51:38 UTC


README

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

This bundle provides a simple integration of the "PDF.JS library" from mozilla into Symfony 4 with different custom parameters.

Following features are supported:

  • Access to pdf outside from web directory.
  • Customizable pdf viewer options.
  • PDF.js incorporated until 23/03/2017.

Available at:

Why use this?:

  • This bundle renders a pdf with on server side. For this reazon you can have an alternative solution to the default browser viewer that can variate the way that a pdf can be loaded on each browser type.
  • This bundle can access files in every part of the server.
  • This bundle can delete the pdf after rendering it.

Installation

1) Download JjalvarezlPDFjsViewerBundle

Its necessary to provide the bundle's name in order to download it:

$ php composer.phar require jjalvarezl/pdfjs-viewer-bundle

2) Enable the bundle

Enable the bundle in the kernel:

<?php
// config/bundles.php

return [
    // ...

    jjalvarezl\PDFjsViewerBundle\jjalvarezlPDFjsViewerBundle:class => ['all' => true],
];

3) Install assets

Don't forget to install assets, is the only way that this bundle works:

$ php app/console assets:install --symlink --relative

Concepts before usage:

First at all, its necessary to establish some taxonomy an initial concepts in order to understand how it works:

  • Webroot: is the web folder of Symfony
  • "PDF.js" works only in webroot folders in all kind of projects.
  • This bundle enables to "PDF.js" to show pdf files in any place that you need to obtain them.
  • It makes a temporal copy with the absolute path of the pdf file in a custom temporal dir inside webroot (defined by the developer). So make sure about the right permissions (files + owner).
  • Once "PDF.js" loads the pdf file, this bundle can immediately delete it from webroot in order to avoid issues such as disk space overflow.
  • This bundle also can show or hide visual "PDF.js" components.

All those features can be performed with parameters which have only true / false values as follows:

Usage

You can choose from different ways to use this bundle:

Fast testing

You can verify functionality in multiple browsers, you can enable the default "PDF.js viewer" with same loaded pdf in your function controller that returns a response:

return $this->get('jjalvarezl_pdfjs_viewer.viewer_controller')->renderTestViewer();

Default viewer

This shows same pdf viewer as the fast testing but its necessary to configure some extra parameters:

$parameters = array(
        //Tell to the bundle that the pdf is outside the webroot
        'isPdfOutsideWebroot' => true,

        //Tell to the bundle where is the pdf. (absolute path for outside temporal folder pdf, just the <name>.pdf for inside temporal folder)
        'pdf' => '/home/jjalvarezl/Descargas/123.pdf',

        //Tell to the bundle that its necessary to delete pdf after render.
        'deletePdfInTmpAfterRenderized' => false,
    );

return $this->get('jjalvarezl_pdfjs_viewer.viewer_controller')->renderDefaultViewer($parameters);

Custom viewer

Also, you can customize which elements from viewer you want to display by editing the parameters:

$parameters = array(
        //Same parameters as defalt viewer.

        //pdf.js viewer options
        'showToolBar' => true,
        'showLeftToolbarButton' => true,
        'showSearchInDocumentButton' => true,
        'showPreviousPageButton' => true,
        'showPreviousPageButton' => true,
        'showFindPageInputText' => true,
        'showNumberOfPagesLabel' => true,
        'showZoomInButton'=> false,
        'showZoomOutButton'=> false,
        'showScaleSelectComboBox'=> false,
        'showPresentationModeButton'=> true,
        'showOpenFileButton'=> true,
        'showPrintButton'=> true,
        'showDownloadButton'=> true,
        'showViewBookmarkButton'=> true,
        'showToolsButton'=> true,
    );

return $this->get('jjalvarezl_pdfjs_viewer.viewer_controller')->renderCustomViewer($parameters);

Here you can play with this parameters as you wish for customize the pdf viewer.

Support

Please email me if you see something wrong or abnormal.

You can always be a contributor or you can add an issue here