kartik-v / yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
http://demos.krajee.com/mpdf
Other
161 stars 150 forks source link

file_put_contents(.../mpdf/ttfontdata/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: Permission denied #9

Closed jonua closed 9 years ago

jonua commented 9 years ago

I'm using mPDF inmy action like this:

$pdf = new Pdf([
                    'mode' => Pdf::MODE_UTF8,
                    'format' => Pdf::FORMAT_A4,
                    'orientation' => Pdf::ORIENT_PORTRAIT,
                    'destination' => Pdf::DEST_BROWSER,
                    'content' => $output,
                    'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
                    'cssInline' => '.kv-heading-1{font-size:18px}',
                    'options' => ['title' => 'My report ' . date("Y/m/d", time())],
                    'methods' => [
                        'SetHeader'=>['My report ' . date("Y/m/d", time())],
                        'SetFooter'=>['{PAGENO}'],
                    ]
                ]);

                return $pdf->render();

and I receive the exception:

file_put_contents(/home/iam/git/superproject/application/vendor/kartik-v/mpdf/ttfontdata/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: Permission denied

How can I solve this trouble?

gwelr commented 9 years ago

it probably means your web server does not have write access to ttfontdata/ folder or that dejavusanscondensed.GSUBGPOStables.dat already exists but could not be written by the web server. Did you manage to fix the issue on your side?

Sentoki commented 9 years ago

A have same problem in Symfony2. mpdf located in vendor, it's ok try write to vendor directory?

kartik-v commented 9 years ago

You may want to check permissions and also look out for help on mpdf forums.

For example see if this solution helps

Sentoki commented 9 years ago

Solve this problem by: define('_MPDF_TTFONTDATAPATH',$temp_dir); before creating instance of mPDF. $temp_dir is dir out of vendor. All work fine now.

kartik-v commented 9 years ago

Thanks for the feedback. I may provide a configuration option for this in the component as well.

kartik-v commented 9 years ago

Will be resolved via #12.

Closing this.

sheetal4123 commented 8 years ago

file_put_contents(/var/www/cluewiz/vendor/mpdf/mpdf/ttfontdata/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: No such file or directory

Getting this error

anton-github commented 8 years ago

I started getting the same error, and I think I finally figured out. After kartik-v changed $pdfLibraryPath property from '@vendor/kartik-v/mpdf' to '@vendor/mpdf/mpdf' (https://github.com/kartik-v/yii2-export/commit/8b60570fb3f541c2fac8ea4ea8e221d6a28e8750#diff-76ff5c7d38933d45f929b811c29f3b62R444) constant _MPDF_TTFONTDATAPATH now gets value from mpdf/mpdf again and tries to write to the vendor (before that commit _MPDF_TTFONTDATAPATH overrides to Yii::getAlias('@runtime/mpdf') during kartik-v/mpdf initialization)

asmythe commented 7 years ago

Ran into this same issue. Did the following before instancing mPDF and it worked.

        define('_MPDF_TTFONTDATAPATH',Yii::getAlias('@runtime/mpdf'));
kartik-v commented 7 years ago

@asmythe this is already taken care of in the Pdf component in this place ... not sure you would need to do that...

anton-github commented 7 years ago

Hi, kartik-v, check please my comment above. I could be wrong, but kartik-v/mpdf component did not initializing at all since your commit (https://github.com/kartik-v/yii2-export/commit/8b60570fb3f541c2fac8ea4ea8e221d6a28e8750#diff-76ff5c7d38933d45f929b811c29f3b62R444)

kartik-v commented 7 years ago

@anton-github the component does initialize fine as seen on the demos page and it should use the logic I mentioned above to create the mpdf directory in your app's runtime folder.

The commit you mentioned above has only one significant change in the repo change for mpdf source library, and you need to ensure that the new extension with its dependencies (including the mpdf repo) are installed fine... and you do not have two different mpdf libraries.

silkisethi commented 7 years ago

file_put_contents(E:/websites/test/vendor/mpdf/mpdf/ttfontdata/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: Permission denied

Added $temp_dir = DIR.'\mpdf\mpdf\ttfonts'; define('_MPDF_TTFONTDATAPATH',$temp_dir); before $pdf = new mPDF('utf-8', 'A4');

Can anyone help me?

gautam-patadiya commented 7 years ago

I faces same problem :( I resolved to create tamp folder with permission 777 and its working :)....

abdou-ghonim commented 7 years ago

This happens because mPDF trying to write a temporary file on TTFONTDATA folder

You can solve it by giving TTFONTDATA folder write permission 0777 or by Changing the _MPDF_TTFONTDATAPATH path to the Linux temp directory by adding the following line before creating the instance of mPDF

define('_MPDF_TTFONTDATAPATH', sys_get_temp_dir()."/");

kartik-v commented 7 years ago

If you wish to set your own temporary location set the Pdf::tempPath property to a valid temporary directory and the above should be automatically taken care of.