• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Coldfusion + Puppeteer (taking screenshot of website)

Explorer ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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?

Views

211

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

we used to use wkhtml but it was too limiting with the CSS it supported. Going Chrome headless sorted that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2024 Aug 21, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation