Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force PDF to display inline, even when Content-Disposition says otherwise?

I am embedding PDF in an IFRAME from a server that is unfortunately serving them as Content-Disposition:attachment;.

Is there any way to force the browser to display the PDF inline? Unfortunately I cannot change the headers for the PDF file linked in the iframe.

like image 987
Jordan Reiter Avatar asked Jun 17 '13 21:06

Jordan Reiter


1 Answers

You could use pdf.js library for rendering pdf in html page. Mozilla Pdf.js

HTML CODE

<!DOCTYPE html>
<html>
 <head>
  <title>PDF.js Learning</title>
 </head>
 <body>
  <script type="text/javascript" src="pdf.js"></script>
  <canvas id="the-canvas"></canvas>

 </body>
</html>

JAVASCRIPT CODE

 var url = "www.pdf995.com/samples/pdf.pdf";

 PDFJS.getDocument(url)
  .then(function(pdf) {
   return pdf.getPage(1);
   })
 .then(function(page) {

 var scale = 1.5;


 var viewport = page.getViewport(scale);

 // Get canvas#the-canvas

 var canvas = document.getElementById('the-canvas');

 // Fetch canvas' 2d context

 var context = canvas.getContext('2d');

 // Set dimensions to Canvas

 canvas.height = viewport.height;
 canvas.width = viewport.width;

 // Prepare object needed by render method

  var renderContext = {
 canvasContext: context,
 viewport: viewport
 };

 // Render PDF page

  page.render(renderContext);
 });
like image 76
Arun Sivan Avatar answered Sep 28 '22 09:09

Arun Sivan