I am trying to view the pdf file created using mpdf.
On using the command as
$pdf = $mpdf->Output('mep.pdf','I');
the pdf gets downloaded rather.
Although, I: send the file inline to the browser. The plug-in is used if available. The name given by filename is used when one selects the "Save as" option on the link generating the PDF.
I would like to view the pdf in the browser and depending on the user choice to download it, print it or just view it and exit.
Kindly help. Thanks.
It depends on the browser whether it can and will display PDF files inline. But to help it a little you should at least tell the browser that it's a PDF file. You can do this by sending a content-type header:
header('Content-Type: application/pdf');
This line should be executed before sending the PDF contents.
You can use this. May be it will help you.
include file:
include_once './mpdf/mpdf.php';
create object of mpdf:
$pdf =new mPDF("","A4","","",10,10,10,10,6,3);
$mpdf->WriteHTML('Text which you want in PDF file');
$pdf->Output('filename.pdf','I');
Still not able to view file:
define content type of header
header('Content-Type: application/pdf',charset=utf-8');
Related
I have a blog in Jekyll and on one of the pages I have two links: one is to a .tex file and the other is to a .pdf file. When the link to the PDF file is clicked, the browser displays the PDF, no problem. However, when the link to the TeX file is clicked, the browser downloads the TeX file.
Is there a way to get the browser to display the TeX file as just plain text? This is the behaviour on some other websites. I know this is related to the Content-Disposition response in HTTP but how to I set this in a regular Jekyll Markdown file?
Thanks in advance for your help!
After uploading a PDF to the Media Archive, I am trying to link to it from a page on a site.
While editing content, I use the hyperlink tool then select the PDF I want to link to via the URL input box.
After saving and publishing the content, clicking the link downloads the PDF and I don't see any apparent way to make this view-able in the browser by using the current Media ID Composite provides. When rendered, we get this:
pdf
Is there a way that I can reference a PDF without using the Media ID and simply use the file name instead?
Here is the Request/Response header info:
After reading what Pauli Østerø said, I understand the problem but am still not able to think of a solution.
I can get the PDF to view in the browser by adding ?download=false to the href URL via Developer Tools. But when I try to add ?download=false to the href through Composite, it doesn't take affect and I get the console output: "Resource interpreted as Document but transferred with MIME type application/pdf: "http://c1.wittenauers.com/media/4afb7bc8-f703-469d-a9b2-a524d8f93dcb/ryc7iw/CompositeDocumentation.PDF"."
Here is the network trace that was asked for by Pauli. In the image, I included the bit where I add ?download=false to the URL, in source view, just in case there could be another way to add it.
Edit: URL and headers for the page.
Here is the link to the page that contains the link:
http://c1.wittenauers.com/cafe/test
Here is the headers for the page containing the link:
From what you're experiencing, it seems to me that Composite have gotten the MIME type of your uploaded file wrong, and is therefor not correctly telling the browser that this file is a pdf, and the browser doesn't know what to do with it.
Try deleting the file and uploading it again.
Try add ?download=false and the end of the href to the file. You prob. need to go into source mode of the content editor.
This is the exact line in the Source Code which is responsible for this behavior, and the logic is as follows
If there is no Querystring named download, the attachment is determined by the Mime Type. Only png, gif and jpeg will be shown inline, the rest will be shown as attachment.
If there is a Querystring named download with a value of false, it will override the Mime Type check and always force the Content-Disposition to be inline.
I made a quick test here to show that the behaviour is a expected. At least in my Chrome browser in Windows 8
Force download: https://www.dokument24.dk/media/9fdd29da-dde8-41f7-ba4c-1117059fdf06/z8srMQ/test/Prisblad%202015%20inkl%20moms.pdf
Show in browser: https://www.dokument24.dk/media/9fdd29da-dde8-41f7-ba4c-1117059fdf06/z8srMQ/test/Prisblad%202015%20inkl%20moms.pdf?download=false
Expanding on Pauli's answer, you can add the following snippet to your page template to automatically add the '?download=false' to all pdf links.
$("a").each(function () {
if (this.href.includes(".pdf")) {
this.href = this.href + "?download=false";
}
})
I have to display pdf file content from database to iframe of a page since I donot want to show any kind of url and file name. Even I do not want the pdf to be generated. I just want to show the pdf content on screen.
Please help me out for this.
if you do not want to generate the PDF where the content of the PDF will be stored? Will it be dumped in DB before?
You can output the PDF content by setting the content type as application/pdf. If the browser is capable of rendering, it will be displayed in browser itself or else it will be downloaded to their local machine.
I am using Karma commercial template. I have make the plugin for to upload document or any type of file, which will save in database and give option of Preview in front end. I have search many plugins for the same. I don't want to download the file but only wanted to preview the file in read only mode.Please help for the same.
I have used javascript code using javascrip plugin:
var documentViewer = $('#document-preview').documentViewer();
But it is not usefull for word file as it is useful for image, pdf and text file.
The Google Document Embedder plugin allows you to display files (PDF, Word, etc.) and has options that will prevent downloads.
http://wordpress.org/plugins/google-document-embedder/
I have a site that allows file uploads and saves them with a uuid filename on the server. When a user right clicks to "save as" and download the file the odd looking uuid filename is shown in the download dialog. Is there anyway possible to show the original filename (which is saved on upload)? I've seen several post like this one but can't seem to get it to work on FF 3.6 or Google Chrome (which I need to support)...
Any ideas?
PS: I'm working with javascript and a python back-end, if that helps...
You need to use a Content-Disposition header, set to attachment and supply a filename.
content-disposition: attachment; filename=myfilename.ext
I'd be more specific, but you did not indicate language or platform.
Update:
In python it would be
response.headers['Content-disposition'] = 'attachment; filename=filename.ext'