V
V
Vladislav Sofienko2017-10-12 18:26:52
Yii
Vladislav Sofienko, 2017-10-12 18:26:52

How to make Yii2Assets/yii2-pdfjs work?

Hello. Has anyone used Yii2Assets/yii2-pdfjs in the Advanced version of Yii2? How to make it work? And in general, how to use the pdfjs library on Yii2? It gives an error in the browser console that it cannot load /assets/1b17959a/yii2-pdfjs.js
I did everything as per the dock . I installed the extension via composer, included the module in common/config/main.php and then called the widget in the view

<?= \yii2assets\pdfjs\PdfJs::widget([
  'url'=> 'domain.ru/files/doc/test_pdf.pdf'
]); ?>

There is nothing in the frame but a dark blue background and, judging by the console, it is empty.
This extension works in the basic version of yii2, but refuses in advanced.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-10-12
@slo_nik

It throws an error in the browser console that it cannot load /assets/1b17959a/yii2-pdfjs.js

And this already applies to AssetBundle .
read the documentation and change this parameter to the correct one PS Actually, you can do without the plugin. This is the case if you only need viewing and the ability to download a pdf file. To do this, upload the file to the web directory, or to a specially created directory. On the page from which you want to open the file, create the following link:
In the controller, for example in SiteController, create an action:
public function actionDownload()
    {
        $path = Yii::getAlias('@webroot') . '/pdf/'; // путь к директории web/pdf в которую загружен файл.
        $file = 'download.pdf';

        return Yii::$app->response->sendFile($path . $file, $file, ['inline' => true]);
    }

Everything, you can open the file in a new tab, read and download.
You may need to tweak the urlManager rules.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question