Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to run HTML2PDF on a generated page

Go to End

4 Posts   2348 Views


Community Member, 57 Posts

16 September 2013 at 10:42am

I'm a little confused as to where I should call HTML2PDF from.

I followed this advice and HTML2PDF is working but I'm having trouble getting my head around how I can link to this.

I have made myself a non-page class that pulls the contents of a particular page and formats it in the way I want it (it's a big boring table of the contents of that page). This is fine but I can't work out how to combine the two, ie create a PDF of this HTML file that is generated with a whole load of children and other controls.

It is like I need to generate the HTML first, and then pass all that to my getPDFTimeTable(args) function (that just runs HTML2PDF on the content passed to it in the (args)). I'm just not sure how to do that. What am I missing?


Forum Moderator, 1848 Posts

16 September 2013 at 2:57pm

Having tried many libraries for this I can fully recomend
Full set of examples
No external dependencies, no need for java and converts mostly all the html fine for me without having to fiddle with it


Community Member, 57 Posts

28 October 2013 at 5:29pm

Edited: 28/10/2013 5:41pm

Thanks for the reply, sorry for the delay.

I think my problem lies elsewhere - more to do with the basic problem of how to send my HTML to the function. ie how to put what is generated by my .ss file into a variable to pass to the function...

So I have my :

<table ID="TimeTable">
<% control TimeTable %>
<tr><th colspan='3' class='TimeTableDay'>Mondays</th></tr>
<% control AllChildren %>
<% if Day == Mondays %>
<tr><td>$MenuTitle</td><td>$Time</td><td>$contactName: $contactTelephone</td></tr>
<% end_if %>
<% end_control %>
<% end_control %>

I can't put getPDFTimeTable( ) around the code above but I don't know what to do so I get all the html into a variable that I can send to the function. Am I being totally stupid?!


Community Member, 290 Posts

2 November 2013 at 9:14am

how to put what is generated by my .ss file into a variable


// parse html
$html = $this->customise($myDataObj)->renderWith($myTmpl);

// create pdf
$pdf = new DOMPDF();
$pdf->set_base_path( BASE_PATH );
file_put_contents($folder.$filename, $pdf->output());