How can i give link to download(not open) pdf file in reactjs - node.js

this is my code which i am writing in render method, which works fine, but instead of downloading this file it's opening in browser.
download
How can i give a link in react to force download a file, file which is coming from external server.

HTML5
<a download href="file.pdf">Download PDF</a>

Suppose you have a variable names as "link" in which the link is stored. So you can do,
<a href={`${link}`} type="application/pdf; download='some_pdf_name'>Download</a>

Related

href pdf file url is not found when click on it

I'm working on the vuejs application and, I'm receiving the pdf file from node backend which has the eg url https:abc.com/api/filename.pdf.
I'm using it link so
const myUrlVariable='https://someurl.com/dataCollection/imperial'
<a :href="myUrlVariable" target="_blank"></a>
The requirement of this is to when user click on link, file should open in the new tab.
But Right now when I click on the link its considering it as application route and show the message page not found, instead it show the pdf file.
I check this link in the postman and its returning the file as expected.
href should not be a string, but a binding to a variable
Change this
to this
<a :href="myUrlVariable" target="_blank"></a>
👆
Is the url correct?
https:abc... -> https://abc...

Firefox OS - Launch external link inside Firefox OS app and retrieve its content

I have a Firefox OS app in which I have opened an web page via mozbrowser attribute.
<iframe id="inlineFrameExample"
mozbrowser=true
src="<some external link>"
</iframe>
How can we retrieve DOM content of the iframe?
You can retrieve DOM content via executeScript() method present in Browser API. It will run the script against the iframe and will allow you to do DOM computation tasks.
Note: The example mentioned in the document didn't worked but the syntax given below worked for me. The diff is is passed as string.
iframe.executeScript('put_your_script_here', {origin: 'domain_name'});

NodeJS Get Completely Rendered HTML Page

I want to get a html page content from a url using NodeJS after JavaScript is fully loaded and the page is completely rendered, or get the basic html then run all JavaScript files to achieve final content.
For example let's assume there is a website based on AngularJS, so the basic html is simple, but after loading all JavaScript codes in the page, page content is completely different. I want to get that final content on my server to find something in it. Any ideas?
After-Load is a NodeJS package that works like a charm :
var afterLoad=require('after-load');
then :
afterLoad('http://stackoverflow.com/questions/29366718',function(html){
console.log(html.indexOf('charm')>0);
//true
})
Maybe it's too late, but back in the day, PhantomJS solved my problem.

Google docs viewer not working

Using this code:
<iframe height="780" src="http://docs.google.com/viewer?url=http://ruh.kz/sites/default/files/doc/ritorika.pdf&embedded=true" style="border: none;" width="600"></iframe>
But all the time im getting this annoying message:
Sorry, we are unable to retrieve the document for viewing or you don't have permission to view the document.
By the way, i have read about ISP might block google docs. But i've checked another sites with google docs viewer and they seemed to work perfectly.
to embed your pdf without putting it in your server , just login to your gmail and upload it in google docs then copy the link and put it in your iframe's src
first you try with online version to view your file if it shows your file,you gave wrong url to iframe,if viewer does not show your file at embedded version and online version check your file size,file url and file permissions to viewer can reach your document.You can try your url, for example http://www.foo.com/bar.pdf paste in your browser,if url is right browser shows the file...

Download link page JSF

How can I produce a URL which somebody could open and that would immediately download a file e.g. pdf?
I have been using ice:outputResource but that requires the user clicks on a link. Is it possible to do this in JSF?
Thanks,
Dwayne
You want to download a PDF file immediately when one opens a page? Use Javascript to fire the request on the PDF file during page load.
<script>
window.onload = function() {
window.location = 'http://example.com/context/path/to/file.pdf';
}
</script>
Update: your question is actually ambiguous. From other point of view, are you asking how to return a PDF file on a GET request? If so: if it's a static PDF file, then just put the PDF somewhere in the webcontent and link to it. Or if it's to be dynamically generated or served from a database or local disk file system outside the webapp, then create a servlet which does the job. Example here.

Resources