Download dynamic generated pdf from dynamic url which is being viewed in webbrowser control in adobe viewer in vb.net - vb.net

I am developing a windows application in vb.net in which i have a url which first ask me to login on the website and then display a view pdf link. As i make it click it again redirect to another page where instead of asking for download pdf it opens it in my web browser control. Now i want to save that opened pdf on my specified path. I have googled a lot but didn't find any solution for the same. I even found some related posts but none of them have my answer. Here my pdf url doesnt contains any file name like '.pdf'. Url contains some token values. To open this url it requires login on the website. I am trying to download pdf file for many days. Please help me.

you have to push your file using http headers
Unique HTTP Headers Returned
because these headers are the only thing controlling how your browser handles the file.
Save As Mode (askapache_pdf=s)
Content-Disposition: attachment
Content-Type: application/pdf
for more info goto http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html#Unique_HTTP_Headers_Returned

This does not have anything to do with server side scripting language its same that you have to add a response in your header of http request. But anyway in ASP you should try something like below
Response.AddHeader("content-disposition", "attachment;filename=somefile.ext")

Related

Pdf shows grey screen at first but loads the content after refresh in IE11

I am generating pdf using XSLT.Facing two issues:
1) Opened one pdf and closed and tried to open another pdf shows the same old pdf content: Looked for a solution and implemented this:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setHeader("Expires", "0"); // Proxies.
But this solution is creating another problem now,now the pdf shows grey screen at first and after a refresh it loads the page.
Any suggestions how to solve this? Thanks In Advance
The first time when it shows grey screen,i saw in developer tools that
it shows In progress ,thus the pdf is not loaded and after a refresh
it shows status OK
Perhaps the pdf file is a little big, and needs some time to load, so, we could wait the pdf file load success, then it will display in the Browser.
Besides, you could also try to clear the browser data (such as cache, cookie and history) to improve the browser performance.
I faced a similar issue when creating a PDF file on the server and redirecting the browser straight to its URL. What seems to have fixed it was, instead of redirecting from the backend, writing
<meta http-equiv="refresh" content="0; url=http://www.pdf995.com/samples/pdf.pdf" />
to my response (substitute the URL of your PDF file). That way, it is the browser that redirects itself after the response has been completed and received.
More info here.

Sense/Net download text file

When I try to download the text file in sensenet, the text file will open in browser but not downloaded, could you give some suggestions about how to set to download text file directly?
It's handled by the browser. If it can open a certain file type, then it will show it instead of downloading.
On server side you can force to download file types on your website if your http handler use disposition when set response stream:
response.AppendHeader("Content-Disposition", "attachment");
With sensenet you have to write your own http handler or modify ProcessRequest of SenseNetStaticFileHandler.cs.
MSDN is not too helpful on this topic, but you can find some information on this here.
On client side there is another solution, if you can change the html code of the link. With html5 <a> tag has got a download attribute that forces the linked file to download instead of navigate the browser to it. It works if the browser supports it. See HTML download Attribute.

Google Document Viewer external URL

Is there a way to supply Google Docs Viewer with a source from a proxy download? Such as from https://www.url.com/download.php?file=fdg46fgd (random download code).
The download script headers look like this:
header("Content-Type: " . $mime);
header("Content-Disposition: attachment; filename=\"$name\"");
header("Content-Length: " . $size);
header("Cache-Control: private");
It prints the contents after the headers are established. This works fine when you enter the link into the browser and works as expected. I have also tried using inline instead of attachment but the Google Doc Viewer always displays "No Preview Available". The document viewer code looks like this:
<iframe src="https://docs.google.com/gview?url=https://www.url.com/download.php?file=fdg46fgd&embedded=true" style="width:800px; height:700px;" frameborder="0"></iframe>
I have tried using different documents such as pdfs, docx, etc.
If I use a direct link it will display properly, but not when using the download script. I have seen people using a download script based URL before and it seemed to work for them. Does this not work with Google Doc Viewer anymore? Any suggestions? Any help appreciated, thanks!
Because the process in your download URL have validation (ex: check login, limit user, ...).
Remove this validation code, Google Doc Viewer can be open file you want.

How to serve a pdf file from ember

I want to make a pdf document available via a link from my ember app, so I figured I would put the file in /public/assets/pdf/ and link to it as
<a href='/assets/pdf/myfile.pdf'> just as I would for an image in public/assets/images. However the link isn't sending the file to the browser. I get a 200 response with a Content-Type: application/pdf header, but no file.
What's the right way to do this?
The way you described should work as there's nothing special about the way Ember handles static asset downloads. To verify, I just initialized a new project using Ember 2.3 and placed a pdf in /assets/test.pdf. I then placed the following into my application.hbs file.
<a href='/assets/test.pdf' download>Test</a>
Without the download attribute it opened as a new tab. With the download attribute the file was downloaded like normal.

Error 404 for file download without browser redirection?

on a website I display links to PDF files.
When the first time call for a file arrives, the request gets redirected to a php-script that generates and returns the file. Additionally, it saves the file to the linked location so next time it will be directly availibe. I send the pdf mime type to make the browser open a download dialog instead of redirecting.
Due to reasony beyond my control, one out of 20 files cannot be generated.
How to respond?
Error 404 or 500 would direct the browser to an error page, while sending a mime-type would let the user download an empty / defect pdf file. Is there an established best practise? How to let the user know that a file link is broken, yet keep him on the site without redirect?
I had the same problem and solved it as follows:
If you have link to file, for example:
<a download href="/files/document.pdf">Click to download</a>
And if you don't want the browser redirect to blank/error page if the file doesn't exist, just reply with 204 without any content.
Nothing will happen, the user will stay where he is without redirection.
In php it would look something like this:
if (!readfile("/files/document.pdf") {
http_response_code(204);
die();
}