Reputation: 1040
I am using an API which provides me base64 encoded content. It is mentioned that we can download the PDF file by saving the content to a .pdf file.
In the API documentation, it's clearly mentioned
A PDF that contains the contents of the invoice. You encode the content with a Base64 string to create a Base64-encoded .pdf file.
You can query this field to download the invoice PDF for a specific invoice. After you query it, you can save the string to a .pdf file, then view the file in any PDF reader.
I am using TCPDF to write the content in PDF file. But it generates a blank PDF file.
$PDF = new PDF('Test Title', 'Test Subject');
$PDF->GetTCPDF()->write(0, 0, '', '', base64_decode($this->Get(self::Body)), 0, 1, 0, true, '', true);
$PDF->Download();
Am I doing anything wrong?
Upvotes: 0
Views: 18696
Reputation: 101
The last time I get a blank PDF I forgot adding a new Page with AddPage(). Apart from this I think M2sh is right.
Upvotes: 0
Reputation: 761
I think you should use this code to get your pdf file :
$data = base64_decode($this->Get(self::Body));
file_put_contents('mypdf.pdf',$data);
Then you can open it.
Or you can echo the content to your page like this :
$data = base64_decode($this->Get(self::Body));
header('Content-Type: application/pdf');
echo $data;
Good luck
Upvotes: 9