Skip to content Skip to sidebar Skip to footer

View A Pdf File In Html Not To Download It

I have a very simple pure html file in which I have many PDF files. I have link it like this: PDF 1 here When I click the link, the PDF fil

Solution 1:

2018 Update

Almost all modern browsers have built-in PDF viewers. You can directly link to the PDF file and the browser will view it. You can also use an <iframe> if you want to view it inside an HTML page (e.g. with your website headers, etc.).

Another approach, but more complicated and not necessary except for very special circumstances, is to convert the PDF files to HTML (as described in #1 of the 2012 answer below).

Original Answer (Outdated, from 2012)

Viewing the PDF file in the browser (without download) requires an add-on to the client's browser. Google Chrome, for example, has a built-in PDF viewer and can open files directly, while IE and Firefox require that you install a plug-in (the one that comes with Adobe Reader).

There are two other approaches:

  1. Convert the file to HTML, image, or any other format that can be directly viewed in the browser. This conversion can be on-the-fly using a server-side (written in PHP, Python, ASP, whatever language), or you can just pre-convert all files to a readable one.

  2. The other approach, which is the best, is to use a Flash-based PDF viewer (such as http://flexpaper.devaldi.com/). This is easy, flexible and doesn't require writing server-side code. This approach is used by many Document-sharing sites (e.g. http://www.scribd.com/, http://www.slideshare.net/, http://www.docstoc.com/)

Solution 2:

i use this

for the HTML

<ahref="view.php?download_file=MIKOGO Remote Support.pdf"><imgsrc="images/view.png"alt=" "border="0"/></a>

and the view.php file for viewing it through PDF.

<?php$path = $_SERVER['DOCUMENT_ROOT']."/demo/documents/"; // change the path to fit your websites document structure$fullPath = $path.$_GET['download_file'];

if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
    case"pdf":
    header("Content-type: application/pdf"); // add here more headers for diff. extensions
    header("Content-Disposition: inline; filename=\"".$path_parts["basename"]."\"");     
    break;
    default;
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directlywhile(!feof($fd)) {
    $buffer = fread($fd, 2048);
    echo$buffer;
}
}
fclose ($fd);
exit;
?>

Make sure the your browser has PDF add-on on it.

Solution 3:

Mozilla created the PDF.js library. It displays pdf files in a web page without an external reader or plugin.

Solution 4:

Your browser needs a PDF reader plug in to read PDFs in browser. A quick google search should provide you with one for whatever browser you are using.

Solution 5:

If the file is not cached, it has to be downloaded. That is, if you grab it using HTTP. If it's on your local filesystem, you could use the file URI scheme.

Post a Comment for "View A Pdf File In Html Not To Download It"