Skip to main content
Participant
December 7, 2020
Question

cfhtmltopdf with svg images

  • December 7, 2020
  • 1 reply
  • 2499 views

Has anyone gotten <cfhtmltopdf> to work with svg (or any other vector image formats). I have a require ment for very large vector pdfs that can be imported into CAD. I have tried using wkhtmltopdf but have had issues with it using local files on the server (on a stand alone work station it works great) and finding a way for it to push the completed pdf back to the user rather than doing a local save on the server. Thus if I could get <cfhtmltopdf> to work with the vector images it would be a godsend.

    This topic has been closed for replies.

    1 reply

    James Moberg
    Inspiring
    December 7, 2020

    I prefer using SVG files with WKHTMLTOPDF as it results in a smaller PDF with higher quality results. Using a webserver is critical so that WK can determine the correct MIME TYPE.  (I also use FontAwesome with WK... but web server-based mime types are important.)

    Generating a local PDF file on the server shouldn't be a real issue.  (I'm sure that CFHTMLTOPDF does the same thing since it supposedly also uses an older version of WKHTMLTOPDF behind the scenes.)  We prefer generating the file and saving it to the server for a number of reasons (troubleshooting, quality review, performance, etc).  We run a scheduled clean up job afterwards to remove any temporary files (BAT file, temporarily resized images, etc). After creating the PDF file, there should be anything prohibiting you from sending a download header and using CFContent with file/delete attributes.  This should provide the same user experience as CFHTMLTOPDF "pushing the completed PDF back to the user".

    <cfheader name="content-disposition" value="attachment; filename="c:\myPDF.pdf">
    <cfcontent type="application/unknown" file="c:\myPDF.pdf" deletefile="Yes">


    Here's another community post that shows comparisons between to two engines.
    https://community.adobe.com/t5/coldfusion/why-does-cfhtmltopdf-suck/m-p/11516137?page=1#M186760

    My personal advice since using WKHTMLTOPDF with ColdFusion 9 and reviewing CFHTMLTOPDF is to continue using WKHTMLTOPDF.

    Participant
    December 8, 2020

    Jamo, thx for the response.

       Please bear with me on this, it's a whole new ballgame for me. I have a rather complex cfm page that allows the user to build a custom assembly (a street light) from a variety of components rendered as html. Once the user has completed an assembly to their liking I need to be able to generate a vector pdf of that assembly from svg source files. I've got all the html/cfml working, now I have to find a way to output it. I've tried to incorporate WKHTMLTOPDF into the page but couldn't figure out a way to parse the assembly directly into WKHTMLTOPDF. I also tried to use an intermediate cfm page that incorporates WKHTMLTOPDF by calling out the actaul cfm assembly page as an argument, I had mixed luck with this. It worked right up to the point where I tried to call out a cfm (or html) page on the same server then failed to execute (as stated in my prior post it works fine on a workstation calling out local files with '--enable-local-file-access' enabled). I've been trying to run WKHTMLTOPDF with <cfexecute>.

       I get the gist from your response, but it's moot until I can render the PDF.

     

    thx

    Ry

    James Moberg
    Inspiring
    December 8, 2020

    Our approach has been to save the static html document to the web path using a temporary filename prior to PDF generation.  This was a better approach than having WKHTMLTOPDF access the content via our web application.  We didn't want it to be negatively impacted by any app security rules.  In some cases, we also generate a dedivated BAT file (with same temp filename) that we can call using CFExecute.  This enables us to manually run the BAT file ourselves on the server to troubleshoot and view any errors that may be reported only in the console.  (We've encountered some odd issues that caused PDF generation to abort, but nothing that we haven't been able to work around yet.)

     

    QUESTION:  Forget WK for the moment, are you able to render a standalone HTML page that is printable via Chrome?