PhantomJS - Rendering fails to show all images

I have a phantomjs script that is stepping through the pages of my site.

For each page, I use page = new WebPage() and then page.close() after finishing with the page. (This is a simplified description of the process, and I'm using PhantomJS version 1.9.7.)

While on each page, I use page.renderBase64('PNG') one or more times, and add the results to an array.

When I'm all done, I build a new page and cycle through the array of images, adding each to the page using <img src="data:image/png;base64,.......image.data.......">.

When done, I use page.render(...) to make a PDF file.

This is all working great... except that the images stop appearing in the PDF after about the 20th image - the rest just show as 4x4 pixel black dots

For troubleshooting this...

    <li>I've changed the render to output a PNG file, and have the same problem after the 19th or 20th image. </li> <li>I've outputted the raw HTML. I can open that in Chrome, and all the images are visible.</li> </ul>

    Any ideas why the rendering would be failing?


    Solved the issue. Turns out that PhantomJS was still preparing the images when the render was executed. Moving the render into the onLoadFinished handler, as illustrated below, solved the issue. Before, the page.render was being called immediately after the page.content = assignment.

    For those interested in doing something similar, here's the gist of the process we are doing:

    var htmlForAllPages = [];

    then, as we load each page in PhantomJS:

    var img = page.renderBase64('PNG'); ... htmlForAllPages.push('<img src="data:image/png;base64,' + img + '">'); ...

    When done, the final PDF is created... We have a template file ready, with all the required HTML and CSS etc. and simply insert our generated HTML into it:

    var fs = require('fs'); var template = fs.read('DocumentationTemplate.html'); var finalHtml = template.replace('INSERTBODYHERE', htmlForAllPages.join('\n')); var pdfPage = new WebPage(); pdfPage.onLoadFinished = function() { pdfPage.render('Final.pdf'); pdfPage.close(); }; pdfPage.content = finalHtml;


  • How to autoplay video in angularjs?
  • SOAP with Attachment / MIME content
  • Convert RSA pem key String to der byte[]
  • Serve file to user over http via php
  • Is it better to use the “hidden” CSS attribute or fetch each set of new images?
  • How to display the images in listview
  • SQL - Select lowest values with group by and order by?
  • Python PIL to extract number from image
  • Undefined navigator.push React-native 0.43.4
  • Cypher - matching two different possible paths and return both
  • Get the number 18437736874454810627
  • redirect_to root_url and return unless @user.activated
  • Is there a way to dynamically embed PDF Files in a JSP pulled from the file system?
  • Outputting SharePoint Hyperlink Column as URL
  • Creating PDF from TIFF image using iText
  • Disable Kendo Autocomplete
  • Django invalid literal for int() with base 10
  • How to view images from protected folder with php?
  • Display images in Django
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Resize panoramic image to fixed size
  • Incrementing object id automatically JS constructor (static method and variable)
  • Modifying destination and filename of gulp-svg-sprite
  • Importing jscolor library in angular 2
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Matrix multiplication with MKL
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • coudnt use logback because of log4j
  • File not found error Google Drive API
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal