View a PDF file in HTML not to download it

前端 未结 6 1898
一个人的身影
一个人的身影 2020-12-30 07:31

I have a very simple pure html file in which I have many PDF files. I have link it like this:

 PDF 1 here 

相关标签:
6条回答
  • 2020-12-30 07:52

    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.

    0 讨论(0)
  • 2020-12-30 07:56

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

    0 讨论(0)
  • 2020-12-30 07:58

    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/)

    0 讨论(0)
  • 2020-12-30 07:58

    i use this

    for the HTML

    <a href="view.php?download_file=MIKOGO Remote Support.pdf"><img src="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 directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
    }
    fclose ($fd);
    exit;
    ?>
    

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

    0 讨论(0)
  • 2020-12-30 08:11

    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.

    0 讨论(0)
  • 2020-12-30 08:13

    right click Open with Choose default programme Select Adobe Reader OK If you want open chrome any other app Same steps Last Step Select Chrome

    0 讨论(0)
提交回复
热议问题