Ajax Le Guide Complete Pdf Printer
I'm having a form that once submitted, the PHP generates a PDF file and sends it to the client. Everything works fine so far. What I'm having trouble with is that I need to trigger window.print() on the window containing the received pdf. Is there a way to make the printing wizard appear for the received pdf file?
Allow only pdf, doc, docx format for file upload? Ask Question. Up vote 17 down vote favorite. I am triggering a file upload on href click. JQuery Ajax File. Quick Reference Guide. Select Complete or Custom Setup. Choose Custom to enable or disab le the integration of PDF Conver ter in other programs. The guide will contain code in. AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX RSS Reader AJAX Poll PHP Examples. At W3Schools you will find complete references of.
Here is the code I have
I'm not even sure if what I want to do is possible. Is is possible for example to open the PDF in a new tab and call window.print()
there?
2 Answers
One easy approach for this is to put the PDF file in a new iFrame.Then you can print the complete content inside the iframe using window.print();
function.
Now call window.print();
function when you want to print your pdf.
To open PDF in new window, you need to essentially generate an GET request (so that window can be open via URL) - one of the simple way is to code your server side code to accept the input parameters via query string. Better way is to use POST request (as you are currently doing) to generate the PDF at the server side and cache it in temp location, then return some token/ticket (e.g. it can be as simple as temp file name) to the browser. This token would be used in GET request to get the PDF file - GET request would go to server that would simply read the file off temp location and return it back as inline ((i.e. header content-disposition: inline;
). Then you may try window.print()
to print it. Similar ways can be used with iframe (with contentWindow.print()
).
However, you may find that these solutions may not work - for example, there is no PDF plugin to display the PDF inline (or user has chosen always open file externally). Or it may not work across browser. So yet another (and IMO better) way is to embed java-script within PDF it self to instruct for print as soon as the file is opened.
For example, see this PHP code example that would embed java-script in PDF generation for auto printing - the example is using FPDF for PDF generation.
Not the answer you're looking for? Browse other questions tagged javascript or ask your own question.
I am triggering a file upload on href click.
I am trying to block all extension except doc, docx and pdf.
I am not getting the correct alert value.
Javascript:
MyFiddle.its showing error
Lii8 Answers
Better to use change
event on input field.
Updated source:
Updated jsFiddle.
antyratantyratYou can use
whearat
application/pdf
means.pdf
application/msword
means.doc
application/vnd.openxmlformats-officedocument.wordprocessingml.document
means.docx
instead.
[EDIT] Be warned, .dot
might match too.
You can simply make it by REGEX:
Form:
And java script validation:
Cheers!
Download game zombie world hack hp nokia 205. For only acept files with extension doc and docx in the explorer window try this