1

I have two files located in localhost/invoice named x.php and template.php, and then I have a URL like this:

localhost/invoice/template.php?name=wawan

How can I convert the output page into a PDF? What I want is to access x.php and then get the converted template.php. I tried using mpdf, but it doesn't work.

Here's x.php:

<?php
include("MPDF54/mpdf.php");

$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list

$mpdf->WriteHTML(file_get_contents('template.php?name=wawan'));

$mpdf->Output();
?>

And this is template.php:

<div> The name is :
<?php


echo $_GET[name];

?>
Charles
  • 50,943
  • 13
  • 104
  • 142
Wawan Brutalx
  • 603
  • 6
  • 15
  • 27
  • What does "doesn't work" mean? How doesn't it work? Is the output incorrect? What's wrong with it? Do you get an error message? If so, what does the error message say? – Andy Lester Dec 12 '12 at 03:46
  • You may want to check this post: http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php – Andy Lester Dec 12 '12 at 03:47

1 Answers1

1

You can use output buffering:

# Capture the output of the page:
ob_start();

$_GET['name'] = 'wawan';

require 'template.php';

$content = ob_get_contents();

ob_end_clean();

# Write the captured HTML to the PDF:
$mpdf->WriteHTML($content);
Ry-
  • 218,210
  • 55
  • 464
  • 476