Send PDF Attachment

By Dave - October 25, 2016 - edited: October 25, 2016

Hey Tim, 

Like the same page you're on?  That's a bit tricky.  How we do it with CreatePDF is we setup some code to buffer the output and then run when the page is finished loading.  

What I'd recommend instead is putting the content of the page in an include, eg: mypage.php and mypage_content.php.  Then include "mypage_content.php" from the parent page.

Then, you can include it again when you want to use it's HTML to create a PDF, like this:

// get PDF of page content
$html    = ob_capture(function() { include("./mypage_content.php"); }); // capture output of included file
$pdfData = createPDF_fromHTML($html);
// createPDF_display('inline', $pdfData, 'example.pdf'); exit; // debug: test displaying PDF

Then you pass that to sendMessage like this:

'attachments' => array('sample.pdf' => $pdfData), 

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com

By Toledoh - October 25, 2016

That makes sense - thanks Dave.

NB.  I'm guessing 

What I'd recommend instead is putting the content of the page in an include

Cheers,

Tim (toledoh.com.au)

By Dave - October 25, 2016

Yes, thanks!  (I fixed the original post)

Dave Edis - Senior Developer
interactivetools.com