PDF writer delivers empty document

Topics: User Forum
May 13, 2013 at 1:46 PM
I have an app that reads info from a db and delivers it to the user as either a xls or a pdf file. When xls is chosen, it returns several thousand rows, whereas the pdf choice delivers an empty document.

This is how I define my workbook and writers:
    if ($_REQUEST['format'] == 'xls')
    {
        $workbookwriter = PHPExcel_IOFactory::createWriter($workbook, "Excel2007");
        // sending HTTP headers
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="buchungsliste.xlsx"');
        header('Cache-Control: max-age=0');
    } else {
        $rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
        $rendererLibraryPath = KFB_PATH.'/global/tcpdf/';
        if (!PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath)) 
        {
            die("Please set the $rendererName and $rendererLibraryPath values" .
                PHP_EOL . ' as appropriate for your directory structure');
        }
        $workbookwriter = new PHPExcel_Writer_PDF($workbook);
        // sending HTTP headers
        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment;filename="buchungsliste.pdf"');
        header('Cache-Control: max-age=0');
    }
At write time, I do this:
    if ($_REQUEST['format'] == 'xls')
    {
        $workbookwriter->save('php://output');
    } else {
        $workbookwriter->writeAllSheets();
        $workbookwriter->save('php://output');
    }
What am I doing wrong?

Any help is highly appreciated.