title: How to send pdf generated by TCPDF as Swiftmailer attachment
body: <p>I already tried several solutions, the closest (for me) should look like this:</p>
  
  <pre><code>$file = $pdf-&gt;Output('', 'E');
  $message-&gt;attach(Swift_Attachment::newInstance($file, 'name.pdf', 'application/pdf'));
  </code></pre>
  
  <p><code>$pdf</code> is an instance of <code>TCPDF</code> and <code>$message</code> is an instance of <code>Swift_Message</code>.
  Using above the email is being sent ok, file is attached but when I try to open it I get the error message that file is corrupted or badly encoded.   </p>
  
  <p>My question is: how to send pdf generated by TCPDF as Swiftmailer attachment <strong>without saving the file to server and deleting it after sending the email</strong>. <a href="https://tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1" rel="nofollow">Here</a> is the link to the TCPDF output method documentation, maybe somebody can see something I have missed.</p>