0

I can convert html page to pdf and send it via email with out any problem, but I am facing trouble with converting php file to pdf.

is it possible to convert php file to pdf using mpdf or do I need to use some other php class for this?

Thanks!

1
  • 4
    Are you trying to embed your php code as text in a pdf file? or convert the OUTPUT of a php file into a pdf? Commented Sep 26, 2012 at 14:20

1 Answer 1

1

The option seems to be like, first convert the output of the php file to html file, save it and pass that file to mpdf.

Thought my solution may seem other way round but it worked well for me.

Or otherwise this Link

<?php
$file = '/home/user/Desktop/myfile.html';
$result = file_get_contents("url/of/ur/page");
echo $result; //view source now
file_put_contents($file, $result);
?>

now u can pass this file to mpdf. Realie sorie bt i havnt used mpdf till date. May be this solution works for you.

Also, other option is curl.

Sign up to request clarification or add additional context in comments.

2 Comments

Your solution seems to be the answer I am looking for but I am unable to create the html file with invoice fields, if possible can you share me your code with me or your method of generating html invoice. Thanks for the help.
I have not tried this code recently, but a year back when i was in Masters, this was my requirement. And this solution helped me. If possible try getting the invoice fields in a html and it would surely help you. and in the meantime i will try to look into my backup to get the required file for you. Regards.

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.