php - create pdf from blob in popup window


I am trying to open a pdf blob in popup window. I don't want to write the blob back to disk for security reasons. I am using php to extract the blob and can produce a pdf document from php using the header() command to set 'content-type: application/pdf', write the blob to the current page. That's fine, but I am afraid the user will close the window when done, rather than go back to the php page, thus exiting the app. I can use php to create a page, and pass the blob to javascript and let it create the popup, and write the contents, but then all I get is the raw contents of the pdf file, not rendered by the PDFreader.

php test code that creates the page with popup:

$pdf = $row['AttachmentDecBlob'];

<script type='text/javascript'>
function loadpdf() {
    w ="","viewer.pdf");
    w.document.write(hdr + "\r\n");
print "var hdr=\"Content-type: application/pdf\"\n";
print "var pdf=\"" . mysql_real_escape_string($pdf,$link) . "\"\n"; 
<input type=button value='Viewer' onClick="loadpdf();return true;"></input>

I need a way to set the content-type of the new window to pdf, or possibly someone can suggest another method to view that pdf blob in a separate window.

People are also looking for solutions to the problem: php - codeigniter pagination with selected records


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.