'Remove 'E' output headers from base64 string in TCPDF

I'm using TCPDF using

$base64String = $pdf->Output('file.pdf', 'E');

So I can send the data via AJAX

The only problem is that it comes with header information in addition to the Base64 string

Content-Type: application/pdf;
 name="FILE-31154d59f28c63efae86e4f3d6a00e13.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="FILE-31154d59f28c63efae86e4f3d6a00e13.pdf"

So if I take the string that is created to base64_decode() or use with phpMailer in my case it errors. Is it possible to remove the headers so I only have the base64 string?

(The error is that the pdf can't be read by any PDF reader when opened)

I thought I'd be able to find something that solves this but I haven't found anything!!

UPDATE

This is what I've put in place to solve the issue

$base64String = preg_replace('/Content-[\s\S]+?;/', '', $base64String);
$base64String = preg_replace('/name=[\s\S]+?pdf"/', '', $base64String);
$base64String = preg_replace('/filename=[\s\S]+?"/', '', $base64String);

However it's not very elegant! So if anyone has a better solution please post it below :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source