spiritix / php-chrome-html2pdf Goto Github PK
View Code? Open in Web Editor NEWA PHP library for converting HTML to PDF using Google Chrome
License: MIT License
A PHP library for converting HTML to PDF using Google Chrome
License: MIT License
Hiya,
When setting a background color in the imported header and footer, it is not showing when generating a PDF. I tried using the printBackground: true
option, but to no luck.
What eventually worked was using the CSS rule -webkit-print-color-adjust: exact
.
Is this expected behavior? Does the rule only apply for the main content?
Parse error: syntax error, unexpected identifier "font", expecting ")" in C:\xampp\htdocs\topdf\index.php on line 12
<div style="font-family: arial; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;" align="center">
above is the input
`<?php
require 'vendor/autoload.php';
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Output\DownloadOutput;
use Spiritix\Html2Pdf\Input\StringInput;
$input = new StringInput();
$input->setHtml(" that sample input here");
$converter = new Converter($input, new DownloadOutput());
$converter->setOption('landscape', true);
$converter->setOptions([
'printBackground' => true,
'displayHeaderFooter' => true,
'headerTemplate' => '
I am a header
',$output = $converter->convert();
$output->download('google.pdf');
?>`
Ref issue #13
Hi, having issues with composer update after upgrade to 1.7.1
npm WARN Invalid version: "1.7"
npm WARN php-chrome-html2pdf No description
npm WARN php-chrome-html2pdf No repository field.
npm WARN php-chrome-html2pdf No README data
npm WARN php-chrome-html2pdf No license field.
Same as with 1.4, it resolved after updating package.json from 1.7 to 1.7.1
I'm using the code below and it's generating the pdf file with the margins. However it's not displaying any header or footer. Neither my custom or chrome's standard. I even tried removing the headerTemplate option and nothing. Is there a bug or am I doing something wrong? I'm using the latest version.
$input = new StringInput(); $input->setHtml($html); $converter = new Converter($input, new StringOutput()); $converter->setOptions([ 'landscape' => false, 'printBackground' => true, 'displayHeaderFooter' => true, 'headerTemplate' => '<p>I am a header</p>', 'margin' => ['top' => '5px', 'bottom' => '5px', 'left' => '5px', 'right' => '5px'] ]); $output = $converter->convert(); $binary = $output->get(); if ($binary) { $this->getLogger()->logUserActivity('result_download'); $filename = 'result.pdf'; return new Response($binary, 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="' . $filename . '"' ]); }
Hello
I have install but giving error 'No data returned'
laravel version 5.5, PHP 7.2 , Node v8
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', true);
$converter->setOptions([
'printBackground' => true,
'headerTemplate' => '<p>I am a header</p>',
]);
$output = $converter->convert();
$output->download();
I created a Laravel Wrapper
https://github.com/montyclt/laravel-chrome-html2pdf
Is not in composer now, but I will publish in the next days.
Hi,
since updating to version 1.4, I'm getting this error:
npm WARN Invalid version: "1.4"
npm WARN php-chrome-html2pdf No description
npm WARN php-chrome-html2pdf No repository field.
npm WARN php-chrome-html2pdf No README data
npm WARN php-chrome-html2pdf No license field.
If I change the version from "1.4" to "1.4.0" in package.json, it works.
Best,
Peter
Some JS tests are failing:
$ npm test
> [email protected] test /home/travis/build/spiritix/php-chrome-html2pdf
> ./node_modules/mocha/bin/mocha --timeout=10000 tests/js
Converter
getDefaultOptions
✓ returns an object
getOptions
✓ returns the merged options object
run
1) returns a buffer
2 passing (10s)
1 failing
1) Converter
run
returns a buffer:
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/travis/build/spiritix/php-chrome-html2pdf/tests/js/test.js)
npm ERR! Test failed. See above for more details.
The command "npm test" exited with 1.
See https://travis-ci.org/github/spiritix/php-chrome-html2pdf/jobs/695030310
The library works fine, must be something related to the tests.
Hello,
First I'd like to say this is an amazing library ! Well done.
I've used this in many scenario's and all is working fine, but now I find myself in a struggle with a PDF that uses a table.
When the table, which is built from thead, tbody and tfoot elements, spreads accross multiple pages due to the tbody contents being long then the header and footer are repeated. This is a pretty neat functionality I must say 👍.
Unfortunately (in my case) it doesn't work as it should.
When this happens, the footer of page 1 is shown on top of the body contents. The footer is then also shown on the top of the 2nd page where it interferes with the header on the 2nd page.
Any idea what I'm doing wrong here or how I can fix it?
I'm trying to add a header to a pdf with margins. These margins are calculated specifically for the content loaded in the pdf and should not be exceeded, as this cuts off part of the pdf content. However, to show the header inside the pdf, i followed the instructions on #9 which stated that the margins should be big enough to show the header content.
Is there a way to add header/footer to pdf without it using the margins set in the options? Or maybe overwriting the margins for the header?
It seems calling chrome directly from php code is possible. What is the pros and cons of using js as gateway?
The library works fine on local host however after pushing it to the production branch and running composer require spiritix/php-chrome-html2pdf
, I am now receiving shell error 127
$stringInput = new StringInput();
$stringInput->setHtml($html_of_page);
$converter = new Converter($stringInput, new StringOutput());
$converter->setOptions([
'printBackground' => true, //Print background is required to have background color styling take effect
'displayHeaderFooter' => true,
'format' => "A4",
'headerTemplate' => '<div></div>',
'footerTemplate' => '<div style="margin: 0px 40px; display:flex; align-items:flex-end; align-content:flex-end; justify-content:flex-end ; width:100vw!important; font-size:10px !important;"><p class="pageNumber"></p><p>/</p><p class="totalPages"></p></div>',
'margin' => ['top' => '40px', 'bottom' => '70px', 'left' => '40px', 'right' => '40px']
]);
$converter_output = $converter->convert();
Error message
production.ERROR: Shell error: 127 {"exception":"[object] (Spiritix\\Html2Pdf\\ConverterException(code: 0): Shell error: 127 at /var/www/html/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:$ [stacktrace]
Attempted solutions
I have tried changing permissions and ownership to the Converter.php file however the error remains
I have also tried to specify the filepath of node
$converter->setNodePath('/home/ec2user/.nvm/versions/node/v10.16.0/bin');
however this results in shell error 126 but upon inspecting the permission node it is already -rwxrwxr-x 1 ec2-user ec2-user 41115408 May 28 2019 node
Hi-
Our PDF generation is suddenly failing on our staging server after working great for the last several months. I suspect this happened after we upgraded from Ubuntu 18 to 20, but I may be mistaken.
We are running:
Here is the full error:
Spiritix \ Html2Pdf\ ConverterException
Binary error: /home/forge/[...]/vendor/spiritix/php-chrome-html2pdf/index.js:11 import getStdin from 'get-stdin'; ^^^^^^^^ SyntaxError: Unexpected identifier at Module._compile (internal/modules/cjs/loader.js:723:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
And the code we use:
public function displayPdf($type, $content, $id) {
$input = new StringInput();
$input->setHtml($content);
$converter = new Converter($input, new EmbedOutput());
$converter->setOption('landscape', false);
$converter->setOptions([
'printBackground' => true,
'displayHeaderFooter' => false,
'mediaType' => 'screen',
]);
$output = $converter->convert();
$output->embed($type.'-'.$id.'.pdf');
}
What I have tried:
Any help is appreciated. I can't seem to find anyone with this exact error here or on the web, so I'm at a loss. Thanks.
Hello,
when trying to create a Pdf from http://google.com there are no Images and Umlauts shown. Iam from Germany. This is how it looks.
test.pdf
Is there a way to fix this, and how?
Getting the following error when attempting to create a PDF:
Binary error: /var/www/pimcore/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230
error: new Errors_js_1.ProtocolError(),
^
ProtocolError: Protocol error (Page.printToPDF): Printing failed
at vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230:24
at new Promise (<anonymous>)
at CDPSession.send (vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:16)
at Page.createPDFStream (vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:2085:50)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Page.pdf (vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:2114:26)
at async Converter.run (vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:24)
at async vendor/spiritix/php-chrome-html2pdf/index.js:23:20 {
originalMessage: 'Printing failed'
}
Node.js v18.6.0
According to the SO question it should be possible to resolve:
$converter->setOptions([
'headless' => true,
]);
But that did not work, likely because it should probably be set in Converter.js. Maybe you can help resolve it?
I am trying to make PDF from page of my site.
All external css have full path (//domain/path.css).
Generated PDF has no styles from css.
Noticed some issues with table in htlm2pdf documents which I can't seem to fix. These are the issues I get:
borders seem to disappear at random locations. If i view the page as html i have a nicely formatted table without border breaks. If i then convert the html to pdf, i get strange line breaks:
as html:
as pdf:
note: in my pdf the user can set the amount of copies, which will duplicate the table x amount of times. In the duplicates i have no issue with border breaks so it seems to happen randomly
div below the table sometimes overflows into the table footer. This also seems to happen randomly, and when i view the document as html i see no issues.
Any ideas what the issue could be here? Are there known bugs in combining html2pdf with table html? I did notice that these bugs occur when the table spans over multiple pages
Thanks in advance for any help you can provide!
Since chromium was installed on node_modules
folder by npm install
, the problem occurred me is UnhandledPromiseRejectionWarning: Error: spawn EACCES
.
After investigation, I found that the chromium binary owned by someone who run composer install
/npm install
, with default mode 700
in my Ubuntu. but php scripts owned and run by others, www
usually. I must change the owner and mode of executable binary manually.
Maybe it is helpful to make executablePath
configurable.
Hi,
I have a situation where I need to create a pdf where the 2nd page is a google map covered in pins and routes. I already have the map setup and running as an iframe on the website but now I need to embed it into the pdf. I created the iframe in the html and used this tool on it but I just get a border around an empty box. I am assuming that's because chrome isn't waiting for the iframe to download and run before it "prints". Is there away around this or do I need to consider just setting a long wait time?
I am getting a binary error whenever I try to convert(). I installed using composer, running PHP 8.2.5, node 16.16.0 on macOS. I have installed chromium and can see the chromium process
Update: I noticed that the Chromium process is actually crashing immediately. It runs fine outside of the Apache environment on the machine, both headless and not. This is on macOS 13.3.1 (Intel), and I wonder if it may be caused by code-signing/sandbox issues. Has anyone gotten puppeteer to work in a similar environment?
Any help would be appreciated. Thanks!
The error:
PHP Fatal error: Uncaught Spiritix\\Html2Pdf\\ConverterException: Binary error: node:internal/process/promises:279\n triggerUncaughtException(err, true /* fromPromise */);\n ^\n\n[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<ErrorEvent>".] {\n code: 'ERR_UNHANDLED_REJECTION'\n}\n in /HTTPServer/htdocs/phppdf/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:188\nStack trace:\n#0 /HTTPServer/htdocs/phppdf/index.php(41): Spiritix\\Html2Pdf\\Converter->convert()\n#1 {main}\n thrown in /HTTPServer/htdocs/phppdf/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php on line 188
Here is a simple example that throws the error:
require __DIR__ . '/vendor/autoload.php';
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\EmbedOutput;
$input = new UrlInput();
$input->setUrl('https://www.google.com');
$converter = new Converter($input, new EmbedOutput() );
$converter->setNodePath('/usr/local/bin/node');
$converter->setOptions([
'displayHeaderFooter' => false,
'printBackground' => true,
'mediaType' => 'screen',
'lowquality' => true,
'dpi' => 75,
'pageWaitFor' => 1000,
'landscape' => false,
'scale' => 0.86,
'margin' => array( 'left' => '0.5in', 'top' => '0.5in', 'right' => '0.5in', 'bottom' => '0.5in' )
]);
$pdfData = $converter->convert();
ob_start();
$pdfData->embed('out.pdf', false);
Hello,
I'm trying to get this working within a Scotchbox VM, and for some reason it won't execute the ->convert()
command.
My Code:
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\StringInput;
use Spiritix\Html2Pdf\Output\FileOutput;
$input = new StringInput();
$input->setHtml(file_get_contents('./html/letter.html'));
$converter = new Converter($input, new FileOutput());
// $converter->setNodePath('/home/vagrant/.nvm/versions/node/v6.10.3/bin/node');
$converter->setOption('landscape', true);
$converter->setOptions([
'printBackground' => true,
'headerTemplate' => '<p>I am a header</p>',
]);
$output = $converter->convert();
$output->store(dirname(__FILE__) . '/out/' . date('h-m') . '.pdf');
As you can see, there's a comment to define the Node Path. If I un-comment that, I get this output:
Uncaught Spiritix\Html2Pdf\ConverterException:
Binary error: (node:2813) UnhandledPromiseRejectionWarning:
Unhandled promise rejection (rejection id: 1): Error: spawn EACCES in /var/www/public/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:188
Stack trace:
#0 /var/www/public/audit-letter/index.php(22): Spiritix\Html2Pdf\Converter->convert()
#1 {main} thrown in /var/www/public/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php on line 188
With the Node Path commented out, my output looks like this:
Fatal error:
Uncaught Spiritix\Html2Pdf\ConverterException:
Shell error: 127 in /var/www/public/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:192
Stack trace:
#0 /var/www/public/audit-letter/index.php(22): Spiritix\Html2Pdf\Converter->convert()
#1 {main} thrown in /var/www/public/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php on line 192
Within the Ubuntu VM, I ran sudo apt-get update && sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
in order to fulfill all the Debian Requirements, but that hasn't changed anything.
Is there something I am doing wrong?
Hi,
I agree ... this solution will sound weird but believe me ... I need it for a project I'm working on so please bear with me :-)
I have a HTML page that contains some specific HTML tags and CSS to create a label, multiple labels on the page also. Works fine and I can convert them to PDF perfectly using this wonderful library.
However, now my use case is to also include external labels (which are PDF) and need to visually be in the same layout (think about 4 A6 labels on one A4 page) as the "HTML" internal labels.
The solution I came up with first was to embed the external PDF urls in an object tag or iframe, but that didn't work. So then I included PDF.js to render the external PDF's, and when the entire page was rendered I want to convert it to PDF.
This works in "html" mode in my browser, but when I convert using this library the PDF.js does not load the PDF document.
Any idea why? I'm clueless.
I am able to access the pdfjsLib but the promise for loading the document does not work.
I also tried setting waitFor to 15000ms but even then it does not work.
Any pointers?
Thanks
Hello.
Debian. No images/css/assets on relative urls.
/css/style.css, /image.jpg - not working, I need to specify full site url https://site.com/css/style.css
Google from example is not working too.
Is here anyway to auto-detect current domain for relative urls? Or may be option {"site":"https://site.com"}?
Thank you!
I have successfully added the library in the PHP project but on the server, I'm unable to install this library.
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
I have this
HTTP/1.0 200 OK Cache-Control: no-cache, private Date: Tue, 06 Dec 2022 10:21:31 GMT
displayed at the top of my PDF and looking through issues/docs and pupeteer docs I don't how I can disable that, anyone have any insight ?
Hi.
When running the code, either via unit tests and actual usage, it fails if there is a space in the project directory.
Spiritix\Html2Pdf\ConverterException: Binary error: internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module '/Users/juliusijie/Projects/Open'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
/Users/juliusijie/Projects/Open Source/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:188
/Users/juliusijie/Projects/Open Source/php-chrome-html2pdf/tests/php/ConverterTest.php:61
In this case, it attempts to run the command: node /Users/juliusijie/Projects/Open Source/php-chrome-html2pdf/src/Spiritix/Html2Pdf/../../../index -o '{"printBackground":false}'
but the node executable throws an error because of the space within the base directory name.
I am able to run the library perfectly on my laptop (Windows 10)
When I upload the same code to my server, I first got this error
ErrorException: fwrite(): write of 8192 bytes failed with errno=32 Broken pipe in file /var/www/html/pdf/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/ProcessUtil.php on line 63
I made the pdf.html file very very simple, with the following code
But this is also giving me this error
Spiritix\Html2Pdf\ConverterException: Shell error: 127 in file /var/www/html/beta/api/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php on line 192
I am using a Laravel project
PHP version is 7.4.13
This is the code in my api.php
`<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\MasterController;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('/generatePdf', [MasterController::class,'generatePdf']);`
This is the code in my MasterController
`<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\StringInput;
use Spiritix\Html2Pdf\Output\FileOutput;
class MasterController extends Controller
{
public function generatePdf() {
// $input = new UrlInput();
// $input->setUrl('https://www.google.com');
$input = $this->getTemplate();
$stringInput = new StringInput();
$stringInput->setHtml($input);
// echo $input;
$converter = new Converter($stringInput, new FileOutput());
$converter->setOption('potrait', true);
$converter->setOptions([
'printBackground' => true,
'displayHeaderFooter' => true,
'headerTemplate' => '<p>I am a header</p>',
]);
$output = $converter->convert();
// $output->download('google.pdf');
$output->store(resource_path('views\pdf\store\google.pdf'));
}
public function getTemplate() {
return file_get_contents(resource_path('views/pdf/pdf.html'));
}
}`
This is the pdf.html file (given in txt format as HTML is not supported when posting in GitHub issues
pdf.txt
)
Hi , i used this demo code in our php after installation of vendor directory and i face some issue for generating pdf file of demo url
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\DownloadOutput;
require_once 'vendor/autoload.php';
$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' => '
I am a header
',$output = $converter->convert();
$output->download('google.pdf');
error :
Spiritix\Html2Pdf\ConverterException: Binary error: (node:8497) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! /opt/lampp/htdocs/php-puppeteer/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome: symbol lookup error: /usr/lib/x86_64-linux-gnu/libcairo.so.2: undefined symbol: FT_Get_Var_Design_Coordinates TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md at onClose (/opt/lampp/htdocs/php-puppeteer/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/launcher/BrowserRunner.js:159:20) at Interface. (/opt/lampp/htdocs/php-puppeteer/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/launcher/BrowserRunner.js:149:65) at Interface.emit (events.js:327:22) at Interface.close (readline.js:424:8) at Socket.onend (readline.js:202:10) at Socket.emit (events.js:327:22) at endReadableNT (internal/streams/readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21) (Use node --trace-warnings ...
to show where the warning was created) (node:8497) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:8497) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. in /opt/lampp/htdocs/php-puppeteer/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:188 Stack trace: #0 /opt/lampp/htdocs/php-puppeteer/app.php(23): Spiritix\Html2Pdf\Converter->convert() #1 {main}
Since eloquent/composer-npm-bridge is flagged as abandoned I did some digging around and found that php-forge/foxy could be a drop in replacement.
Am I missing something ? Any objections ?
Hi,
it would be nice to be able to define a "waitForFunction" as an option:
await page.waitForFunction(
'document.querySelector("body").innerText.includes("Hello Ajahne")'
);
I used the example and it produced a PDF file that didn't use the header template. I searched for an error, only to later find out that this is by design and that another option needs to be set:
'displayHeaderFooter' => true,
The README file should be changed to include this option.
Hi, as described here puppeteer/puppeteer#2410
I need to pass the arg --font-render-hinting=medium
. How can I do this using this package?
Update please puppeteer version in dependencies.
Curren version: 0.13.0
Actual: 1.10.0
0.13.0 not support headerTemplate and footerTemplate options!
I am trying to get this package up and running with a simple example but am unable to get past an error.
My development environment: Windows 11, Node v18.7.0, npm v8.15.0, Laravel 9.
The error is from $converter->convert():
Spiritix \ Html2Pdf \ ConverterException
Binary error: node:internal/fs/utils:348 throw err; ^ Error: EPERM: operation not permitted, lstat 'C:\Users\me' at Object.realpathSync (node:fs:2552:7) at toRealPath (node:internal/modules/cjs/loader:405:13) at tryFile (node:internal/modules/cjs/loader:401:10) at tryExtensions (node:internal/modules/cjs/loader:413:22) at Module._findPath (node:internal/modules/cjs/loader:569:20) at resolveMainPath (node:internal/modules/run_main:19:25) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:75:24) at node:internal/main/run_main_module:17:47 { errno: -4048, syscall: 'lstat', code: 'EPERM', path: 'C:\\Users\\me' } Node.js v18.7.0
This is the code I'm using in a Laravel controller, similar to the example provided in the readme:
<?php
namespace App\Http\Controllers;
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\DownloadOutput;
class DownloadController extends Controller
{
public function __invoke()
{
$input = new UrlInput();
$input->setUrl('http://www.example.com');
$converter = new Converter($input, new DownloadOutput());
$converter->setNodePath('C:\nodejs\node.exe');
$converter->setOption('landscape', true);
$converter->setOptions([
'printBackground' => true,
'displayHeaderFooter' => true,
'headerTemplate' => '<p>I am a header</p>',
]);
$output = $converter->convert();
return $output->download('example.pdf');
}
}
Hi,
I'm using this wonderful library to print out some labels that are being created in HTML.
We create the HTML and it contains just simple texts and a barcode SVG but nothing too fancy. Some icons are loaded through fontawesome.
// Need to include fontawesome for icons that are used
$labelsHtml .= '<script src="https://kit.fontawesome.com/5084f22b83.js" crossorigin="anonymous"></script>';
and when the HTML is populated we set it like this:
$input = new StringInput();
$input->setHtml($labelsHtml);
$converter = new Converter($input, new EmbedOutput()); $converter->setOptions([
'printBackground' => true,
'landscape' => true,
'width' => $height,
'height' => $width,
'margin' => ['top' => '5mm', 'right' => '5mm', 'bottom' => '5mm', 'left' => '5mm']
]);
$output = $converter->convert();
$output->embed('labels' . DateHelper::now(false, 'd-m-Y-H-i-s') . '.pdf');
We have been using this for quite some time but recently been noticing it takes a lot of time. On the same link we got a timeout earlier today, now it is working, but since fontawesome is loading very fast for me I'm wondering if that is the delay.
Since we set HTML, and there is nothing external except fontawesome, what could be triggering this timeout?
Also, is there something we need or can do to speed up the process? Like for example in PHP kill the process or something?
Trying to figure out what might be causing the delay.
Any help is appreciated, see the error below:
Spiritix\Html2Pdf\ConverterException /var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php in Spiritix\Html2Pdf\Converter::convert Binary error: node:internal/process/promises:246 triggerUncaughtException(err, true /* fromPromise */); ^ TimeoutError: Navigation timeout of 30000 ms exceeded at /var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/LifecycleWatcher.js:100:111 at async DOMWorld.setContent (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/DOMWorld.js:152:23) at async Page.setContent (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/Page.js:482:9) at async Converter._convert (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:76:9) at async Converter.run (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:24) at async /var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/index.js:23:20 -- ASYNC -- at Frame. (/var/OurPlatform/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/helper.js:94:19) at Page.setContent (/var/OurPlatform/vendor/spiritix/php-chrome-html2p...php
Hey, any idea why do i get this error:
Uncaught PHP Exception Spiritix\Html2Pdf\ConverterException: "Shell error: 133" at /var/www/vhosts/pimcorex/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php line 192 {"exception":"[object] (Spiritix\\Html2Pdf\\ConverterException(code: 0): Shell error: 133 at /var/www/vhosts/pimcorex/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:192)"} []
Hi, yesterday I updated Composer packages on server and got this error:
Node.js v18.12.0
{"exception":"[object] (Spiritix\\Html2Pdf\\ConverterException(code: 0): Binary error: file:///var/www/project/app/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:79
await page.waitFor(parseInt(options.pageWaitFor));
^
TypeError: page.waitFor is not a function
at Converter._convert (file:///var/www/project/app/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:79:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Converter.run (file:///var/www/project/app/vendor/spiritix/php-chrome-html2pdf/lib/Converter.js:37:24)
at async file:///var/www/project/app/vendor/spiritix/php-chrome-html2pdf/index.js:23:20
As I found, this error only appears when converter's option pageWaitFor
is set.
Node version: 18.12.0
Package version: 1.7.2
Any ideas?
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
',Would it be possible to update the eloquent/composer-npm-bridge
dependency to v5
, or perhaps (if possible) support both (v4|v5
)? That way it would be possible to use this package with composer@v2 as well 😀
Hi;
I used the following options to generate pdf
$html = "
<script>
document.write('screen.width = ' + screen.width);
document.write('screen.height = ' + screen.height);
</script>";
$input->setHtml($html);
$converter->setOptions([
'landscape' => false,
'printBackground' => true,
'format' => null,
'width' => '1440px',
'viewport' => [
'userAgent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36',
'width' => 1440,
'height' => 600,
'isMobile' => false,
'hasTouch' => false,
'isLandscape' => false,
],
'mediaType' => 'print',
]);
PDF output:
screen.width = 800screen.height = 600
Version:
"spiritix/php-chrome-html2pdf": "^1.4"
OS:
Centos 7
Based from #35 I'll add a feature request to be able to re-use the same instance of chromium.
For X amount of time? Or for X amount of page requests?
That might be options that we ca integrate into the library so the developer has the choice between reusing for 24 hours or 100 requests for example.
Other ideas are appreciated on how other developers see this idea.
If it's possible it would be really nice to have an option to specify cover page html template. Cover page unlike the rest of the pages shouldn't have any header/footer and margins. I would like to be able to use full page image on the cover page and have footers and headers on the rest of the pages.
Is it possible to change it from inline to attachment?
We encountered an issue when downloading and according to https://stackoverflow.com/questions/11432538/file-download-in-chrome-appears-incorrect-file-name-pagename-aspx-it-worked-b inline is not supported
I found some issues and want to check if there is any work around to fix them -
$pdfInputObj = new UrlInput();
$pdfHTMLURL = $this->getWebURLForPDFGeneration();
$pdfInputObj->setUrl($pdfHTMLURL);
$this->mPDFFileHandler = new FileOutput();
$this->mPDFBuilder = new Converter($pdfInputObj, $this->mPDFFileHandler);
$lang = ['name' => 'lang-key, 'value' => 'lang-value', 'domain' => '.app.localhost'];
$cookiesList = [];
$cookiesList[] = $lang;
$this->mPDFBuilder->setOption('cookies', $cookiesList);
$this->mPDFBuilder->convert();
LogFormat "%V:%p; %h; %{X-Forwarded-For}i; %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\""
The Apache2 log prints -
localhost:80; 127.0.0.1; -; [12/Jun/2023:23:25:23 +0530] "GET /some-url.html HTTP/1.1" 200 83778 "-" "-" "-"
Issue 1 - if User Agent is not set then our server deny the request but we can by-pass that check for localhost. However, User Agent was expected.
Issue 2 - Cookies are not sent. It is show stopper for us.
Please check and let me know if these are real issues or we are not using the lib as expected.
Upon installation we get the following error: npm WARN deprecated [email protected]: Version no longer supported. Upgrade to @latest
Are there any plans on offering a newer version?
Trying to get this running and having a devil of a time. My tech and I have been through the troubleshooting steps listed, but not finding anything. Help!
Here's the error I am getting when I try to convert an HTML file:
Binary error: file:///home/sites.local/cattle.local/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/esm/puppeteer/node/BrowserRunner.js:269
reject(new Error([
^
Error: Failed to launch the browser process!
../../base/allocator/partition_allocator/partition_address_space.cc(70) Check failed: false
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (file:///home/sites.local/cattle.local/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/esm/puppeteer/node/BrowserRunner.js:269:20)
at Interface.<anonymous> (file:///home/sites.local/cattle.local/vendor/spiritix/php-chrome-html2pdf/node_modules/puppeteer/lib/esm/puppeteer/node/BrowserRunner.js:257:24)
at Interface.emit (node:events:525:35)
at Interface.close (node:internal/readline/interface:533:10)
at Socket.onend (node:internal/readline/interface:259:10)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v18.14.2
Any ideas?
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?
Update de version of puppeter please
Fatal error: Uncaught Spiritix\Html2Pdf\ConverterException: Binary error: # # Fatal error in , line 0 # Check failed: reservation_.SetPermissions(protect_start, protect_size, permission). # # # #FailureMessage Object: 0x7fffb9146770 1: 0x7f78d67426c5 [/lib64/libnode.so.93] 2: 0x7f78d6b54d59 V8_Fatal(char const*, ...) [/lib64/libnode.so.93] 3: 0x7f78d7aed863 [/lib64/libnode.so.93] 4: 0x7f78d7afe6af v8::internal::PagedSpace::SetReadAndExecutable() [/lib64/libnode.so.93] 5: 0x7f78d7a1b097 v8::internal::Isolate::Init(v8::internal::SnapshotData*, v8::internal::SnapshotData*, bool) [/lib64/libnode.so.93] 6: 0x7f78d7e4c680 v8::internal::Snapshot::Initialize(v8::internal::Isolate*) [/lib64/libnode.so.93] 7: 0x7f78d78dacb4 v8::Isolate::Initialize(v8::Isolate*, v8::Isolate::CreateParams const&) [/lib64/libnode.so.93] 8: 0x7f78d6713c1d node::NodeMainInstance::NodeMainInstance(node::SnapshotData const*, uv_loop_s*, node::MultiIsolatePlatform*, std::vector<std::string, std::allocatorstd::string > const&, std::vector<std: in /var/www/html/t/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php on line 188
what would be the reason ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.