spiritix / php-chrome-html2pdf

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

can't open pdf file #32

Closed NandGoit closed 2 years ago

NandGoit commented 2 years ago

we have some problems opening the pdf file, we can't open it in chrome, edge, adobe, adobe acrobat reader, ... the only way we can open it is through firefox or if we send it to someone with a mac he than can open it.

I already tested the pdf in some pdf checker tools, which indicated that there were some underlying errors,

error: (the document contains content that is not labeled in the code that causes the reading software to not know how to read this document).

I'm testing this with the code in the readme file nothing else:

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', true);

$converter->setOptions([
    'printBackground' => true,
    'displayHeaderFooter' => true,
    'headerTemplate' => '<p>I am a header</p>',
]);

$output = $converter->convert();
$output->download('google.pdf');

Could it be that there are additional things that need to be configured, or do you have an idea why this is happening?

coxfrederic commented 2 years ago

I'm having the same issue on PC but not on Mac, any idea what can be causing this? Is this a Chromium issue, library issue or system issue? Library doesn't seem feasible since it works on my Mac but any pointers can be helpful. Thanks!

spiritix commented 2 years ago

Is there maybe a whitespace somewhere in one of the PHP files before the opening PHP tag? That could easily break a PDF file. Didn't experience such a behaviour before, usually the generated files can be opened in any viewer.

NandGoit commented 2 years ago

@spiritix, I have checked the pdf content in notepad++ and see that all the content of the page where I use the pdf converter is in the pdf code as in all the html/css and javascript and then at the end of the file the real pdf content starts, Do you know if this can cause problems and if we can prevent this?

spiritix commented 2 years ago

@NandGoit Yeah then it's no wonder that you can't open the file. I didn't experience this behaviour before. The converter itself seems working, since you wrote that the PDF file does contain some binary contents. Does the $outputvariable already contain the HTML/CSS?

NandGoit commented 2 years ago

@spiritix, it's weird i literally use the code i sent in my first post, i never set somthing else to the $output variable. maybe there's something wrong with how the company I work for generates the frontend, I'll let you know when I know more.