Giter Site home page Giter Site logo

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 tijuan avatar wypalacz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jjalvarezlpdfjsviewerbundle's Issues

Symfony 4.3+ deprecation warning

Problem

I got a deprecation warning:

The "Symfony\Component\Config\Definition\Builder\TreeBuilder::root()" method called for the "jjalvarezl_pd_fjs_viewer" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead.

Path

/vendor/jjalvarezl/pdfjs-viewer-bundle/jjalvarezl/PDFjsViewerBundle/DependencyInjection/Configuration.php:21 {▼
    › $treeBuilder = new TreeBuilder();
    › $rootNode = $treeBuilder->root('jjalvarezl_pd_fjs_viewer');

Possible fix

    › $treeBuilder = new TreeBuilder('jjalvarezl_pd_fjs_viewer');

Please fix this.

Parameter blob or base64 PDF

Hello, could you make any changes, so that I can pass a file blob parameter or some base64 of the file contents?

$parameters = array(
'isPdfOutsideWebroot' => true,
//here would be a blob or the contents of the file
//instead of the file path
'pdf' => '/home/jjalvarezl/Descargas/123.pdf',
'deletePdfInTmpAfterRenderized' => false,
);

pdf.worker.js include-path is wrong when pdf.js is initiated from a web sub-dir

Hi, nice job on this library. It works great and saves us Symfony-heads a lot of effort. I tried to fix this issue myself but couldn't figure it out, due to the varying paths and includes based on dev/test vs. production, as well as the bower build dist versions, and not knowing which version your bundle is based on.
I'm on a shared, and very controlled hosting platform, and must use your installer to install to a sub-directory when pushing to production. The installer does all the right things except one, the JS that calls pdf.worker.js assumes: /bundles/jjalv..., but it needs to be: /mySubDir/bundles/jjalva...
I can fix it in dev with a symlink, but I can't do that in production because my app is self-contained in its own sub-directory.
Is there any possibility that this is an easy fix, or you could provide some clues on how to fix it? Thx!

PDF file is not showing

The PDF file is now showing put it is always downloaded. And the pdf viewer show this message.

Error 204, unexpected server response.

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.