I am trying to get a PDF from binaries. My old code is working, but now that I'm using ZF2, the PDF seems to be corrupted and I'm not sure why.
Old code
echo $html->link($zvk,array('controller'=>'daten', 'action'=>'download',$id,$zvk),array('escape' => false));
Action
header('Content-Disposition: attachment; filename=doc_' . $zvk . '.pdf');
header("Cache-control: private");
header("Content-transfer-encoding: binary");
header("Content-type: application/pdf;");
header('Content-length: ' . strlen($binary));
echo $binary;
ZF2 Code
// Disable layout and view
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// Generate PDF filename
$sFilename = sprintf("doc(%s, %s) - %s.pdf",
$oSelectedP->name,
$oSelectedZ->Zvk,
date("Y-m-d"));
$this->getResponse()
->setHeader("Content-type", "application/pdf")
->setHeader("Content-disposition", "attachment; filename=\"" . $sFilename . "\"")
->setHeader("Content-length", strlen($aData[0]["dokument"]))
->setHeader("Cache-control", "private")
->setHeader("Content-transfer-encoding", "binary")
->setBody($aData[0]["dokument"]);
I dont get any error messages, just the corrupted file. Any suggestions?
Checking the corrupted PDF give this
Open file. 0x80410108 - E - The end-of-file marker was not found. - File: C:\Windows\TEMP\tmpCB04.tmp 0x8041010A - E - The 'startxref' keyword or the xref position was not found. - File: C:\Windows\TEMP\tmpCB04.tmp 0x80410108 - E - The end-of-file marker was not found. - File: C:\Windows\TEMP\tmpCB04.tmp Close file.
But I do not know how to set those. I did not have to do this in the first way, so i would guess it is part of the binaries.