[Solved] ContentNotFoundError wkhtmltopdf exited with code 1

October 26th, 2018 / by api2pdf /

Intro

If you are using wkhtmltopdf, an open source HTML to PDF library, you might find that sometimes you receive a “ContentNotFound wkhtmltopdf exited with code 1” error. The error is common and can be easily solved. We see it happen frequently with Api2Pdf customers and so we wanted to write this article to assist. For our Api2Pdf customers, you may find the error in your request logs when you log into the portal.

The error is caused by having some content in your HTML that is referenced by a relative link that your application does not have access to, or some other static asset that results in a 404 Not Found.

For example, you might be including javascript or css files in your code like below:

<script type=”text/javascript” src=”../app/app.js”></script>

<link rel=”stylesheet” href=”../static/styles.css”>

Same idea for images and other content.

Solution

Api2Pdf does not store your assets on the servers here — so therefore all relative links would fail because the assets do not exist at those locations. To resolve this, Api2Pdf needs to see the fully resolved URLs to the assets like so:

<link rel=”stylesheet” href=”https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.css”>

Generally it is best practice to host your static assets on a CDN or static file server like Amazon S3, rather than to serve them from your application.

What is Api2Pdf?

Api2Pdf is a web service that allows you to generate PDFs at massive scale. Convert HTML to PDFs, Word to PDF, Web Pages to PDF, and merge PDFs together in minutes by using our extremely low cost API. It supports wkhtmltopdf, Headless Chrome, and LibreOffice under the hood. Avoid having to wrangle these libraries on your own servers and dealing with the headache. Api2Pdf runs on AWS Lambda so it can scale to millions of requests with no rate limits or file size limits.

Get started by checking out our documentation.

Tags: , ,

Comments are closed.