Yii2 PDFJS bundle of PDF.js plugin. PDF.js Portable Document Format (PDF) viewer.
Can now define custom CSS for the viewer, e.g. for the white background use:
<?= \yii2assets\pdfjs\PdfJs::widget([
'url'=> "somefile.pdf",
'options' => [
'viewerStyle' => "body {background-color: #fff;}",
]
]); ?>
Can now define additional URL params (More info ), e.g. to zoom to page width by default use:
<?= \yii2assets\pdfjs\PdfJs::widget([
'url'=> "somefile.pdf",
'options' => [
'additionalUrlParams' => "#zoom=page-width",
]
]); ?>
PDF.js updated to version 1.7.225 (latest stable as of 19.07.2017)
The preferred way to install this extension is through composer.
Either run
php composer require --prefer-dist yii2assets/yii2-pdfjs ">=1.0"
or add
"yii2assets/yii2-pdfjs": ">=1.0"
to the require section of your composer.json
file.
The extension has been created as a module to enable access preview pdf
file. you must add the module to your configuration file.
//....
'modules'=>[
'pdfjs' => [
'class' => '\yii2assets\pdfjs\Module',
],
],
//...
Once the extension is installed, simply use it in your code by :
<?php
use yii\helpers\Url;
?>
<?= \yii2assets\pdfjs\PdfJs::widget([
'url'=> Url::base().'/downloads/manualStart_up.pdf'
]); ?>
<?php
use yii\bootstrap\Modal;
use yii\helpers\Url;
Modal::begin([
'header' => '<h2>Hello world</h2>',
'toggleButton' => ['label' => 'click me'],
]);
echo \yii2assets\pdfjs\PdfJs::widget([
'url' => Url::base().'/downloads/manualStart_up.pdf'
]);
Modal::end();
?>
http://app-url/index.php?r=pdfjs&file=download/manualStart_up.pdf
<?php
use yii\helpers\Url;
?>
<?= \yii2assets\pdfjs\PdfJs::widget([
'width'=>'100%',
'heith'=> '500px',
'url'=> Url::base().'/downloads/pdfjs.pdf'
]);
?>
<?php
use yii\helpers\Url;
?>
<?= \yii2assets\pdfjs\PdfJs::widget([
'url'=> Url::base().'/downloads/pdfjs.pdf',
'buttons'=>[
'presentationMode' => false,
'openFile' => false,
'print' => true,
'download' => true,
'viewBookmark' => false,
'secondaryToolbarToggle' => false
]
]);
?>
//....
'modules'=>[
'pdfjs' => [
'class' => '\yii2assets\pdfjs\Module',
'waterMark'=>[
'text'=>' Yii2 PDF.JS',
'color'=> 'red',
'alpha'=>'0.3'
]
],
],
//...