steamulo/pdfjs-viewer-bundle

该包提供了Mozilla的pdf.js与Symfony 4框架的集成,并在服务器端提供可自定义的参数。

安装次数: 3,661

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 13

语言:JavaScript

类型:symfony-bundle

v4.0.0 2023-01-31 16:26 UTC

This package is auto-updated.

Last update: 2024-09-29 05:36:28 UTC


README

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

该包提供了一种将Mozilla的"PDF.JS库"简单集成到Symfony 4中的方法,具有不同的自定义参数。

支持以下功能

  • 访问网目录之外的PDF文件。
  • 可自定义的PDF查看器选项。
  • 至2017年3月23日整合了PDF.js。

可在以下位置找到

为什么使用这个?

  • 该包在服务器端渲染PDF。因此,您可以选择替代默认的浏览器查看器,以便在不同的浏览器类型上以不同的方式加载PDF。
  • 该包可以访问服务器上的任何部分的文件。
  • 该包可以在渲染后删除PDF。

安装

1) 下载JjalvarezlPDFjsViewerBundle

必须提供包的名称才能下载它

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

2) 启用包

在内核中启用包

<?php
// config/bundles.php

return [
    // ...

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

3) 安装资产

别忘了安装资产,这是此包工作的唯一方式

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

使用前概念

首先,需要建立一些分类和基本概念,以便了解其工作原理

  • Webroot:是Symfony的Web文件夹
  • "PDF.js"仅在所有类型的项目中的Webroot文件夹中工作。
  • 此包使"PDF.js"能够在需要获取PDF文件的地方显示PDF文件。
  • 它会在Webroot中的自定义临时目录(由开发人员定义)中创建PDF文件的绝对路径的临时副本。因此,请确保正确的权限(文件+所有者)。
  • 一旦"PDF.js"加载了PDF文件,此包就可以立即将其从Webroot删除,以避免诸如磁盘空间溢出等问题。
  • 此包还可以显示或隐藏可视的"PDF.js"组件。

所有这些功能都可以通过以下参数执行,这些参数只有true/false值

使用方法

您可以选择不同的方式来使用此包

快速测试

您可以在多个浏览器中验证功能,您可以在功能控制器中启用默认的"PDF.js查看器",并返回相同的加载PDF的响应

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

默认查看器

这显示与快速测试相同的PDF查看器,但需要配置一些额外的参数

$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);

自定义查看器

此外,您可以通过编辑参数来自定义要显示的查看器元素

$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);

在这里,您可以随心所欲地玩这些参数来定制PDF查看器。

支持

如果您看到任何错误或不正常的情况,请通过电子邮件联系我。

您始终可以成为贡献者,或者您可以在以下链接处提交问题