Ajax Le Guide Complete Pdf Printer

  

AJAX Tutorial in PDF - Learn AJAX in simple and easy steps starting from basic to advanced concepts with examples including What is AJAX?, Overview, Technologies, Examples, Browser Support, Action, XMLHttpRequest, Response, ActiveXObject, Msxml2.XMLHTTP, Microsoft.XMLHTTP, Database Support, DOM Manipulation.

  1. Mortal Kombat X Krypt Guide Complete
  2. Topps Baseball Card Price Guide Complete Sets
Active6 years, 7 months ago
Guide

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?

Ajax Le Guide Complete Pdf Printer

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?

hsuk
5,12211 gold badges43 silver badges76 bronze badges
LoupaxLoupax
2,4094 gold badges32 silver badges57 bronze badges

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.

WolfWolf
2,0241 gold badge12 silver badges10 bronze badges

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.

VinayCVinayC

Mortal Kombat X Krypt Guide Complete

35.7k5 gold badges46 silver badges60 bronze badges
Iphone

Topps Baseball Card Price Guide Complete Sets

Not the answer you're looking for? Browse other questions tagged javascript or ask your own question.