embed PDF not working in Android Chrome - plugin not supported - html

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

Related

Preview pdf in iframe do not download

I have a basic html code to preview some pdf
<iframe src="file.pdf" />
But from time to time, should depend on the user browser config the file is downloaded and nothing is displayed in the preview. Is there any way to force the preview ?
I also tried
<object data="file.pdf" type="application/pdf">
<embed src="file.pdf" type="application/pdf" />
</object>
But not compatible on all browser
This is the older way of doing it. Now these methods have started to be deprecated.
Few methods by which you can implement this is:
Google Docs Embed
You can upload the file on google docs and get the embed link from the share option and embed it into the site using iframe.
Pdf.js
This is a library in javascript that helps in dealing with pdf files.

Embed PDF in mobile browsers

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!

How to embed a Powerpoint in html with some constraints listed inside

I am trying to embed a company PowerPoint presentation into an intranet website and am having some issues. I tried converting to pdf and embedding it with this html:
<object data="myFile.pdf" type="application/pdf" width='100%' height="8000px">
<p>It appears you don't have a PDF plugin for this browser.You can <a href="myFile.pdf">click here to
download the PDF file.</a></p>
</object>
but there is a link in the ppt that stops linking correctly somehow. So I tried converting to an htm page and doing a javascript redirect to that page but I get a page that just says my browser doesnt have the correct plugin to open the pdf.
And unfortunately, being a company project, we aren't allowed to use commercially available cloud storage (ie: Google Docs, Onedrive, etc.) for security and privacy purposes. Are there other ways to embed the powerpoint, not using 3rd party software?

Change background color in PDF viewer using either embed, object or iframe methods

I've been playing around with different methods of displaying PDFs with the goal of finding a way of changing the grey background to white.
Here is a simple example using object tags (I get the same result with embed and iframe tags):
http://jsfiddle.net/5CALy/7/
HTML
<object data='https://dl.dropboxusercontent.com/u/58922976/test.pdf#view=FitH&scrollbar=0&toolbar=0&statusbar=0&messages=0&navpanes=0'
type='application/pdf'
width='84%'
height='110px'>
<p>It appears your Web browser is not configured to display PDF files.
No worries, just <a href='https://dl.dropboxusercontent.com/u/58922976/test.pdf'>click here to download the PDF file.</a></p>
</object>
Thanks!!
The OP Link actually now succeeds by default, here is the view of requesting no pdf where response is with image on white background
https://dl.dropboxusercontent.com/u/58922976/test.pdf
However it is normal to use a dark or light presentation background for images PowerPoints pdf other viewing
It is entirely up to the viewer
This browser only opens files in external mode
Or why not rainbow friendly?
But for the answer, ask users to do it themselves
For Firefox users there is a hack see How can I enable dark mode when viewing a pdf file in firefox https://stackoverflow.com/a/74564207/10802527
You can but cannot!
I mean,
Every browser (Chrome, Edge, Firefox, Safari, etc.) use their own PDF engine for displaying embedded PDF Files. You can use JavaScript or jQuery to detect the element which has the grey color and change it to white but you'll have to do this for every browser available in the market which is nearly impossible. Moreover, Web Browsers do not provide you an API for this.
The only better solution for this is to make your own PDF Viewer:
You can use this https://mozilla.github.io/pdf.js/ opensource package (By Mozilla) to get it done.
Welcome!

How to embed a PDF?

I am trying to embed a PDF in an HTML document, but this seems to work only with Chrome. Other browsers appear to either require plugins or require a user to click a link which is not what I want. Here is what I have tried:
<object data="pdfFiles/interfaces.pdf" type="application/pdf">
<embed src=" pdfFiles/interfaces.pdf" type="application/pdf"> </embed>
alt :<a href="pdfFiles/interfaces.pdf">
</object>
Here is the code you can use for every browser:
<embed src="pdfFiles/interfaces.pdf" width="600" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html">
Tested on firefox and chrome
<iframe src="http://docs.google.com/gview?url=http://example.com/pdf.pdf&embedded=true"
style="width:600px; height:500px;" frameborder="0"></iframe>
Google docs allows you to embed PDFs, Microsoft Office Docs, and other applications by just linking to their services with an iframe. Its user-friendly, versatile, and attractive.
This works perfectly and this is official html5.
<object data="https://link-to-pdf"></object>
do you know about http://mozilla.github.io/pdf.js/ it is a project by mozila to render pdf inside of your html using canvas. it is super simple to use.
I recommend using PDFObject for PDF plugin detection.
This will only allow you to display alternate content if the user's browser isn't capable of displaying the PDF directly though. For example, the PDF will display fine in Chrome for most users, but they will need a plugin like Adobe Reader installed if they're using Firefox or Internet Explorer.
At least PDFObject will allow you to display a message with a link to download Adobe Reader and/or the PDF file itself if their browser doesn't already have a PDF plugin installed.
FlexPaper is probably still the best viewer out there to be used for this kind of stuff. It has a traditional viewer and a more turn page / flip book style viewer both in flash and html5
http://flexpaper.devaldi.com