This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Video content on product page prevents PDF Generation

kmadler wrote on 2017-02-01:
Does anyone know why embedded YouTube videos are causing the following error in the PDF generation:

502 Bad Gateway

The server returned an invalid or incomplete response.

PDFs are generated just fine on pages without embedded YouTube videos.
support wrote on 2017-02-02:
Hello,

Could you please post here a sample link to a web page that demonstrates the problem?
kmadler wrote on 2017-02-02:
This is an example of a page that gives the error:

http://www.cmcrescue.com/equipment/mpd/

Yet this page also has a video and does not error right at the moment (it seems like sometimes I get the bad gateway errors on video pages and then other times it works fine):

http://www.cmcrescue.com/equipment/freetech-harness/
support wrote on 2017-02-06:
Hello,

We are unable to say what exactly causes the error. However, we noticed that the page does not validate with the W3C validator. There seems to be a problem with document encoding. Could you try to fix it and check to see if it helps?
kmadler wrote on 2017-02-08:
Here is the response from my web developer. Please continue to investigate this as the Print to PDF service is very spotty for us in terms of functionality on pages with embedded YouTube videos. Thanks.

"
That validator is really picky and doesn't come close to validating for any page on the site, yet obviously many of the pages can be printed to pdf. As a test, I've taken a single page that cannot be printed to pdf and I've manually corrected all 120 validation errors/warnings. This page http://staging.cmcrescue.com/test_w3c.php now validates using that tool, but I still get the bad gateway error response almost immediately. This officially disproves their theory the issue is related to encoding or the page not passing strict validation.

The issue definitely seems to be tied to embedded youtube videos. Since sometimes it works and other times it doesn't, this likely points to some sort of timing issue. Their documentation says there is a timeout after 30 seconds if the page hasn't finished loading, but the 502 error we're getting happens after only a couple seconds.
"
support wrote on 2017-02-12:
Hello,

Thank you for the information. We just wanted to rule out the possibility that the error is caused by non-validating HTML code. We investigated the issue further and it seems that it is a combination of several factors but we are unable to determine the primary cause. There is something in the HTML document layout which causes our converter to abort the conversion.

A simple document containing just the video converts without an error:
<html>
  <head>
  </head>
  <body>
    <h1>Video</h1>
    <p><iframe src="https://www.youtube.com/embed/5TJHjqAwEHc" width="560" height="315" allowfullscreen="allowfullscreen"></iframe>
  </body>
</html>


One thing you could try is the trial and error method - try to disable parts of the document or CSS and check to see if it helps. You can use the free conversion form on our web site for this.
kmadler wrote on 2017-02-14:
I've already tested removing just the video from the page and the PDF generates without issue in that case. We also know that sometimes the Freetech Harness PDF link works and sometimes it doesn't, which rules out there being something wrong with the HTML (the same page always has the same HTML).

What do you think? Could it be a time out issue in the render?
support wrote on 2017-02-16:
Hello,

Your HTML is definitely ok. However, there is something in it that triggers a bug in our implementation. One option that could resolve the issue is to disable JavaScript in the API:
$client->enableJavaScript(False)
kmadler wrote on 2017-02-16:
We don't use the API service. We use the "print to PDF". Any other ideas? Are there other users having the same issue?

Thanks!
support wrote on 2017-02-19:
Hello,

The "Save to PDF" link now supports the option to turn the JavaScript off. I tried to convert your page with the following and all seem to work
//pdfcrowd.com/url_to_pdf/?use_print_media=1
//pdfcrowd.com/url_to_pdf/?use_print_media=1&no_javascript=1
//pdfcrowd.com/url_to_pdf/?no_javascript=1

Please let us know if this fixes the issue for you.