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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With