netandreus / pdfjs-viewer-bundle
此包提供了Mozilla的pdf.js与Symfony 4框架的集成,并允许在服务器端自定义参数。适用于Symfony 4.4+
v3.0.0
2020-09-24 14:47 UTC
Requires
- php: >=5.3.2
This package is not auto-updated.
Last update: 2024-09-21 08:41:58 UTC
README
此包提供了Mozilla的"PDF.JS库"与Symfony 4集成的简单方法,并支持不同的自定义参数。
以下功能得到支持:
- 访问网络目录之外的PDF。
- 可自定义PDF查看器选项。
- PDF.js集成至2017年3月23日。
可在以下位置获得:
为什么使用这个?
- 此包在服务器端渲染PDF。因此,您可以选择替代默认浏览器查看器,以便在不同的浏览器类型中更改PDF的加载方式。
- 此包可以访问服务器任何部分的文件。
- 此包可以在渲染PDF后将其删除。
安装
1) 下载JjalvarezlPDFjsViewerBundle
必须提供包名才能下载
$ php composer.phar require jjalvarezl/pdfjs-viewer-bundle
2) 启用包
在内核中启用包
<?php // config/bundles.php return [ // ... jjalvarezl\PDFjsViewerBundle\jjalvarezlPDFjsViewerBundle:class => ['all' => true], ];
3) 安装资源
别忘了安装资源,这是此包工作的唯一方式
$ php app/console assets:install --symlink --relative
使用前概念
首先,需要建立一些分类和初始概念,以便理解其工作原理
- Webroot:是Symfony的网页文件夹
- "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查看器。
支持
如果您看到任何错误或不正常之处,请通过电子邮件联系我。
您始终可以成为贡献者,或者您可以在此处添加问题