How to make PDF in my server show instead of downloading - pdf

I uploaded a PDF File in my Web.
But the PDF file while accessed via a URL, is getting downloaded instead of showing it in the web browser.
How can I solve this issue ?

If you are generating PDF file from javascription then you should make sure you are representing your PDF file as datauri base 64 encoded data.
If your file is on server then make sure server headers sent back contains Content-Disposition: inline; filename='example.pdf' so it will tell to display inline rather than download it

Related

Force download itextsharp created anchor in PDF

I need to develop application which creates pdf files and serve them via http. PDF is created using iTextSharp. In my pdf files are lot of anchors navigating to images and videos stored on the same server f.e. http://192.168.10.10/video.mp4 .
Files are generated and trasmitted via http correctly, but when I click on those anchors in my pdf source files are opening in browser. I would like to force download them.
I read all itextsharp documentation and cannot find anything.
Is there some way to do that?

IE and Edge are ignoring application/octet-stream MIME Type

Recently I've created a subdomain for downloads and I want the browser to download files instead of viewing it. For this I've added the following line into the .htaccess file:
AddType application/octet-stream .txt .png .jpg .jpeg .gif .exe .zip .rar .gz .sh .bat .doc .docx
On Firefox and Google Chrome it works but both Microsoft browser - Internet Explorer and Microsoft Edge are ignoring the MIME-Type and viewing them instead. How I also can force them to also download the files?
I can see that you had added all the file types in single line. So you can try to add them in separate line to check whether it solves your issue or not.
Based on my search, I find that IE can work with code below. So you can also make a test with it.
# Force PDF Download instead of display
<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
## End Force PDF Download instead of display
Reference:
Forcing a file to download in a browser via htaccess
If you are using PHP than you can try to refer approach below.
PHP allows you to change the HTTP headers of files that you’re writing, so that you can force a file to be downloaded that normally the browser would load in the same window. This is perfect for files like PDFs, document files, images, and video that you want your customers to download rather than read online. Using PHP you can take advantage of the PHP built-in readfile function:
$file_url = 'http://www.example.com/file.pdf';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url);
exit();
Reference:
(1) Force Files to Download and Not Open in Browser Using Apache or PHP
(2) Force save files all browsers - not open in browser window

Cannot open pdf file in browser using fpdf

I am new to fpdf. In my application, if a user clicks on a link, then I create a pdf file and the file gets downloaded. But I wanted the file to be opened in the browser. Here is my code
$fpdf->Output("Circular.pdf", "I");
But the code isn't working. The browser is showing garbage. I don't know what I am doing wrong. In the attached image you can see the output that I can see in the browser.
read up on the Content-Type header: https://www.rfc-editor.org/rfc/rfc2616#section-14.17

File is showing instead of download

When I download file, it is not downloaded and it shows in browser.
zip file is downloaded. this say server is working,
but when i try with ipa file(the extension of file is ipa), it shows content of file in browser instead of downloading.
I am using mamp.
Please help me
You may want to set a Content-Disposition header for this file - please see more information on MDN Content-Disposition. This way the server indicates that the file is an attachment and should be saved on the disk.
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"
The filename parameter is not mandatory. However, it'll suggest the name of the file.
On the other hand, if you have a HTML5 page with an anchor tag you may want to use download attribute, e.g.:
<a href="filename.jpg" download="filename.jpg">
The problem with download attribute is - it's not supported by all of the major browsers - see download attribute support. There is still a lack of support from the IE, iOS and Opera mini.

open pdf file through URL using uid

I work with alfresco 4.2
I want to get an image from alfresco through URL using uid
I can get the result through this link
http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/98996554-212 f-4846-876a-89b40999901a/test.jpg
my problem is to do the same thing but for a pdf file
with chrome I can not open the file
and firefox the file is opened in binary format
is there a way to open a pdf file through URL using the uid of alfresco file
I'd try using the download servlet. I believe the url you are using is not setting the mimetype headers correctly. This url should do the trick:
/alfresco/download/direct/workspace/SpacesStore/0000-0000-0000-0000/myfile.pdf
Possible reason could be mimetype of your pdf file is not correctly set. Normally browsers have addons avilable out of box which enable them to read pdf file correctly.
https://helpx.adobe.com/acrobat/using/display-pdf-in-browser.html
Those appliation are associated with perticular file types so whenever it detects that file type browser invoke that application to deal with it. So you can make sure your file's extension and mimetype are correct.
One more thing you can try is download that file and try to open it directly in browser.
Also, there are chances file may be corrupt. Are you able to see prview of pdf in alfresco?