spiritix / php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome
MIT License
112 stars 29 forks source link

No data returned error in Core php #15

Closed techsamy closed 4 years ago

techsamy commented 4 years ago

Hello,

I am usng Php-chrome-html2pdf in core php but it displaying me the error

Fatal error: Uncaught Spiritix\Html2Pdf\ConverterException: No data returned in C:\Inetpub\vhosts\abc.com\xyz.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\Converter.php:196 Stack trace: #0 C:\Inetpub\vhosts\abc.com\xyz.co.in\convert.php(24): Spiritix\Html2Pdf\Converter->convert() #1 {main} thrown in C:\Inetpub\vhosts\abc.com\xyz.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\Converter.php on line 196

It working fine on xampp localhost but when i am trying to upload this on my web server it giving me the above error.

Here is my Code.

`<?php ini_set( 'display_errors', 1 ); error_reporting( E_ALL );

require_once DIR . '/vendor/autoload.php';

use Spiritix\Html2Pdf\Converter; use Spiritix\Html2Pdf\Input\UrlInput; use Spiritix\Html2Pdf\Output\DownloadOutput;

$input = new UrlInput();

$input->setUrl('https://www.google.com/');

$converter = new Converter($input, new DownloadOutput());

$converter->setOption('landscape', false);

$converter->setOptions([ 'printBackground' => true, 'headerTemplate' => '

I am a header

', ]); $output = $converter->convert(); $filename=date('YmdHis').".pdf"; $output->download($filename,'D'); ?>`

spiritix commented 4 years ago

This error means that the node executable didn't return any output. As a next step, I'd suggest debugging it by adding var_dump($command); to src/Spiritix/Html2Pdf/Converter.php on line 213. Then run the script, copy the command and run it manually on the webserver. Then report back here what output you've got or if there were any errors.

techsamy commented 4 years ago

After using var_dump($command) , it shows the below error.

I am a header<\\/p>""}"" Fatal error: Uncaught Spiritix\Html2Pdf\ConverterException: No data returned in C:\Inetpub\vhosts\arcclients.com\xyz.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\Converter.php:196 Stack trace: #0 C:\Inetpub\vhosts\arcclients.com\xyz.co.in\convert.php(25): Spiritix\Html2Pdf\Converter->convert() #1 {main} thrown in C:\Inetpub\vhosts\arcclients.com\xyz.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\Converter.php on line 196 string(225) "node C:\Inetpub\vhosts\arcclients.com\xyz.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\..\..\..\index -o "{""landscape"":false,""printBackground"":true,""headerTemplate"":""

spiritix commented 4 years ago

And what do you get if you execute the following command manually in your terminal?

node C:\Inetpub\vhosts\arcclients.com\xyz.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\..\..\..\index -o "{""landscape"":false,""printBackground"":true,""headerTemplate"":""I am a header<\\/p>""}"

techsamy commented 4 years ago

After Executing the following command in terminal we get the following Error : node C:\Inetpub\vhosts\arcclients.com\binaykumar.co.in\vendor\spiritix\php-chrome-html2pdf\src\Spiritix\Html2Pdf\..\..\..\index -o "{""landscape"":false,""printBackground"":true,""headerTemplate"":""I am a header<\\/p>""}"

Error

%PDF-1.4
%????
1 0 obj
<</Creator (Chromium)
/Producer (Skia/PDF m78)
/CreationDate (D:20191128064046+00'00')
/ModDate (D:20191128064046+00'00')>>
endobj
3 0 obj
<</ca 1
/BM /Normal>>
endobj
4 0 obj
<</Filter /FlateDecode
/Length 95>> stream
♀¶?R?µ¶???z?F?`▬P??♠?+@↑E?\???
L?@?q♣☻! ?*↓?
endstream
endobj
2 0 obj
<</Type /Page
/Resources <</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/ExtGState <</G3 3 0 R>>>>
/MediaBox [0 0 612 792]
/Contents 4 0 R
/StructParents 0
/Parent 5 0 R>>
endobj
5 0 obj
<</Type /Pages
/Count 1
/Kids [2 0 R]>>
endobj
6 0 obj
<</Type /Catalog
/Pages 5 0 R>>
endobj
xref
0 7
0000000000 65535 f
0000000015 00000 n
0000000355 00000 n
0000000154 00000 n
0000000191 00000 n
0000000543 00000 n
0000000598 00000 n
trailer
<</Size 7
/Root 6 0 R
/Info 1 0 R>>
startxref
645
%%EOF
spiritix commented 4 years ago

That looks like PDF data is being returned, so the actual converter works fine. Must be related to your web server settings then. You will need to debug the Converter.php class which is responsible for retrieving the output from Node, cannot provide assistance here, sorry.

dss1210 commented 1 year ago

I had the same problem. In my case 195 string - "if (mb_strlen($result['output']) === 0) {" equal true, but output was not empty. php8.1-mbstring extension was not installed. I ran "sudo apt install php8.1-mbstring" and problem solved!

BrianVB commented 9 months ago

Had the same issue and turns out same as @dss1210 the mbstring module wasn't installed. So odd that there'd be no error calling the function without the module installed.