GithubHelp home page GithubHelp logo

bijsterdee / jjalvarezlpdfjsviewerbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jjalvarezl/jjalvarezlpdfjsviewerbundle

0.0 0.0 0.0 3.69 MB

PDF.js bundle for Symfony 4

License: Apache License 2.0

JavaScript 88.21% PHP 0.73% CSS 5.86% HTML 2.20% Twig 3.00%

jjalvarezlpdfjsviewerbundle's Introduction

JjalvarezlPDFjsViewerBundle

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

jjalvarezlpdfjsviewerbundle's People

Contributors

jjalvarezl avatar bijsterdee avatar tijuan avatar wypalacz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.