Opening a local pdf file in iframe with javascript - javascript

I am using the below code to open a pdf file but its not working-
<iframe src="file:///C:\Users\Downloads\0895custbill08132015.pdf" style="height: 638px;" frameborder="0"></iframe>
For a google doc the below code is working fine, I am not sure what is required to open a locally saved doc.
<iframe src="http://docs.google.com/gview?url=http://webshire-aioopsss.com/pdfs/sample_contract.pdf&embedded=true" style="height:638px;" frameborder="0"></iframe>

Most browsers won't let you open a locally stored file from a website for security reasons. Typically I will host the file on an IIS server and then retrieve it from there (which is what you're doing when you're retrieving it from googledoc).

You are using backslashes in your src. Please change them to slashes
<iframe src="file:///C:/Users/Downloads/0895custbill08132015.pdf" style="height: 638px;" frameborder="0"></iframe>

You can use
var pdf = $('\<\object type="application/pdf">');
pdf.attr('data', "you pdf scr");
append it in your iframe..

Related

Iframe not displaying the PDF

I have a link when pasted it would display as PDF
But when I embed in iframe its not displaying and refusing to connect.
I have tried with
<iframe src="https://docs.google.com/presentation/d/1s5kA0DXmxUGZ7Ydjk3Aa-wu7xhKyInM3s7p19XUfaFU/export/pdf?id=1s5kA0DXmxUGZ7Ydjk3Aa-wu7xhKyInM3s7p19XUfaFU&pageid=g9fbb3c24c3_0_71&attachment=false" title="IFRAME">
</iframe>
I realized that, when ceratin URLS have a XFRAME as sameorigin they don't allow to embed via iframe. Its evident here.
Make sure you have public access to view the pdf file. You can also use the Object tag to view pdf if the user has the pdf plugin installed. else it will display a Google doc file.
<object data="https://docs.google.com/viewerng/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true">
<iframe src="https://docs.google.com/viewerng/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" frameborder="0" height="100%" width="100%"></iframe>
</object>

How to view a pdf using iframe from my website?

I have pdf files on my website that I would like to show on a page , I tried :
<iframe src="https://mywebsite.com/files/file.pdf" frameborder="0" width="600" height="550" style="margin:0px; padding:0px;"></iframe>
but the file is downloaded.
I tried using google drive :
<iframe src="https://drive.google.com/viewerng/viewer?embedded=true&url=http://mywebsite.com/files/file.pdf" ></iframe>
But I get the html of my login page , I think it automatically redirects to login page.
and I tried to use iframe to access the folder that contains the file:
<iframe src="https://mywebsite.com/files" ></iframe>
But I get forbidden message that tells me to edit my file permissions .
-Is there is a specific permission that I could use to access the folder or the file?
-Is there is a library , function in any web developing language or anything that could help?

Display word/pdf file on web page

I have few files in doc/docx/pdf format stored on server's folder and their path are saved in database. I wish to fetch the path of these files from database and then display it on my website.
In the database the files are stored in this format
id path
1 abc/request/file1.docx
2 abc/request/file2.pdf
3 abc/request/file3.docx
To display the file i used the following method
$a = $data->path;
$b = 'http://example.com/';
$r = $b.$a;
<iframe src="http://docs.google.com/gview?url=<?php echo $r; ?>&embedded=true" style="width: 100%; height: 600px;" frameborder="0"></iframe>
Issue
Earlier the file was getting displayed but all of a sudden it is not getting displayed now
I did the following checks to see the validity of file
1) File is in proper format and is not corrupted and does exist on server folder
2) The console is not giving any errors
3) Tried to run http://docs.google.com/gview?url=http://example.com/abc/request/file1.docx on browser, there also the file is not getting displayed, however the other example url given on net are working
Can anyone please tell how to correct the error. And I would also appreciate if anyone could tell any other way(using jquery, javascript or any but reliable way) to display the files on website without disturbing the formatting of the original file
For PDF, you can use ViewerJS to render.
For doc/docx, consider using Microsoft Office Viewer as a walkaround if Google Docs Viewer is not stable enough to you
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http%3A%2F%2Fieee802%2Eorg%3A80%2Fsecmail%2FdocIZSEwEqHFr%2Edoc' width='100%' height='900px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>
P/S: Don't know why the code snippet is not working, but you can take a look here: https://jsfiddle.net/gcuzq343/
you can use
1. google docs viewer
<iframe src="http://docs.google.com/gview?url=http://example.com/my-document.doc&embedded=true"></iframe>
2. Microsoft viewer
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://example.com/my-document.doc.doc' width='800px' height='600px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>

How to upload PDF to google drive and embed them in a HTML static site?

I have a static HTML site. It's for a little food shop. They need to upload their menus and other every month. SO they need to upload PDF documents somehow. I think uploading to google drive is better. No ? It's easy than creating a seperate admin view to upload files and all.
so anyone can tell me how can I upload PDF in google drive and embed the link in my code ? There are eight menus and they need to show as thumbnails. When users click on them, they will download.
You need to share the pdf file to "Public on the web"
The go to file > embedded this pdf file. This will give you the html code.
Copy and paate it in your html code
Refer http://www.mybloggerlab.com/2013/03/how-to-embed-pdf-and-other-documents-in-blogger-posts.html
It is simple to upload a PDF in Google Drive and embed a direct download link into your code. I have inserted an excerpt from labnol.org
Google Drive doesn’t offer a simple option for creating these “direct download” link but you can easily create them by slightly modifying the generated URLs. Here’s the trick.
A file hosted on Google Drive has a shared link that looks like this
https://drive.google.com/file/d/FILE_ID/edit?usp=sharing
When you access this link, it will render the file in the browser but if you can rewrite this URL slightly, the link, when clicked, will download the corresponding file in the user’s browser instead of opening it in the browser. The modified URL would be:
https://drive.google.com/uc?export=download&id=FILE_ID
All you have to do is make note of the FILE_ID in the original URL and use it in the modified URL. For example, here’s an image file hosted on Google Drive that will open in the browser and here’s the modified URL that forces the browser to download the file.
Just do...this and enjoy
INSERT_YOUR_ID_HERE = your pdf file id
1st solution below
<iframe src="https://drive.google.com/file/d/**INSERT_YOUR_ID_HERE**/preview" height="100%" width="100%" frameBorder="2" scrolling="auto" ></iframe>
2nd solution
<embed
src="https://drive.google.com/file/d/**INSERT_YOUR_ID_HERE**/preview"
height="100%"
width="100%"
></embed>
enter image description here

How to removes a link from iframe

I hvae iframe code like this
<iframe id="iframe" align="left" style="background-color:#000000" src="//third party url" frameborder="0" height="85" width="300" scrolling="no">
Now it generates a link inside body.& i want to remove a link from that.
Any suggestions??
If the iframe src points to another server than yours, you cannot alter its HTML (the cross-domain restriction).
You can however hide the link by Javascript or CSS if you can control somehow the third party server (a method named JSONP).
You can't do that from the Javascript as it is from external site. Alternately you can do it from server side (either PHP/ASP.NET or others) using CURL or respective syntax to read the content and change before serving. It should work without any issues.

Categories