Skip to main content
Inspiring
August 20, 2024
Question

Coldfusion + Puppeteer (taking screenshot of website)

  • August 20, 2024
  • 2 replies
  • 577 views

I have project that takes an html file and using Chrome headless it converts that html into a PDF. That all works great, the problem is that I want to be able to save that html file as a jpg thumbnail. I know you can do it using Puppeteer but I'm not sure how to get Puppeteer to execute using CFEXECUTE as puppeteer is run from the command line like this:

 

node testcase1.js

 

testcase1.js holds all the puppeteer code. If I run it direct from the command line it works perfectly.

 

i've tried using a cfexecute in various ways:

 

<cfexecute name="node.exe" arguments="testcase1.js">

<cfexecute name="C:\Program Files\nodejs\node.exe" arguments="testcase1.js">

 

but nothing happens, the page doesnt even error. I've tried adding an output variable to see any errors and its just blank.

 

Can anyone offer any advice to get this working?

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    August 20, 2024
    quote

     

    node testcase1.js

     

    testcase1.js holds all the puppeteer code. If I run it direct from the command line it works perfectly.


    By @partTimeCrazy

     

    How/Where does the HTML file come in?

    Legend
    August 20, 2024

    What account is your ColdFusion service running under?  It might not have permissions to access the node directory?

     

    You could try putting your node commnd in a batch file and then use CFExecute to run that.

    <cfexecute name="C:\myNodeCommand.bat">

     

    I might also suggest a different app, altogether.  To my knowledge, it the same engine CF uses in its HTMLTOPDF engine:

    https://wkhtmltopdf.org/

     

    We use this all the time for site screenshots.  Running it from the command line gives us much more flexibility and control than Adobe's tag.  It can do PDFs or images.

     

    <cfexecute name="C:\Program Files\wkhtmltopdf\0.12.6\bin\wkhtmltopdf.exe" arguments="#yourOptions#">
    </cfexecute>

     

    <cfexecute name="C:\Program Files\wkhtmltopdf\0.12.6\bin\wkhtmltoimage.exe" arguments="#yourOptions#">
    </cfexecute>

     

    All the command-line options are here: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

    Community Expert
    August 21, 2024

    I like the batch file suggestion. I seem to recall that working consistently. But if you didn't want to put everything in a batch file for some reason, you could also try something like this:

     

    <cfexecute name="c:\windows\system32\cmd.exe" arguments="/c \path\to\node.exe testcase1.js">

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC