createPDF and send file as attachement

By ht1080z - September 28, 2015 - edited: September 28, 2015

Hi,

How can i store (not temporarily) in a selected folder and send immediately as attachment a PDF file after creation?

Any suggestions are welcome,
Karls

By Dave - September 30, 2015

Hi Karls, 

Here's some sample code from: Admin > Plugins > Create PDF > Example Code

// From /plugins/createPDF/examples/html_as_inline.php "HTML variable as inline PDF"
$html = '<h1>HTML As Inline</h1>';
$data = createPDF_fromHTML($html);
createPDF_display('inline', $data, 'example.pdf');

You can use this to get the PDF content in $data and then email that.  Here's an example:

// Send as email
$errors = sendMessage(array(
  'from'    => "dave@interactivetools.com",
  'to'      => "dave@interactivetools.com",
  'subject' => "Email with attached PDF",
  'text'    => "Here's the PDF attachment!\n",
  'attachments' => array(
    'sample.pdf'  => createPDF_fromHTML('<h1>HTML As Inline</h1>')
  ),
));
if ($errors) { die($errors); }

Let me know if that works for you!

Dave Edis - Senior Developer
interactivetools.com

Hi Dave,

Can you send me a quick hint how can i set the destination/source folders on each script please?

Thank you in advance,
Karls

By Dave - September 30, 2015

Hi Karls, 

That code example doesn't require any files.  The file data is just stored in memory until it's sent and the email recipient can choose where to save the attachment.

But you can create files like this:

file_put_contents('hello.txt', 'Hello World'); 

And read them in like this:

$data = file_get_contents('hello.txt'); 

What are you trying to do specifically?

Dave Edis - Senior Developer
interactivetools.com

By Dave - October 2, 2015

Hi Karls, 

You can try adding the help switch to ensure the switches are getting to CreatePDF: 

$GLOBALS['CREATEPDF_CUSTOM_SWITCHES'] = '--disable-smart-shrinking --margin-left 5 --margin-right 5  --extended-help';  

That should cause all the help out to be displayed.  If it's not, the switches aren't reaching Wkhtmltopdf, if it is displayed then you'll have to experiment more.  I'd try --margin-left 50 or 500 and see if that's visible.

And, no, outgoing mail doesn't store attachments (to prevent using too much disk space).

Dave Edis - Senior Developer
interactivetools.com