title: Blank pdf attachment while sent using FPDF and SwiftMailer
body: <p>I am trying to create a PDF stream using FPDF library and to send the pdf over e-mail using Swift Mailer. Below is my code. The mail is sent successfully and even pdf is also attached but the pdf is of zero bytes size and so could not be opened. When I download the pdf using $pdf->Output('receipt.pdf', 'D') it is successful and the content of PDF is also present. Can somebody help me to identify whether I am doing something wrong? Or do I need to set some additional fields in the message so that it will send the PDF correctly. I searched all the posts related to FPDF and swiftmailer but could not identify issue in my code.</p>
  
  <pre><code>$pdf = new FPDF();
  $pdf-&gt;AddPage();
  $pdf-&gt;Text(80, 30, "Dummy text");
  $pdfstream = $pdf-&gt;Output('receipt.pdf', 'S');
  $attachment = Swift_Attachment::newInstance($pdfstream, 'name.pdf', 'application/pdf');
  
  $message = Swift_Message::newInstance('Dummy subject')
      -&gt;setFrom(array("abc@xyz.com" =&gt; 'XYZ'))
      -&gt;setTo('pqr@abc.com')
      -&gt;setBody('Dummy body text');
  
  $message-&gt;attach($attachment);
  
  $transport = Swift_MailTransport::newInstance();
  
  $mailer = Swift_Mailer::newInstance($transport);
  
  $result = $mailer-&gt;send($message);
  </code></pre>
  
  <p>EDIT 1:
  Below is working perfectly fine for me. Please note that I have used two external libraries SwiftMailer and FPDF so you need to do required things like imports etc. to make them work.</p>
  
  <pre><code>$pdf = new FPDF();
  $pdf-&gt;AddPage();
  $pdf-&gt;Text(80, 30, "Dummy text");
  $data=$pdf-&gt;Output('receipt.pdf', 'S');
  
  $message = Swift_Message::newInstance('Subject')
      -&gt;setFrom(array("Geoff" =&gt; 'abc@xyz.com'))
      -&gt;setTo('xyz@abc.com')
      -&gt;setBody('This is body text', 'text/html');    
  if(!empty($data))
  {
    $attachment = Swift_Attachment::newInstance($data, 'pdf_name.pdf', 'application/pdf');
    $message-&gt;attach($attachment);
  }
  $transport = Swift_MailTransport::newInstance();
  $mailer = Swift_Mailer::newInstance($transport);
  $result = $mailer-&gt;send($message);
  </code></pre>