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];

?>
2
  • 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? Commented Dec 12, 2012 at 3:46
  • You may want to check this post: stackoverflow.com/questions/391005/… Commented Dec 12, 2012 at 3:47

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.