Forum How do I...?

pdf as an email attachment

nirvahnuh
Hi guys, I'm new with princexml. I have one question. Is it possible to generate a pdf file and automatically attach that pdf into email by using mail() function? anyway, I'm using PHP.

Please help, thanks :roll:
mikeday
You can certainly generate a PDF file from PHP using Prince, but I'm not an expert on the mail() function. What you need to know is how to send an email from PHP that includes attachments, which would make it a multipart MIME message. (The type of the attachment file doesn't really matter). If you google for "PHP mail() attachments" you will find a number of examples demonstrating how to send mail including attached files; once you've got this working it should be easy to attach a PDF generated with Prince.
consultend
We switched from DomPDF to PrinceXML because of the better rendering time. With DOMPDF we were using $dompdf->output() to write the PDF output to a string. This string was attached to the email.

The benefits of this solution are:
- PDF could be attached as a file
- No file stored on the server

--- DOMPDF Code ---
$dompdf = new DOMPDF();
$dompdf->set_paper( 'a4', 'portrait' );
$dompdf->load_html( $mypdf );
$attachment = chunk_split( base64_encode( $dompdf->output( array("compress" => 1) ) ) );

Later on, the attachment was attached to the mail.

My question:
What is the PrinceXML equivalent to $dompdf->output?

If I use convert_file_to_passthru the output is sent to screen. The _to_string solution is not applicable since I don't want to store a file on the server.

The result should be something like this:
$attachment = chunk_split( base64_encode( $prince->convert_file_to_passthru( 'example.html' ) ) );

Thanks in advance
mikeday
You can use ob_start() and ob_end_flush() around the passthru to capture the results as a string instead of returning it to the browser.