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

IIS ACCESS_DENIED to c:\windows\temp when calling getOutputFromHtml() #123

Closed
HeavenCore opened this issue Nov 12, 2014 · 4 comments
Closed

Comments

@HeavenCore
Copy link

Hi there

When calling getOutputFromHtml() we're seeing the following errors on IIS8:

Fatal error:  Uncaught exception 'RuntimeException' with message 'The file 'C:\Windows\TEMP\knp_snappy54637e792dbd24.73938986.pdf' was not created (command: C:\wkhtmltopdf\bin\wkhtmltopdf.exe --lowquality "C:\Windows\TEMP\knp_snappy54637e792da033.68527031.html" "C:\Windows\TEMP\knp_snappy54637e792dbd24.73938986.pdf").' in C:\inetpub\wwwroot\www.XXXXXX.co.uk\classes\Knp\Snappy\AbstractGenerator.php:300
Stack trace:
#0 C:\inetpub\wwwroot\www.XXXXXX.co.uk\classes\Knp\Snappy\AbstractGenerator.php(135): Knp\Snappy\AbstractGenerator->checkOutput('C:\\Windows\\TEMP...', 'C:\\wkhtmltopdf\\...')
#1 C:\inetpub\wwwroot\www.XXXXXX.co.uk\classes\Knp\Snappy\Pdf.php(52): Knp\Snappy\AbstractGenerator->generate(Array, 'C:\\Windows\\TEMP...', Array, false)
#2 C:\inetpub\wwwroot\www.XXXXXX.co.uk\classes\Knp\Snappy\AbstractGenerator.php(166): Knp\Snappy\Pdf->generate(Array, 'C:\\Windows\\TEMP...', Array)
#3 C:\inetpub\wwwroot\www.XXXXXX.co.uk\classes\Knp\Snappy\AbstractGenerator.php(189): Knp\Snappy\AbstractGenerator->getO in C:\inetpub\wwwroot\www.XXXXXX.co.uk\classes\Knp\Snappy\AbstractGenerator.php on line 300

Usage:

require_once '/classes/autoload.php';

use Knp\Snappy\Pdf;

$snappy = new Pdf('C:\wkhtmltopdf\bin\wkhtmltopdf.exe');
//header('Content-Type: application/pdf');
//header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutputFromHtml($Document);

As you can see, the command being generated is fine:

C:\wkhtmltopdf\bin\wkhtmltopdf.exe --lowquality "C:\Windows\TEMP\knp_snappy54637e792da033.68527031.html" "C:\Windows\TEMP\knp_snappy54637e792dbd24.73938986.pdf"

If we run this command manually in CMD, the pdf is created perfectly.

When ran from PHP I can confirm that knp_snappy54637e792da033.68527031.html is being created on disk (C:\Windows\TEMP), the ACCESS_DENIED is then occuring immedietly after.

We ran sysinternals procmon to prove this:

image

How can we get round this without giving waaaay too much windows access to the Application Pool? Does Snappy support the changing of the temp folder? i.e. we'd much prefer to change the location where the temporary html & pdf files are being created to a specific folder to which the application pool can have controlled access rights?

Also, when the php script can create the html file in the first place, why is it getting access denied when trying to create the pdf? Has anyone managed to get this working on IIS?

@reafle
Copy link

reafle commented Jan 13, 2015

+1, we have the same problem. Runs perfectly in cmd, access denied for IIS.

@HeavenCore Have you solved this issue? Did the latest snappy update that allows to change temp folder help?

EDIT: Fixed this by changing php.ini values for sys_temp_dir and upload_tmp_dir to somewhere IIS can write without problems.

@jeremyb
Copy link
Contributor

jeremyb commented Jun 30, 2015

I got the same issue today. IMO it can be related to two things:

@naz19
Copy link

naz19 commented May 15, 2016

ACCESS_DENIED is occurring because IIS does not have permission to run C:\wkhtmltopdf\bin\wkhtmltopdf.exe. Give execute permissions to IUSR and IIS_IUSRS on wkhtmltopdf.exe and the Access Denied error should go away.

@akerouanton
Copy link
Contributor

I'll add a note today about this in the FAQ based on @naz19 and @jeremyb answers.

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

No branches or pull requests

6 participants