How to create an invoice (and client) via php api?

No, not very good. It works but I just found that if I put the content from the string to a file (with fopen (…) and name this file invoice.pdf, the pdf works. However, this gives me an empty pdf file:

$invoice = Invoice::find(1);
$pdf = $invoice->download();

header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($pdf));
header('Content-Disposition: attachment; filename="test.pdf"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

return $pdf;