Google Document Viewer external URL - pdf

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.

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.

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.

Download dynamic generated pdf from dynamic url which is being viewed in webbrowser control in adobe viewer in 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")

Can I set the "HTML" Title of a PDF file served by my Apache Web server

I have HTML pages that contain <a> tags with hrefs that point to PDF files. My Apache Web server serves them just fine, but the title, as shown in the Browser history, is of the file name. I would like to be able to set that title.
Perhaps there's a Header than can be set?
I don't want to write a script to serve the files as the server can handle Content-Encoding negotiation (e.g., for gzip), and do flow control, none of such do I want to re-create.
Here is an http header you can set.
Content-Disposition:inline; filename="*File name you want*";
I suspect the issue you are having is that the client browser is storing the file name in the history, which you cannot fix.
Last I checked, the title in the history came from the setting of the HTML page (not a header), so there should be no HTTP header field for the title.
I am no HTTP expert and do not know all the fields, but I do not remember there being a setting in any server that I have ever worked with to set the page's title (just the status code, protocol, etc.)
I created a PHP-Skript (e.g. download.php, filename doesn't matter) like this:
<?php
header("Content-Type: application/pdf");
header('Content-Disposition: inline; filename="'.addslashes($_REQUEST['title']).'"'); //filename doesn't set the browser title here, only when page is saved/downloaded
$content = file_get_contents($_REQUEST['filename']);
header('Content-Length: '.strlen($content));
echo $content;
In my setup (Windows 10; Apache 2.4.37; PHP 7.1.25) you can now do a request like this:
http://..../download.php/browser_title?filename=test.pdf
I tested this successfully in Chrome and Firefox.
Internet Explorer was not able to display a PDF-Document inline :-/.
Microsoft Edge also included the URL-Parameter in the title bar :-(.