-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed with Error "Loading pages (1/6) [> ] 0% [======> ] 10%" #125
Comments
Hmm, not really. I've never seen this behavior myself, but there are other issues that reported the same problem. I've never found out what is causing this, though. So any further debugging information is very welcome. |
You could also try if the https://github.com/mikehaertl/phpwkhtmltopdf#wrapper-options |
@mikehaertl i'm having this issue. With a html table of small data, renders fine, but with html table of 1000 rows, it fails with this error message. code is as follows: private function toPdf($html,$name)
{
$pdf = new \mikehaertl\wkhtmlto\Pdf($html);
$pdf->binary = '/usr/local/bin/wkhtmltopdf';
if($pdf->saveAs('/tmp/'.$name.'.pdf')){
return file_get_contents('/tmp/'.$name.'.pdf');
}
throw new \exception('Failed To write PDF with message: '.$pdf->getError());
} |
What about |
updated code still same result: private function toPdf($html)
{
$pdf = new \mikehaertl\wkhtmlto\Pdf($html);
$pdf->binary = '/usr/local/bin/wkhtmltopdf';
$pdf->setOptions(['ignoreWarnings'=>true]);
if($html = $pdf->toString()){
return $html;
}
throw new \exception('Failed To write PDF with message: '.$pdf->getError());
} |
Oh dude. i figured it out. the twig template i'm rendering is not a valid html file. its just a html snippet. enclosing in valid document markup solved problem. here's the deal though, it only renders the table head now. no tbody. http://puu.sh/lbgdN/44ef308606.jpg |
my particular issue was the usage of data-uri's in image tags. letting |
I'm having the same issue as @tilman but that's only when I load it via php-fpm. If I run from command line
Any environment variable that have to be set? |
I wonder if it has to do with the mikehaertl/php-shellcommand#9 (comment) It's in |
I did make the suggestion, using stream_set_blocking() And Now I have this result: Fatal error: Uncaught exception 'Exception' with message ' Every refresh the name of the file temp change, but never create my pdf file. Any suggest? Thanks! |
I really suspect the issue here is that the environment is not set correctly. In order to fix my issue I installed the dev version(0.12.3-dev-79ff51e) - which has no dependencies to other libraries and it works just fine. I suspect some env variables were not being set in the php context. See if this resolves your issue as well. |
I tried to get tmpdir with your function
That can you help ? |
@babeuloula On CentOS there seem to be some security restrictions in effect. You could check this comment here: #99 (comment) |
No works!!!.. diable or enabled SELinux is the same. |
Same for me |
It would help, if I had a code example, where the issue always happens. So that I can reproduce and investigate the problem. |
My code is confidential, can you send me an email (see my profile) and I will send you a zip file. |
@babeuloula Sorry, but I'd prefer something simple. |
Ok there is the code :
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'vendor/autoload.php';
$pdf = new \mikehaertl\wkhtmlto\Pdf(array(
'no-outline',
'binary' => '/usr/local/bin/wkhtmltopdf',
'commandOptions' => array(
'procEnv' => array(
'LANG' => 'fr_FR.UTF-8',
),
),
'margin-top' => 25,
'margin-right' => 25,
'margin-bottom' => 25,
'margin-left' => 25,
'page-size' => 'A4',
'header-left' => "Titre",
'header-right' => "Utilisateur",
'header-spacing' => 10,
'footer-left' => 'Site Internet',
'footer-center' => '',
'footer-right' => '[page]',
'footer-spacing' => 10,
'javascript-delay' => 1000,
));
$pdf->addPage('test.html');
setlocale(LC_CTYPE, "fr_FR.UTF-8");
if (!$pdf->send()) {
throw new Exception('Could not create PDF: '.$pdf->getError());
}
<!DOCTYPE html>
<html lang="fr">
<head>
<title>PDF Test</title>
<meta charset="UTF-8">
<script src="javascript.js"></script>
<style>
* {
-webkit-box-shadow : none !important;
-moz-box-shadow : none !important;
-ms-box-shadow : none !important;
-o-box-shadow : none !important;
box-shadow : none !important;
-webkit-text-shadow : none !important;
-moz-text-shadow : none !important;
-ms-text-shadow : none !important;
-o-text-shadow : none !important;
text-shadow : none !important;
color : #000;
}
body {
background-color: #FFF;
overflow: visible;
}
</style>
</head>
<body>
<div id="chart_1"></div>
<div id="chart_2" style="margin-top: 50mm"></div>
<div id="chart_3"></div>
<div id="chart_4" style="margin-top: 25mm"></div>
<div id="chart_5"></div>
<div id="chart_6" style="margin-top: 25mm"></div>
<div id="chart_7"></div>
<div id="chart_8" style="margin-top: 25mm"></div>
<script type="text/javascript">
jQuery(function($){
$("#chart_1").highcharts({
colors: ["#FFAAAA", "#D46A6A"],
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "pie"
},
title: {
text: "chart_1"
},
plotOptions: {
series: {
animation: false,
dataLabels: {
enabled: true,
format: "<b>{point.name}</b> ({point.y:,.0f})"
}
}
},
series: [{
name: "chart_1",
data: [
["value 1", 0],
["value 2", 1],
]
}]
});
$("#chart_2").highcharts({
colors: ["#C38552", "#C35252"],
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "bar",
height: "250"
},
title: {
text: "chart_1"
},
xAxis: {
categories: [
"value 1",
"value 2",
"value 3",
],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: null,
align: "high"
},
labels: {
overflow: "justify"
},
allowDecimals: false
},
plotOptions: {
bar: {
animation: false,
dataLabels: {
enabled: false
}
}
},
series: [{
name: "name 1",
data: [
1,
1,
0,
]
}, {
name: "name 2",
data: [
0,
0,
1,
]
}]
});
$("#chart_3").highcharts({
colors: [
"#54afec",
"#60c2c3",
"#6dd894",
"#7aed67",
],
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "pyramid",
marginRight: 150
},
title: {
text: "chart_3"
},
plotOptions: {
series: {
animation: false,
dataLabels: {
enabled: true,
}
}
},
series: [{
name: "name",
data: [
[
"value 1", 5
],
[
"value 2", 1
],
[
"value 3", 1
],
[
"value 4", 2
],
]
}]
});
$("#chart_4").highcharts({
colors: ["#FE353C", "#65C869"],
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "pie"
},
title: {
text: "chart_4"
},
plotOptions: {
series: {
animation: false,
dataLabels: {
enabled: true
}
}
},
series: [{
name: "name",
data: [
{
name: "value 1",
y: 12
},
{
name: "value 2",
y: 1
}
]
}]
});
$("#chart_5").highcharts({
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "bar",
height: "250"
},
title: {
text: "chart_5"
},
xAxis: {
categories: [
"value 1",
"value 2",
"value 3",
"value 4",
],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: null,
align: "high"
},
labels: {
overflow: "justify"
},
allowDecimals: false
},
plotOptions: {
bar: {
animation: false,
dataLabels: {
enabled: false
}
}
},
series: [{
name: "name 1",
data: [
6,
1,
1,
1,
]
}, {
name: "name 2",
data: [
0,
0,
0,
0,
]
}]
});
$("#chart_6").highcharts({
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "bar",
height: "250"
},
title: {
text: "chart_1"
},
xAxis: {
categories: [
"value 1",
"value 2",
"value 3",
"value 4",
"value 5",
],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: null,
align: "high"
},
labels: {
overflow: "justify"
},
allowDecimals: false
},
plotOptions: {
bar: {
animation: false,
dataLabels: {
enabled: false
}
}
},
series: [{
name: "name 1",
data: [
1,
1,
2,
2,
2,
]
}, {
name: "name 2",
data: [
0,
0,
0,
0,
0,
]
}]
});
$("#chart_7").highcharts({
colors: ["#8085e9", "#f15c80", "#e4d354", "#2b908f", "#f45b5b"],
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "pie"
},
title: {
text: "chart_7"
},
legend: {
enabled: true
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: "pointer",
depth: 35,
dataLabels: {
enabled: true,
format: "{point.name}"
}
},
series: {
animation: false,
dataLabels: {
enabled: true,
format: "<b>{point.name}</b> ({point.y:,.0f})"
}
}
},
series: [{
type: "pie",
name: "name 1",
data: [
[
"value 1", 1
],
[
"value 2", 2
],
[
"value 3", 3
],
[
"value 4", 5
],
[
"value 6", 6
],
]
}]
});
$("#chart_8").highcharts({
colors: ["#8085e9", "#f15c80", "#e4d354", "#2b908f", "#f45b5b"],
style: {
fontFamily: "sans-serif",
fontSize: "12px"
},
credits: {
href: "http://www.exemple.com/",
text: "Site Internet"
},
chart: {
type: "column"
},
title: {
text: null
},
plotOptions: {
column: {
stacking: "normal",
animation: false,
depth: 25
}
},
yAxis: {
title: {
text: "chart_8"
},
allowDecimals: false
},
xAxis: {
categories: [
"value 1", "value 2", "value 3", "value 4", "value 5", "value 6", "value 7"
]
},
series: [
{
name: "value 1",
data: [
1,
2,
3,
4,
5,
6,
7,
]
},
{
name: "value 2",
data: [
1,
2,
3,
4,
5,
6,
7,
]
},
{
name: "value 3",
data: [
1,
2,
3,
4,
5,
6,
7,
]
},
{
name: "value 4",
data: [
1,
2,
3,
4,
5,
6,
7,
]
},
]
});
});
</script>
</body>
</html>
http://code.jquery.com/jquery-2.1.4.min.js
https://code.highcharts.com/highcharts.js
https://code.highcharts.com/modules/funnel.js |
Fatal error: Uncaught exception 'Exception' with message 'Could not create PDF: Failed without error message: ../usr/local/bin/wkhtmltopdf --no-outline --margin-top '25' --margin-right '25' --margin-bottom '25' --margin-left '25' --page-size 'A4' --header-left 'Titre' --header-right 'Utilisateur' --header-spacing '10' --footer-left 'Site Internet' --footer-center '' --footer-right '[page]' --footer-spacing '10' --javascript-delay '1000' 'test.html' '/tmp/tmp_wkhtmlto_pdf_5n1dkJ.pdf'' in /home/nitico5/public_html/php-pdf/test2.php:41 Stack trace: #0 {main} thrown in /home/nitico5/public_html/php-pdf/test2.php on line 41 |
I have the same error |
|
Work around
|
No works for me... remember that the, I'm using vps centos in imotion hosting. |
I am also getting this problem. On CentOS 6.7 - none of the above suggestions helped. Weird thing is it works fine from command line. Also works fine when using Google as the page, but once trying my own page, it hangs on 10%. Spent hours debugging and trying different things but nothing is working. |
@JayAdra Can you try to set the |
@mikehaertl I have tried this in the past, but also tried it again now and getting the same result. Strangely, sometimes when I change some settings and run it, it generates the image, but it's a white image strip instead of the page. But then running it subsequent times causes it to hang. |
@mikehaertl If it helps, here the PHP I'm using: $img = new Image([
'type' => 'jpg',
'format' => 'jpg',
'crop-h' => 2000,
'quality' => 50,
'width' => 1600,
'user-style-sheet' => '/home/*******/public_html/assets/global/admin/css/print-module-editor.css',
'cookie' => [
'cl_session' => session_id()
],
'commandOptions' => [
'useExec' => true
]
]);
$img->binary = '/usr/local/bin/wkhtmltoimage';
//$img->setPage('http://www.google.com');
$img->setPage(site_url('/******'));
$img->saveAs('/home/*******/public_html/page1.jpg');
echo "<pre>";
print_r($img); The command produced when printing |
No idea. Keep in mind, that the library is just a simple frontend for wkhtmltopdf. So I don't know what happens inside. Maybe it has to do with the progress bar output. Have you tried to add the
So at least it's not really my library here but a more general problem with executing wkhtmltopdf from PHP. |
@mikehaertl Okay, I swore I tried it the same way before, but trying exec() again in PHP manually with the same command is now working. But using the library results in it hanging. This is the command which works in exec(): exec("/usr/local/bin/wkhtmltoimage --format 'jpg' --crop-h '2000' --quality '50' --width '1600' --user-style-sheet '/home/*****/public_html/assets/global/admin/css/print-module-editor.css' --cookie 'cl_session' 'abd5d3831b2a99b7d9f5a3130edf25a68fe6f285' 'http://jay.*****.com/users' '/home/*****/public_html/test.jpg'"); So there must be something different when executing from the library? |
If use |
@mikehaertl I actually copied this code out of the execute() function and ran it manually: $execCommand = $this->captureStdErr ? "$command 2>&1" : $command;
exec($execCommand, $output, $this->_exitCode);
$this->_stdOut = implode("\n", $output);
if ($this->_exitCode!==0) {
$this->_stdErr = $this->_stdOut;
$this->_error = empty($this->_stdErr) ? 'Command failed' : $this->_stdErr;
return false;
} And I set $command to the command I was using when running exec() and it worked. So weirdly it looks like it's the same code, but when run through the library it fails? There must be other steps in the processing before or after the execute() is called which is causing the issue. I'm going to start stepping through some of it now and see if I can find anything. Hope this extra info gives you an idea though? |
@JayAdra The only idea I had was about the extra arguments to Did you copy this into a class? Because there's |
@mikehaertl Thanks for the help so far. I did change the class references to normal variables when testing it and I also tried -q but didn't help. I think I found the issue is coming from my sessions somehow. When I use I know this isn't really in the scope of your library, but if you have any ideas on why this could be, I'd appreciate the input. |
@JayAdra There are some pitfalls in PHP with locking of the session file. Maybe related? http://stackoverflow.com/questions/252907/why-does-session-start-cause-a-timeout-when-one-script-calls-another-script-usin |
@mikehaertl That's done it! You are a lifesaver Mike! Thanks for the assist with this, I really appreciate it. It's always so simple... I hope this helps anyone else with this problem. Thanks again! |
@JayAdra Cool. Maybe you can give a quick summary of what happened and how you fixed it? |
@mikehaertl Sure. I was trying to generate an image of a protected page (it requires authentication), so was using the user's current browser session (retrieved by using This would always hang (at 10%) and I now know it's because the session was locked and couldn't be used by two scripts at the same time (first by the PHP script and the second by the wkhtmltoimage process). So the simple fix was to add TL;DR Add |
Just wanted to comment to add a datapoint to this. Noticed a previously working setup was suddenly failing on a shared hosting provider. Manually running the command from a shell worked fine, but from the webserver with PHP 5.4 and 5.6 it always failed. Calling it directly through exec and adding an strace shows I've tried increasing my php memory limit, but I'm assuming the shared hosting provider has some aggressive limit enforcing in there. Update: Hate using the sledgehammer approach to fixing an issue, but upgrading the version of wkhtmltopdf I was using from 0.12.2.1 to 0.12.4 appears to have resolved the issue for me. |
I have the same issue. The class stopped working fine a few days ago. |
@playinteractive Did you change anything? Usually things don't just break - something must have changed. |
Hi @mikehaertl, I made some changes in the html code adding time information at the end of the images:
|
Hmm. Not sure then. Must have to do with |
The thing with that class is that only works with chrome. This thread is talking about this issue: Is there some way to disable errors like warnings?
|
@playinteractive Interesting, but I don't think, that we can do much about it here. And If you find something to improve on that code, let me know. |
I tried this:
And the result: Failed loading page https://www.google.com/ But after remove "https" works fine so the problem comes from the https/ssl |
@mikehaertl not sure if i should open a new issue. The library worked for me in windows subsytem for linux with ubuntu 16 but once I went to a live environment with ubuntu 14 it wasn't working. I switched to simply run wkhtmltopdf and wkhtmltoimage with system() and all is working fine. Here is the way I installed wkhtmlpdf wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz Maybe you should put some kind of note in the readme, It took me a few days until I realized my issue was the library...but thank you very much in any case! |
@yehudahkay So you still have a problem? The note about different wkhtmltopdf versions is already in the README. Adding detailled install instructions for wkthmtltopdf is really out of the scope of this library, though. There are too many OS and versions out there. https://github.com/mikehaertl/phpwkhtmltopdf#installation-of-wkhtmltopdf |
@mikehaertl i'm sorry if i didn't explain, i cannot use the library as it was failing for me on ubuntu 14, instead I am using system(). it took me several days to realize the problem with my code was the library and not wkhtmltopdf. |
Hmm, I'm sorry to hear that. I guess you now already found a solution that works for you. But just in case you find out what caused your problem I'm happy to add any fixes. The problem is probably rather caused by https://github.com/mikehaertl/php-shellcommand that we use to execute the command. There's also some discussion there already. So feel free to add any findings there. |
@mikehaertl thank you, i assume you are right. if i get any time i will see if i can figure anything out |
getting same error for python Any solution for this? |
When i use render url is same or assets url same domain its locking request. I think its php limitation, its waiting for end of request. |
For anyone still interested: I've meanwhile completely refactored the way we work with the I/O streams with You'd have to replace your copy of Any feedback welcome - but please comment on the related issue of php-shellcommand. |
I've released 2.4.1 which will use the latest version of php-shellcommand which should fix many issues with commands that generate a lot of output (which is probably the main reason for many issues). So I'm closing this for now. If there are still issues, feel free to leave a comment. |
I tested with following code:
The Page only displays: "Loading pages (1/6) [> ] 0% [======> ] 10%"
My Testserver:
/var/www/cgi-bin/pdf/ has this linux rights drwxr-xr-x and user apache
Any Tips to get it working?
The text was updated successfully, but these errors were encountered: