# Frequently asked questions ###### *Q*: It does not work and everything is broken. *A*: Please, try to execute the command manually in your shell. Snappy is a thin PHP wrapper and most likely your issue is with wkhtmltopdf itself or is already described in this FAQ. If not, feel free to open the issue in Snappy issue tracker. Please, note that wkhtmltopdf takes only input URL(s) or file name(s) as source. ###### *Q*: How to get the command executed by Snappy? *A*: You need to install any PSR-3 compliant logging library and call `setLogger()` method on the generator. It will log every command executed, its env vars and timeout. It will also log stdout and stderr whenever a command finishes, even if it fails. ###### *Q*: My tables are broken when it is rendered on multiple pages with break. *A*: Add ```thead``` and ```tbody``` tags. Add the following css ```css table { page-break-inside:auto; } tr { page-break-inside:avoid; page-break-after:auto; } thead { display:table-header-group; } tfoot { display:table-footer-group; } ``` ###### *Q*: I have a PNG with a transparent background. When generating a PDF, the background turns black. *A*: It is wkhtmltopdf bug as described in https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2214. You should update wkhtmltopdf to at least 0.12.3-dev ###### *Q*: Is there a way to secure the pdf so it can't be edited? *A*: There is no way to add a password via wkhtmltopdf, but there is a way via other linux tools like pdftk ###### *Q*: We are using wkhtmltopdf to export html to pdf. It breaks the HTML in two pages of pdf. Can we add a break? *A*: It is known problem of `wkhtmltopdf`. You can use css `page-break-after`, like: ```html
Lorem ipsum
HTML; $footer = <<Lorem ipsum
HTML; // Without html extension you might face following error: // Exit with code 1, due to unknown error. $footerPath = tempnam('/tmp', 'footer') . '.html'; file_put_contents($footerPath, $footer); $pdf = new \Knp\Snappy\Pdf(__DIR__ . '/vendor/bin/wkhtmltopdf-amd64'); $pdf->generateFromHtml('', '/tmp/out/test.pdf', ['header-html' => $header, 'footer-html' => $footerPath], true); ``` ###### *Q*: Is it possible to include an header and/or footer only on some specific pages? *A*: No, wkhtmtopdf does not allow this. ###### *Q*: When running wkhtmltopdf through Snappy, I got an exit code 5 or 6 *A*: It's usually due to bad environment variables. For example, on MacOS, you need to check the value of `DYLD_LIBRARY_PATH` (see [#27](https://github.com/KnpLabs/snappy/issues/27#issuecomment-7199659)). On Linux, you should check the value of `LD_LIBRARY_PATH`. Also note that, depending on the way you execute PHP, your environment variables might be reset for security reasons (for instance, look at `clear_env` on php-fpm). ###### *Q*: On Windows, when I generate a PDF nothing happens (there's no PDF file written) *A*: You should check with sysinternals procmon if you experience `ACCESS_DENIED` error. If that's the case, you need to give execution permission to IIS users on wkhtmltopdf binary. Also, your user(s) should have write permissions on the temporary folder. For more details see [#123](https://github.com/KnpLabs/snappy/issues/123). ###### *Q*: Snappy takes an endless amount of time to generate a PDF and eventually fails due to timeout *A*: This is generally indicating some networking issues. It might be bad DNS record(s), some sporadic packet losses, unresponsive HTTP server ... Note that if you use the PHP embedded server, you can't generate a PDF from an HTML page accessible from the same embedded server. Indeed, the embedded server never forks and does not use threads. That means it's not able to process two requests at the same time: it processes the first one, send the first response and only then starts to process the second one. ###### *Q*: How to proceed when experiencing `ContentNotFound`, `ConnectionRefusedError` or timeouts? *A*: When you experience errors like `ContentNotFound`, `ConnectionRefusedError` or timeouts it is hard to know what is failing. The best you can do to narrow the scope of the bug is to slightly change your HTML code until you found the culprit. Start by removing whole parts, like document body. If that's now working, re-add it but now remove one half of its content. And repeat again and again until you find which URLs is buggy. There's one more (better) way though: fire up tcpdump or wireshark and listen for http requests. You should see which request(s) is failing, and you can even check the content of the request/response.