[Solved] Troubleshooting rendering issues with HTML to PDF

April 10th, 2019 / by api2pdf /

In this article we will walk you through the best way to figure out why your HTML is not properly rendering as PDF using our API service.

Step 1

Open up your favorite text editor like notepad++ or VS Code and save your raw HTML that you’ve been sending to API2PDF and save it as a .html file. After you save this .html file, open up the file in Google Chrome.

Step 2

With Google Chrome and your .html file open, hit F12 key to bring up your Developer Console. Scan for any errors that might appear in this console. The most common mistake is that you are referencing assets using relative links instead of fully resolved links. For example, in your HTML you might have something like:

<img src=”/uploads/static/logo.png” />

This will not work because your logo is not hosted on the API2PDF servers and that is where the PDF is being generated. This problem applies to all assets, such as javascript, css, etc. With fully resolved urls, it would look something similar to:

<img src=”https://mysite.com/uploads/static/logo.png” />

Step 3

Resolve all of the errors that appear in the console and then try again. If you are still experiencing problems, then your issue may be a bit more complex. Verify that the issue you are facing still occurs when you test it against the API directly using our SwaggerHub Documentation here: outlined here: https://www.api2pdf.com/how-to-use-api2pdfs-swaggerhub-to-get-the-most-out-of-our-support-team/

**Note** – There is a limitation in SwaggerHub that will abort your request if generating the PDF takes longer than 10 seconds. So if your PDF takes longer than 10 seconds to generate, this step will not be helpful.

If it works fine on SwaggerHub, but not from within your own code, then you know there must be a bug in your code that you have to figure out.

Step 4

If you are out of ideas and need guidance from support, you can email support@api2pdf.com and please be sure to include the following information:

  • Endpoints you are using (GET or POST method, wkhtmltopdf/headless chrome, url/html, merge, delete, zxing, etc).
  • What language you are writing your code in. Are you using one of our client libraries or wrote your own code?
  • If using URL to PDF, provide a sample URL. If you are using HTML to PDF, provide a gist.github.com or attach a .html file sample of the HTML to you are using.
  • Are you using any of the advanced wkhtmltopdf or headless chrome options like header / footer, margins, page sizes, etc.?
Tags: , , , ,

Comments are closed.