Como mostrar o ficheiro pdf em HTML

Tenho um ficheiro PDF gerado automaticamente por itext e preciso de mostrar esse ficheiro PDF em HTML. Minha pergunta é: como exibir um arquivo PDF local em HTML usando pdf.js ? Esse arquivo PDF deve ser gerado por alguns padrões?

 79
Author: Matthias Braun, 2013-07-22

11 answers

A implementação de um ficheiro PDF na sua página web HTML é muito fácil.

<embed src="file_name.pdf" width="800px" height="2100px" />

Certifique-se de mudar a largura e a altura para as suas necessidades. Boa sorte!

 127
Author: Gofilord, 2016-08-18 18:01:43

Se quiser usar pdf.js, sugiro que leia isto.

Você também pode carregar o seu pdf em algum lugar (como o Google Drive) e usar o seu URL numa iframe

Ou

<object data="data/test.pdf" type="application/pdf" width="300" height="200">
<a href="data/test.pdf">test.pdf</a>
</object>
 18
Author: Community, 2017-05-23 12:02:39

Uso o visualizador de PDF incorporado do Google Docs. Os documentos não têm de ser enviados para o Google Docs, mas têm de estar disponíveis online.

<iframe src="http://docs.google.com/gview?url=http://path.com/to/your/pdf.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
 17
Author: Rahul Sinha, 2016-07-04 04:36:43

Na página html para pc é fácil de implementar

<embed src="study/sample.pdf" type="application/pdf"   height="300px" width="100%">

Mas a apresentação em pdf no móvel por este código não é possível, você precisa de um plugin

Se não tiver respondido ao seu site. Em seguida, acima do Código pdf não Mostrar no celular, mas você pode colocar a opção de download após o código

<embed src="study/sample.pdf" type="application/pdf"   height="300px" width="100%" class="responsive">
<a href="study/sample.pdf">download</a>
 7
Author: pradip kor, 2017-07-09 07:11:12

Você pode mostrar facilmente numa página html como esta

<embed src="path_of_your_pdf/your_pdf_file.pdf" type="application/pdf"   height="700px" width="500">
 4
Author: harun ugur, 2017-09-14 09:06:16

Já tive algo semelhante antes e usei normalmente etiquetas

<a href="path_of_your_pdf/your_pdf_file.pdf" tabindex="-1"><strong>click here</strong></a>
Mas é interessante descobrir outras maneiras como em cima!
 3
Author: DirWolf, 2018-07-26 15:34:56

Formato de Documento Portátil (PDF).

  • Qualquer navegador " Use _Embeddable Google Document Viewer para incorporar o ficheiro PDF em iframe.

    <iframe src="http://docs.google.com/gview?
        url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true"
        style="width:600px; height:500px;" frameborder="0">
    </iframe>
    
  • Apenas para o navegador chrome "visualizador de PDF Chrome usando o 'plugin'. pluginspage=http://www.adobe.com/products/acrobat/readstep2.html.

    <embed type="application/pdf" 
    src="http://www.oracle.com/events/global/en/java-outreach/resources/java-a-beginners-guide-1720064.pdf" 
    width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" 
    background-color="0xFF525659" top-toolbar-height="56" full-frame="" internalinstanceid="21" 
    title="CHROME">
    

Exemplo Sippet:

<html>
   <head></head>
   <body style=" height: 100%;">
      <div style=" position: relative;">
      <div style="width: 100%; /*overflow: auto;*/ position: relative;height: auto; margin-top: 70px;">
         <p>An 
            <a href="https://en.wikipedia.org/wiki/Image_file_formats" >image</a> is an artifact that depicts visual perception
         </p>
         <!-- To make div with scroll data [max-height: 500;]-->
         <div style="/* overflow: scroll; */ max-height: 500; float: left; width: 49%; height: 100%; ">
            <img width="" height="400" src="https://peach.blender.org/wp-content/uploads/poster_bunny_bunnysize.jpg?x11217" title="Google" style="-webkit-user-select: none;background-position: 0px 0px, 10px 10px;background-size: 20px 20px;background-image:linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee 100%),linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #eee 100%);cursor: zoom-in;" />
            <p>Streaming an Image form Response Stream (binary data) «  This buffers the output in smaller chunks of data rather than sending the entire image as a single block. 
               <a href="http://www.chestysoft.com/imagefile/streaming.asp" >StreamToBrowser</a>
            </p>
         </div>
         <div style="float: left; width: 10%; background-color: red;"></div>
         <div style="float: left;width: 49%; ">
            <img width="" height="400" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot"/>
            <p>Streaming an Image form Base64 String « embedding images directly into your HTML.
               <a href="https://en.wikipedia.org/wiki/Data_URI_scheme">
               <sup>Data URI scheme</sup>
               </a>
               <a href="https://codebeautify.org/image-to-base64-converter">
               <sup>, Convert Your Image to Base64</sup>
               </a>
            <pre>data:[&lt;media type&gt;][;base64],&lt;data&gt;</pre>
            </p>
         </div>
      </div>
      <div style="width: 100%;overflow: auto;position: relative;height: auto; margin-top: 70px;">
      <video style="height: 500px;width: 100%;" name="media" controls="controls">
         <!-- autoplay -->
         <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/mp4">
         <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/ogg">
      </video>
      <p>Video courtesy of 
         <a href="https://www.bigbuckbunny.org/" >Big Buck Bunny</a>.
      </p>
      <div>
         <div style="width: 100%;overflow: auto;position: relative;height: auto; margin-top: 70px;">
            <p>Portable Document Format 
               <a href="https://acrobat.adobe.com/us/en/acrobat/about-adobe-pdf.html?promoid=CW7625ZK&mv=other" >(PDF)</a>.
            </p>
            <div style="float: left;width: 49%; overflow: auto;position: relative;height: auto;">
               <embed type="application/pdf" src="http://www.oracle.com/events/global/en/java-outreach/resources/java-a-beginners-guide-1720064.pdf" width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" background-color="0xFF525659" top-toolbar-height="56" full-frame="" internalinstanceid="21" title="CHROME">
               <p>Chrome PDF viewer 
                  <a href="https://productforums.google.com/forum/#!topic/chrome/MP_1qzVgemo">
                  <sup>extension</sup>
                  </a>
                  <a href="https://chrome.google.com/webstore/detail/surfingkeys/gfbliohnnapiefjpjlpjnehglfpaknnc">
                  <sup> (surfingkeys)</sup>
                  </a>
               </p>
            </div>
            <div style="float: left; width: 10%; background-color: red;"></div>
            <div style="float: left;width: 49%; ">
               <iframe src="https://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true#:page.7" style="" width="100%" height="500px" allowfullscreen="" webkitallowfullscreen=""></iframe>
               <p>Embeddable 
                  <a href="https://googlesystem.blogspot.in/2009/09/embeddable-google-document-viewer.html" >Google</a> Document Viewer. Here's the code I used to embed the PDF file: 
<pre>
&lt;iframe 
src="http://docs.google.com/gview?
url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" 
style="width:600px; height:500px;" frameborder="0"&gt;&lt;/iframe&gt;
</pre>
               </p>
            </div>
         </div>
      </div>
   </body>
</html>
 1
Author: Yash, 2018-02-05 10:34:02

Usando Javascript, é possível exibir um arquivo PDF no HTML via Mozilla PDF.Biblioteca JS. Veja aqui uma demonstração .

Existe também um plugin de Javascript de Visualizador de PDF para incorporar ficheiros PDF. Aqui está uma demonstração. (o plugin não é gratuito)

 1
Author: Useful Angle, 2018-05-18 08:02:07

A maneira mais simplesé usar,

<iframe src="pdf-link">
</iframe>

E se ainda estiver a obter download em vez de visualização, verifique o cabeçalho de resposta do servidor, que deverá ter, Content-Disposition:Inline e não, Content-Disposition:Attachment.

 0
Author: Rohith Murali, 2018-10-04 10:54:38

Opção do Rio Único:

Tentei usar o OneDrive e gostei mais, uma vez que mostra várias opções, incluindo abrir numa página nova e um cursor de qual página está activa de momento e também uma opção para abrir numa janela nova.

Tudo o que precisas de fazer é:

  1. envie o seu ficheiro para uma conta OneDrive
  2. Seleccione o ficheiro e carregue em "Embed"
  3. Copia o código e podes ir!
A visualização de um ficheiro OneDrive não precisa que os utilizadores façam login OneDrive e o espectador vem muito sensível.
<iframe src="https://onedrive.live.com/embed?cid=54ED32C07853E1A8&resid=54ED32C07853E1A8%2137025&authkey=AKS95k1Xm-uE1lA&em=2" width="476" height="288" frameborder="0" scrolling="no"></iframe>
 -1
Author: Aditya Bajaj, 2018-03-14 17:01:54

Se quiser pode usar o visualizador.js para o visualizador de pdf é a melhor opção se você estiver a abrir o ficheiro existe na sua máquina caso contrário, terá de enviar esse ficheiro até agora, não tive nenhuma opção de mostrar o ficheiro em forma binária a mostrar na janela web

 -1
Author: dheerendra singh, 2018-07-23 09:48:34