Embed PDF in mobile browsers - html

I have the code below which is a perfect solution to what I need, which would essentially be embedding any of JPG, GIF, PNG or PDF files in my webpages. It works perfectly in PC browsers, but a critical requirement for the pages is to have them compatible in mobile browsers due to its target users.
<iframe src="uploads/test1.pdf" width="auto" height="auto"> </iframe>
Although image files work fine, PDF files are opened separately in the mobile browser and not embedded inline in the web page. What would be an alternative solution or implementation to this?

You can use PDFJs library. Using just JS you can render pdf files.
Please , check here : https://mozilla.github.io/pdf.js/

One simple option is that the the object element provides a fallback, so you can do:
<object data='some.pdf'>
<p>Oops! Your browser doesn't support PDFs!</p>
<p>Download Instead</p>
</object>
Then, when the mobile browser can't get the item, it'll just show this and you'll be all set, kinda.

Here is my solution to this problem.
<object data="mypdf.pdf" type="application/pdf" frameborder="0" width="100%" height="600px" style="padding: 20px;">
<embed src="https://drive.google.com/file/d/1CRFdbp6uBDE-YKJFaqRm4uy9Z4wgMS7H/preview?usp=sharing" width="100%" height="600px"/>
</object>
Explanation:
<object> tag has a feature that when it is unable to load item, it loads the content inside itself i.e tag.
Since object tag cannot load on mobile view, therefore on mobile devices, embed tag will become active.
Q) Why can't we directly use tag for all cases?
You can actually, but since the embed tag is loading file from
drive, it does not gives any user controls for the pdf that we see
with object tag (zoom, page no., etc.). So our code will give the user pdf view controls atleast in the desktop mode instead of not giving any controls at all.
Q) Direct drive links don't work....so why this solution?
In the above google drive URL, view is changed to preview.
drive.google.com/file/d/1CRFdbp6uBDE-YKJFaqRm4uy9Z4wgMS7H/view?usp=sharing
becomes,
drive.google.com/file/d/1CRFdbp6uBDE-YKJFaqRm4uy9Z4wgMS7H/preview?usp=sharing
So, we can make direct drive links work with this little modification

Google Docs viewer offers a feature, that lets you embed PDF files and PowerPoint presentations on a web page.
<iframe src="https://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:100%; height:650px;" frameborder="0"></iframe>
replace the URL(http://infolab.stanford.edu/pub/papers/google.pdf) with your own address, It's worked for me but it takes more time to load on
src:http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html?utm_source=pocket_mylist

The only way I have found, which allows you to embed pdf is using Google drive, then select the menu button once you have opened your file, and select get embed code, you can only use a Google drive or Google docs reference. And you must also turn public sharing on otherwise others won't be able to view it without permission.

Using Adobe PDF Embed API solved my problem.
Adobe PDF Embed API

I ran into the same issue. As a new developer, I wasn't aware that mobile browsers have issues embedding PDF files in iframes. I am now... lol
I racked my resources trying to get this to work when it dawned on me that mobile browsers do not have an issue displaying PNG files in a new window. So, in my infinite wisdom, I opened the PDF files in Gimp 2.0 then exported them as PNG files. And then I created buttons for the user to click and now it opens the graphic instead of trying to embed the PDF.
Looks like this:
<input class="AG" id="UnityBtn" type="button" value="Unity" onclick="location.href='../Meeting_Info/Unity.png'" />
I don't know if this is possible for you, but it worked beautifully for me.

Use an object tag with a iframe tag inside your object tags.
The object data can be a pdf or png file by changing the type and can use any link you want stored wherever, however the I frame is the one which will be loaded for mobiles which has to be a link from Google drive or Google docs you also need to allow the files to be shared public otherwise others won't be able to view them.
I would share the code but this site has some rubbish rules about code and won't let me share them so I'll leave you to Google how object and iframe tags work by viewing better sites that actually wants the help from developers.
Have fun guys!

Related

embed PDF not working in Android Chrome - plugin not supported

I want to display my PDF files on my web page.
This is my code which works perfectly my computers browser but id does not display in mobile's chrome shows the message
plugin not supported
this is my code
<embed src="http://health.ntuh.gov.tw/health/NTUH_e_Net/NTUH_e_Net_no91/%E7%99%8C%E7%97%87%E7%AF%A9%E6%AA%A2.pdf" type="application/pdf" />
You can use Google Drive PDF viewer with Object data
ex.
<object data="https://drive.google.com/viewerng/viewer?embedded=true&url=http://health.ntuh.gov.tw/health/NTUH_e_Net/NTUH_e_Net_no91/%E7%99%8C%E7%97%87%E7%AF%A9%E6%AA%A2.pdf" type="application/pdf">
<embed src="https://drive.google.com/viewerng/viewer?embedded=true&url=http://health.ntuh.gov.tw/health/NTUH_e_Net/NTUH_e_Net_no91/%E7%99%8C%E7%97%87%E7%AF%A9%E6%AA%A2.pdf" type='application/pdf'>
</object>
PDF must be a download to browsing device So Some browsers can display with their pdf extension and some may not have such a pdf extender.
Users can set their own PDF preferences like display or not display after download or use a different PDF extender.
Embed is not the preferred method for serving a PDF, the most preferred method is text or a thumbnail cover / image icon with <a href=file.pdf download> click to download whole file</a> this reduces the load on the server (reduced cost like Amazon / book sites)
&nbsp
2nd best is one iFrame on a page Below on Right (more than one means multiple downloads.)
Finally an Embed (Object is a method to be avoided as now depreciating / not good) See your Embed in an Object Above Left

How can I directly embed audio that I have uploaded to OneDrive into HTML using the <audio> element?

I would like to know how I can directly embed an audio file that I have uploaded to OneDrive in HTML using the <audio> element.
I know there's always an Embed button in OneDrive, but I don't want that. That really only provides a big rectangle-shaped thing with a music icon and the filename, and when I click that, I'm still redirected to OneDrive. How can I really embed this using the HTML <audio> element?
I actually already tried the Copy Audio Location menu item from Firefox's context menu. It gave me a link that worked in the Dreamweaver's Live Preview (in the split view), but it didn't work in any other browser, including Firefox and Chrome.
I would like to use pure HTML to do this, i.e. no JavaScript.
Does anyone know how to do this? Thanks!
You can probably do it this way:
Get the direct link to the file:
how to do it:
Open OneDrive and Copy Embed Code
Paste the Embed Code and Modify:
Now paste the embed code you copied in a notepad or a text editor. This code looks like this one – <iframe src="https://onedrive.live.com/embed?cid=FA476CAFF1A7E75C&resid=FA476CAFF1A7E75C%21122&authkey=AN_axXpcOy7Zfl8" width="98" height="120" frameborder="0" scrolling="no"></iframe>. You have to modify this code, remove everything except source URL of the file https://onedrive.live.com/embed?cid=FA476CAFF1A7E75C&resid=FA476CAFF1A7E75C%21122&authkey=AN_axXpcOy7Zfl8 and then just replace embed with download to get direct/permanent link. After this modification, the link should look like this – https://onedrive.live.com/download?cid=FA476CAFF1A7E75C&resid=FA476CAFF1A7E75C%21122&authkey=AN_axXpcOy7Zfl8
That’s the OneDrive direct or native link
Use this link in the audio tag:
<audio src="https://onedrive.live.com/download?cid=FA476CAFF1A7E75C&resid=FA476CAFF1A7E75C%21122&authkey=AN_axXpcOy7Zfl8"></audio>
I mean provide into src the link you get from OneDrive.

Object tag content disappears in Safari/Chrome

We allow users of our application to embed a webpage containing a set of thumbnails into another third party webpage/blog etc. The embedding is done by using an object tag.
Each thumbnail provides an option to download original file. When user clicks on this option, the embedded content is disappearing in Safari 5.1.1 and Chrome 15.0 and instead "Could not render embedded content" is shown. Whereas FF 8.0 works correctly i.e. the embedded page stays there even after download, as it should.
The embed code we are using is like this -
<object data="http://myserver.com/em.aspx?e=FytXStk=" height="600" width="900" type="text/html">
<p>Could not render embedded content.</p>
</object>
Can anyone see what might be wrong here? Thanks.
I had to add target="_parent" for the download link. That did the trick.
Actually, if you just choose "Shockwave" instead of "Flash" from the drop down menu for video type, it all works perfectly.
Joomla Core Team has gotta do a better job on notifying developers and webmasters. It's obviously not obvious.

Embed a Powerpoint in a Web Page

Is there any way to embed a PowerPoint slide show in an HTML page using just the standard tags etc? I tried using a iframe, but that just results in the PowerPoint being downloaded.
<iframe src="Chapter1.pptx">Your browser does not support.</iframe>
I am looking for a way to show the slide show using only standard stuff. I realize I could use google docs or flash or something, but I'd rather have a simple implementation.
Does the web just not know how to process a PowerPoint presentation?
Plain and simple...this is the best method to embed any Microsoft or Adobe file into a HTML website.
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[https://www.your_website/file_name.pptx]' width='100%' height='600px' frameborder='0'>
Just to update this question - as there is a new way to embed Powerpoints in a web page. If you have an account on OneDrive, do the following using Powerpoint Online (accessing Powerpoint via the browser) to embed a Powerpoint:
Click 'File', then 'Share', then 'Embed'
Click the 'Generate' button to generate HTML code to be embedded
Copy the 'Embed Code' and paste it in the HTML of a website
Web browsers don't understand power point, but there are solutions besides Flash.
You could export it to HTML or a PDF. Or you could also upload to site like slideshare and make use of their players which are built for this problem.
I have decided to take a hack route and upload the powerpoint onto YouTube and then just include the youtube video in the iframe.
<iframe height="375" width="600" src="http://www.youtube.com/embed/assignedId"></iframe>
I know, it's cheap, but it's also easy.
EDIT
I eventually checked my page as XHTML Strict, which does not support the <iframe> tag. So I used the object tag instead.
<object data="http://www.youtube.com/embed/assignedId">
I tried answer posted by Shane, which looks exactly right and how MS used to have PPT viewing online earlier but it didn't worked for me. After doing some research I found out that the link has changed a bit.
So use:
https://view.officeapps.live.com/op/view.aspx instead of https://view.officeapps.live.com/op/embed.aspx
Example:
<iframe src='https://view.officeapps.live.com/op/view.aspx?src=[https://www.your_website/file_name.pptx]' width='100%' height='600px' frameborder='0'>
Note: Link to PPT need to be publicly accessible.
Use Microsoft skydrive, upload your power point to this site and use this code
where
http://skydrive.live.com/redir.aspx?cid=20f065afc1acdb2e&page=view&resid=20F065AFC1ACDB2E!723&parid=20F065AFC1ACDB2E!719 is the URL of the powerpoint file.
You have to replace SD20F065AFC1ACDB2E!723 for your own string of the corresponding URL
Upload a PowerPoint document on your Google Drive and then 'Share' it with everyone (make it public):
Sharing your pptx doc
Then, go to File > Publish to the web > hit the publish button.
Go to Embed and copy the embed code and paste it to your web page
Copy embed code
Works Best for me.
Goto MS View Office Documents Online Page
Enter link to PPT file
Note: This link should be publicly Accessible
Click on Create URL.
Link to view office documents online will be generated.
Paste this link to any webpage or as iframe src attribute.
You are all set!! :)
If you are using Google slides you could easily publish it on the web and also embed the slide in an iframe.
Go to google slides -> file-> sharing -> embed and copy the code
and then in your HTML file use the below code to show slides in fullscreen mode.
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/journey.css">
</head>
<body>
<!-- show slides in html web page -->
<iframe src="https://docs.google.com/presentation/d/e/2PAxxxxxCX-xxxxxxxx-_GuZImZqRUxxxxxxxxxx/embed?start=true&loop=false&delayms=3000" frameborder="0" width="1440" height="839" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
</body>
</html>
why not use prezi, I just use it in my work, very easy and useful.
I was able to do this by saving the PPT as an mp4 (Save As > MPEG-4 Video (*.mp4)) and then using the video tag.
<video controls autoplay preload="none" style="width:1000px;">
<source src="/_dev/power_point/m11983.mp4" type="video/mp4" />
<p>Your browser does not support HTML5 Video.</p>
</video>

Display PDF within web browser

How can I display a pdf within a web browser on an .html page?
I use Google Docs embeddable PDF viewer. The docs don't have to be uploaded to Google Docs, but they do have to be available 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>
instead of using iframe and depending on the third party`think about using flexpaper, or pdf.js.
I used PDF.js, it works fine for me. Here is the demo.
preffered using the object tag
<object data='http://website.com/nameoffolder/documentname.pdf#toolbar=1'
type='application/pdf'
width='100%'
height='700px'>
note that you can change the width and height to any value you please visit
http://www.w3schools.com/tags/tag_object.asp
The simplest way is to create an iframe and set the source to the URL of the PDF.
(ducks mad HTML designers) Done it myself, works fine, cross browser (crawls into bunker).
The browser's plugin controls those settings, so you can't force it. However, you can do a simple <a href="whatver.pdf"> instead of <a href="whatever.pdf" target="_blank">.
As long as you host the PDF the target attribute is the way to go. In other words, for relative files, using the target attribute with _blank value will work just fine.
<e>
<a target="_blank" alt="StackExchange Handbook" title="StackExchange Handbook"
href="pdfs/StackExchange_Handbook.pdf">StackExchange Handbook</a>
For absolute paths engines will go to the Unified Resource Locator and open it their. So, suppress the target attribute.
<e>
<a alt="StackExchange Handbook" title="StackExchange Handbook"
href="protocol://url/StackExchange_Handbook.pdf">StackExchange Handbook</a>
Browsers will make a rely good job in both cases.
I did a careful evaluation of providers on this space:
free solutions
iframe: Just use an iframe, however, this is not what most people search here.
Pdf.js is the open source solution without external dependencies
Adobe offers a 'free' PDF Embed API
Commercial Providers
Pdf.js Express is commercialized extension to Pdf.js
PSPDFKit - Provder from Austria with rather good business support
Foxit - Chinese company providing a PDF web solton as well.enter link description here
PDFTron - US-based competitor to PSDPDFkit - more costly but also mot advanced.
Hope this helps. I might publish more detailed information in a blogpost, if this is helping people (let me know in comments).
You can also embed using JavaScript through a third-party solution like PDFObject.
You can use this code:
<embed src="http://domain.com/your_pdf.pdf" width="600" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html">
Or use Google Docs embeddable PDF viewer:
<iframe src="http://docs.google.com/gview?url=http://domain.com/your_pdf.pdf&embedded=true"
style="width:600px; height:500px;" frameborder="0"></iframe>
If you don't want to use some third party, you can use the <embed> tag with the source of the file in the src attribute. This uses the native browser PDF viewer, and offers more browser support than the object tag.
<embed src="your_pdf_src" style="position:absolute; left: 0; top: 0;" width="100%" height="100%" type="application/pdf">
Live example:
<embed src="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" style="position:absolute; left: 0; top: 0;" width="100%" height="100%" type="application/pdf">
Loading the PDF inside a snippet won't work, since the frame into which the plugin is loading is sandboxed.
Tested in Chrome and Firefox. See it in action.
Update - Adobe PDF Embed API
Adobe released their Adobe PDF Embed API which is completely free. Since they created the PDF format itself, their API is probably the best for this.
It delivers the highest quality PDF rendering available.
You can fully customize user experience and choose how to display a PDF.
You will also have analytics on PDF usage so you can understand how users interact with PDFs, including time spent on a page and searches.
All you have to do is create an api_key and use it in the code snippet.
Displaying PDF as buffer
Here is the example of the code snippet that you can just add to your HTML and take advantage of their API for displaying PDF if you have the buffer (local file for example). You would have to add { promise: <FILE_PROMISE> } config.
<div id="adobe-dc-view"></div>
<script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
<script type="text/javascript">
document.addEventListener("adobe_dc_view_sdk.ready", function(){
var adobeDCView = new AdobeDC.View({clientId: "api_key", divId: "adobe-dc-view"});
adobeDCView.previewFile({
content: { promise: <FILE_PROMISE> }
metaData: { fileName: "file_name_to_display" }
}, {});
});
</script>
Displaying PDF by file_url
Here is the example of the code snippet that you can just add to your HTML and take advantage of their API for displaying PDF by file_url. You would have to add { location: { url: "url_of_the_pdf" } } config.
<div id="adobe-dc-view"></div>
<script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
<script type="text/javascript">
document.addEventListener("adobe_dc_view_sdk.ready", function(){
var adobeDCView = new AdobeDC.View({clientId: "api_key", divId: "adobe-dc-view"});
adobeDCView.previewFile({
content: { location: { url: "url_of_the_pdf" } },
metaData: { fileName: "file_name_to_display" }
}, {});
});
</script>
The simple solution is to put it in an iframe and hope that the user has a plug-in that supports it.
(I don't, the Acrobat plugin has been such a resource hog and source of instability that I make a point to remove it from any browser that it touches).
The complicated, but relative popular solution is to display it in a flash applet.
You can also have this simple GoogleDoc approach.
<a style="color: green;" href="http://docs.google.com/gview?url=http://domain//docs/<?php echo $row['docname'] ;?>" target="_blank">View</a>
This would create a new page for you to view the doc without distorting your flow.
By far the simplest method to avoid cross site and or server load Issues is include the cover icons in the page and provide a DownLink. It is minimal demand rendering a page of several covers / icons. The second best method is show a single iFrame with your adjoining commentary.
However many modern browser users a weary of exploits may have turned PDF display OFF and blocked any attempts to pop-up or window.open inline runnable embedment objects like SWF or PDF.
Note the snippet is a small icon but you can use larger front cover like Amazon Books (within the browser datauri limits)
<center>
<h4>Click on the below icon to download pdf file :<br>If blocked by Security Refresh to show Cover and Right Click to Download</h5>
<a href="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAABBVBMVEUAAABTwd7O7PUAAAC35PEAAAAAAABTwd5Twd5Swd5Twd5Swd5RwN7A6POw4fBUwd5Xwt9bxOCS1+pTwd5Vwt9Wwt9dxeCC0ecAAABXw99bxOBcxOAAAABUwd4AAABWwt8AAABkx+Juy+MAAABUwd5Uwd5Vwt9Wwt9Yw99gxuFryeJoyeN/0OeZ2utXwt9Wwt9Wwt9bxOBWwt9Yw99gxuEAAABNv91Uwd5Uwd5Vwd5Yw98AAABaw+BbxOBYxOAAAAByzeVVwt9Vwt9Zw+BfxeBKvt1oyeIAAAAAAABVwt9Yw98AAABTwd5bxOBaxOBpyOKC0eYAAACN1emD0OZUwd5RwN4AAADkCLpdAAAAVHRSTlMA/QK/BICP+fby7fv4CgbjjlAK58KhPg7PgF5JQMevnmAiFxDf0r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cXTqQcHvhD1hCyhNB9S3JitB6ZpxKifBkTZ3UkbcxCXvarzMv1LoPlypR9FeMjT1wL8JPNGBZlGSdiP0FJJlJr2azfJJLr4ZsOvYuQ9Mkk7NP3CxDIjbJoXSe5zN3CFmVf+BZjuTl3q3yHH9JE+M4tOJZEpHZFZuJcV/vkNinB/QuT76Z9NCFxNDjA8fzHHnyLJqlh4/8d4UhLjmccXn+kaeFDdkkHUPpTIZ/zAxZsjiZRvkZN0T/l30D1xyHzxgRNCEAAAAASUVORK5CYII=" alt="react">
<br><b> Download Dummy.pdf</b></a>
I recently needed to provide a more mobile-friendly, responsive version of a .pdf document, because narrow phone screens required scrolling right and left a lot. To allow just vertical scrolling and avoid horizontal scrolling, the following steps worked for me:
Open the .pdf in Chrome browser
Click Open with Google Docs
Click File > Download > Web Page
Click on the downloaded document to unzip it
Click on the unzipped HTML document to open it in Chrome browser
Press fn F12 to open Chrome Dev Tools
Paste copy(document.documentElement.outerHTML.replace(/padding:72pt 72pt 72pt 72pt;/, '').replace(/margin-right:.*?pt/g, '')) into the Console, and press Enter to copy the tweaked document to the clipboard
Open a text editor (e.g., Notepad), or in my case VSCode, paste, and save with a .html extension.
The result looked good and was usable in both desktop and mobile environments.
[this is a very old answer, from when other options mentioned now didn't exist]
Back in 2011, we used to render the PDF file pages as PNG files on the server using JPedal (a java library). That, combined with some javascript, gave us high control over visualization and navigation.
Displaying content saved in PDF/DOC/DOCX file format is ideal for displaying the pdf/doc/docx file on your web page
Have you tried using a simple img tag?
<img scr="https://www.typomania.co.uk/pdfs/lipsum.pdf">