Skip to main content
Inspiring
January 17, 2012
Question

HTML to PDF converter

  • January 17, 2012
  • 4 replies
  • 4171 views

Hi All,

Is there any tool which we can use with Coldfusion to generate the PDF's from HTML/webpage?

I have seen many tool kit, when we want to convert a PDF from the webpage, we need to click "find" on the browser and select the tool , where the PDF will be created.

Instead can we use some API of that and implement the same functionality ?

All I need is a link or button in my webpage, when the user clicks on that, the PDF should be generated with the current page as the content.

I hope my question is understood.

Your help in highly appreciated.

Thanks in advance!

This topic has been closed for replies.

4 replies

Participant
February 2, 2012

I have tried a lot of converters for a recent project and I  would recommend the hiqpdf html to pdf tool. It could convert complex JQuery scritps and css3 syntax without problems.

meensiAuthor
Inspiring
February 3, 2012

Hi Seval2,

Thanks for your reply.

I will definitely try it out.

My requirements do not want the pdf text to go via net to the pdf server.

Participating Frequently
January 18, 2012

In your current pages (assuming they are cfm).

<form action="makepdf.cfm">

<input type="hidden" name="makeapdf" value="yes">

<input type="hidden" name="desiredpage" value="#listgetat(script_name,listlen(script_name,"/"),"/")#">

<cfset FormVariables = "">

<cfif IsDefined("Fieldnames")>

    <cfloop index="variable" list="#Fieldnames#">

                  <cfif ListFind(FormVariables, variable) is 0>

                                          <cfoutput>

                                                                            <input type="hidden" name="#variable#"

                                                                                                     value="#evaluate('Form.#variable#')#">

                                                             </cfoutput>

             <cfset FormVariables = ListAppend(FormVariables, variable)>

 

           </cfif>

</cfloop>

</cfif>

<input type="submit" value="Create as PDF">

</form>

<!--- and on makepdf.cfm --->

<cfif isdefined("makeapdf")>

  <cfdocument  format="pdf"  pagetype="letter" pagewidth="8.5" pageheight="11">

<cfinclude template="#desiredPage#">

    </cfdocument>

</cfif>

 

</body>

</html>

meensiAuthor
Inspiring
January 19, 2012

Hi Fyreman,

Will try this code and see;

Thanks for your detailed code.:)

Participant
January 17, 2012

I'd recommend DocRaptor. Its API is easy to integrate with your own web applications, and as long as you can make an HTTP POST request against its server, you can generate PDFs from HTML code.

BKBK
Community Expert
Community Expert
January 18, 2012

illbzo1 wrote:

I'd recommend DocRaptor. Its API is easy to integrate with your own web applications, and as long as you can make an HTTP POST request against its server, you can generate PDFs from HTML code.

True, DocRaptor is one of the better HTML-to-PDF converters out there. Remember, however, that it costs money and is a web service. If Meensi's client is very particular about perfection, then he will likely be very particular about Meensi posting his documents to the web.

Still, DocRaptor remains a good suggestion. What Meensi could do is install DocRaptor's engine, Prince. He could then run Prince from ColdFusion by means of cfexecute. 

Owainnorth
Inspiring
January 17, 2012

CFDocument?

meensiAuthor
Inspiring
January 17, 2012

Hi Owain,

I was expecting your reply.:)

With the CFDOCUMENT I need to write a code to generate a PDF.

I have nearly 60 different reports, all are different with the fonts, images etc. So If I use CFDOCUMENT, I need to write 60 different files.Am I right ??

Instead I thought I can purchase some kit with the help of that, I can generate the PDF with the current page(HTML).

Owainnorth
Inspiring
January 17, 2012

CFDocument just takes HTML input, so however you get that is up to you. If you already have a method for creating the report in HTML just do so, use CFSaveContent to grab the HTML you were about to output to the screen and wrap it in a CFDocument. It won't be perfect, but it should do.