-1

PHP code generates pdf content(using mpdf).I need to display it in browser using js (ajax request gets this pdf content as string). How can I do this?

PHP:

$data['content'] = utf8_encode($this->_getViewPDF($data['content']));

JS:

var jsonString = utf8_decode(data.content);
var template = "<object type='application/pdf' data= '" + jsonString + "'>";
var windowPrint,
objBrowse = window.navigator;

windowPrint = window.open('', '_blank');

windowPrint.document.write(template);
windowPrint.document.close();
windowPrint.focus();

But browser displays only pdf code

hakre
  • 193,403
  • 52
  • 435
  • 836
Miranda
  • 1
  • 1
  • 7
  • 1
    Was there anything wrong with the 43,300,000 results returned for a Google search on [display pdf with javascript](https://www.google.com.au/#q=display+pdf+with+javascript)? – Christian May 08 '14 at 07:31
  • possible duplicate of [Can JavaScript set the mime type on window.open](http://stackoverflow.com/questions/7707957/can-javascript-set-the-mime-type-on-window-open) – hakre May 08 '14 at 07:52
  • I have read a lot of posts, but I didn't found how to display pdf from base64 code – Miranda May 08 '14 at 08:10
  • @AlexK: Have you tried with [RFC 2397](http://tools.ietf.org/html/rfc2397)? Those could work with `window.open` as those URIs can ship a mime-type. But I'm just guessing, you need to do further research. – hakre May 08 '14 at 09:57

1 Answers1

0

Generate a PDF file into a temporary file accessible via a URL from your web server, and then have the script send back the URL for accessing that file.

Refer links below

using AJAX and Jquery to create pdf using FPDF

XMLHttpRequest to open PDF in browser

Community
  • 1
  • 1
Dave
  • 4,376
  • 3
  • 24
  • 37