How to display pdf file in HTML

I have an automatically generated PDF itext file and I need to display this PDF file in HTML. My question is: how to display a local PDF file in HTML using pdf.js ? Should a PDF file be created by some standards?

+122
html pdf
Jul 22 '13 at 9:29
source share
10 answers

Implementing a PDF file on an HTML web page is very simple.

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

Be sure to change the width and height of your needs. Good luck

+183
Mar 21 '14 at 21:31
source share

I am using Google Docs Embedded PDF Viewer. Docs do not need to be uploaded to Google Docs, but they must be available online.

 <iframe src="https://docs.google.com/gview?url=https://path.com/to/your/pdf.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe> 
+37
Jul 03 '16 at 17:55
source share

If you want to use pdf.js, I suggest you read THIS

You can also upload your pdf file (e.g. Google Drive) and use its URL in the iframe

or

 <object data="data/test.pdf" type="application/pdf" width="300" height="200"> <a href="data/test.pdf">test.pdf</a> </object> 
+23
Jul 24 '13 at 16:19
source share

you can easily view it on an html page like

 <embed src="path_of_your_pdf/your_pdf_file.pdf" type="application/pdf" height="700px" width="500"> 
+10
Sep 14 '17 at 9:06 on
source share

The html page for PC is easy to implement

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

but pdf to show this code on a mobile phone is impossible, you need a plugin

if you do not respond to your site. Then the above pdf code is not displayed on the mobile phone, but you can put the download option after the code

 <embed src="study/sample.pdf" type="application/pdf" height="300px" width="100%" class="responsive"> <a href="study/sample.pdf">download</a> 
+9
Jun 29 '17 at 5:01
source share

Portable Document Format ( PDF ).

  • Any Browser Use the _Embeddable Google Document Viewer to embed a PDF in an 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> 
  • Chrome browser only "Chrome PDF Viewer using the 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"> 

Sippet example:

 <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 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> " <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 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> png; base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 // <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 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> dot" /> <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 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> 

+4
Feb 05 '18 at 10:34
source share

I had something similar before, and I used regular tags

 <a href="path_of_your_pdf/your_pdf_file.pdf" tabindex="-1"><strong>click here</strong></a> 

but it’s interesting to know some other ways as stated above!

+4
Jul 26 '18 at 15:34
source share

the easiest way is to use

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

and if it still loads downloaded instead of viewing, check the response header of the server, it should have Content-Disposition:Inline , not Content-Disposition:Attachment .

+4
04 Oct '18 at 10:54
source share

Using Javascript, you can display a PDF file in HTML format through the Mozilla PDF.JS library. See here for a demo .

There is also a PDF Viewer Javascript plugin for embedding PDF files. Here is a demo . (plugin is not free)

+2
Sep 27 '17 at 20:59 on
source share

The element is supported by all browsers and defines an embedded object in an HTML document.

Bottom line: OBJECT is Good, EMBED is Old. In addition to IE PARAM tags, any content between OBJECT tags will be displayed if the browser does not support the specified OBJECT plugin, and it seems that the content receives an HTTP request regardless of whether it is rendered or not. Reference

Working code: https://www.w3schools.com/code/tryit.asp?filename=G7L8BK6XC0A6

 <!DOCTYPE html> <html> <body> <object width="400px" height="400px" data="https://s3.amazonaws.com/dq-blog-files/pandas-cheat-sheet.pdf"></object> </body> </html> 

0
Sep 02 '19 at 7:22
source share



All Articles