Skip to content
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

Cannot Generate PDF with 149 pages or more #78

Closed
jwdepetro opened this issue Nov 26, 2014 · 16 comments
Closed

Cannot Generate PDF with 149 pages or more #78

jwdepetro opened this issue Nov 26, 2014 · 16 comments

Comments

@jwdepetro
Copy link

I am trying to generate a PDF with 150+ pages and cannot seem to get a PDF with 149 or more pages.

If I run this simple loop for 148 pages and will execute fine and return an inline PDF in a second or two.

for($i = 0; $i < 148; $i++){
$pdf->addPage('Single HTML test line');
}
if(!$pdf->send()){
logToFile('Error generating PDF', $pdf->getError());
}

Now if I increase the 148 to anything higher the browser window will keep spinning and no PDF will ever come back. I looked in my tmp directory where everything is generated and the file count is correct. Not sure what makes 149+ pages different than 148.

@mikehaertl
Copy link
Owner

Is there any error logged?

@jwdepetro
Copy link
Author

No, there is no error being logged.

@mikehaertl
Copy link
Owner

You could try to run the command manually on the command line and see if it works there. I'm not sure, if there's a limit to the command length that you can use with proc_open() in PHP. The relevant code is here:

https://github.com/mikehaertl/php-shellcommand/blob/master/src/Command.php#L266

Maybe you want to play around a little?

@pmxjason
Copy link

I have exactly the same problem. For a 149 page document code executes up to #292 and then hangs indefinitely.

https://github.com/mikehaertl/php-shellcommand/blob/master/src/Command.php#L292

We are running nginx on linux. Previously we was using 1.2.4 without issue.

As a work around I enabled useExec.

$this->_pdf = new \mikehaertl\wkhtmlto\Pdf(array(
    'encoding' => 'UTF-8',
    'commandOptions' => array(
        'useExec' => true
    )
));

This allows me to generate the 750 page documents like I was previously.

I am happy to provide more information. Do you have any instructions on running the command. If I print the command and exit none of the tmp files have been created. This is for both creating a 148 and 149 page document.

Note, we previously had a problem with huge documents hanging with 1.2.4 and came to the conclusion that the command length was too long. Now we limit document size to 750 though it could probably go a little higher. At first I thought this was the same issue but as exec works and 148 is fairly low number of pages compared to what is possible it is probably something else.

@mikehaertl
Copy link
Owner

@pmxjason Thanks for the info. The obvious difference from 1.2.4 to the current version is that we now also capture the stdout of the shell process (See proc_open()).

Can you maybe comment out lines 285, 292 and 294 in Command.php and see, if this really fixes the issue? If this is the case, we should find out what's the problem here and if there's a fix. I'd be happy for any suggestions as I don't have this problem.

Another question: Are you on windows?

@datOneperson
Copy link

I had the same problem. I'm using wkhtmltopdf version 0.12.2.1 on ubuntu/trusty64. I commented out those three lines and I was able to get 700 pages opposed to the 149 limit from before. The useExec workaround did not work for me.

@mikehaertl
Copy link
Owner

@datOneperson Are you sure about useExec? If that is on, the above lines are not executed at all. What happens if you enable useExec?

@mikehaertl
Copy link
Owner

@datOneperson @pmxjason @jwdepetro There are some interesting comments in the proc_open() manual:

http://php.net/manual/en/function.proc-open.php#97012
http://php.net/manual/en/function.proc-open.php#81317

Maybe you can give that a try? I think the second one sounds interesting. So you could try to insert this line after https://github.com/mikehaertl/php-shellcommand/blob/master/src/Command.php#L288:

stream_set_blocking($pipes[2], 0);

@datOneperson
Copy link

@mikehaertl I get "Command failed" when trying to do useExec.

I uncommented those three lines and added the line below after 288 and it didn't work.

stream_set_blocking($pipes[2], 0);

The first link actually worked for me. Replace the array in line 285. I was able to print 1800 pages.

0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'a') // stderr

@mikehaertl
Copy link
Owner

Ok, I've just released 2.0.3 version. The problems here are actually issues of https://github.com/mikehaertl/php-shellcommand. Thus I've removed the composer.lock file from this project so you can now update the dependencies independently.

@datOneperson @pmxjason @jwdepetro
So you could now try to update to the latest version. It should be 2.0.3 vor mikehaertl/phpwkhtmltopdf and 1.0.5 for mikehaertl/php-shellcommand.

@datOneperson Are you on windows? Because in the comment in the PHP manual he mentions that this problem only exists on windows. So I'm not sure if it also fixes the issue for the others.

@mikehaertl
Copy link
Owner

I had to undo this change in https://github.com/mikehaertl/php-shellcommand again, as it broke error reporting on linux.

To really solve the issue I'd need to know:

  • Did mikehaertl/php-shellcommand version 1.0.5 solve the issue for everyone?
  • Is this a Windows-only problem?

@datOneperson
Copy link

I got 1.0.5 working on Windows. And I'm guessing the problem is only on Windows.

@mikehaertl
Copy link
Owner

@datOneperson Thanks a lot. I'd be glad if you could help me testing. It's very easy: Simply replace the file in vendor/mikehaertl/php-shellcommand/src/Command.php with this file here:

https://raw.githubusercontent.com/mikehaertl/php-shellcommand/master/src/Command.php

This should fix both now, Windows and Linux.

As soon as you confirm this fix, I'll tag 1.0.7 release, so all these other issues should hopefully be gone then.

@mikehaertl
Copy link
Owner

Just released php-shellcommand 1.0.7 which should fix the issue for windows machines. Feel free to reopen, if the problem still exists.

@datOneperson
Copy link

Sorry, been away for two days. The fix, now on 1.0.7, works on Windows.

@mikehaertl
Copy link
Owner

Ok, great. So hopefully that's fixed now also for the OP. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants