views:

1418

answers:

2

I want to generate a PDF file on server side, and then in response want to send that file (buffer,fileName- whatever may work) and show a print dialog to ask user to print the generated PDF file.

I tried something like below. But it does not trigger window.print() dialog.

   public static void ForcedPrint(HttpResponse response, byte[] buffer, string fileName, string fileExtension) {
      response.Clear();
      response.Buffer=true;
      response.Write("<script>window.print();</script>");
      response.Charset="";
      response.Cache.SetCacheability(HttpCacheability.NoCache);
      response.ContentType="application/pdf";
      response.BinaryWrite(buffer);
      response.Flush();
      response.End();
    }

Can someone please help me with this? The feature i am looking for is that i should be able to create PDF file on server, and in response user should get a dialog to print the generated file.

Thanks in advance.

+1  A: 

As far as I'm aware you cannot generate a print command to the browser on the server. The most you can do is generate the javascript which will make it pop up with a print dialog (window.print()) but that wouldnt help you with what you're trying to do.

Just speculating but you may try generating a page with an iframe that points to the PDF file, and in the base page have the javascript that tells the iframe to print?

Hope this helps,

Darko

Darko Z
A: 

You need to embed the PDF in the HTML document, say in a div called thePDF and in JavaScript code in the document, you need to invoke

thePDF.printWithDialog()

The dialog that appears will be the Adobe Reader plugin's print dialog rather than the browser's print dialog; this will allow selection of pages etc. before printing.

Vinay Sajip
I didn;t get this. can you please show me some sample code, or some link for reference.Thanks for the reply.
Amby
Just Google for `printWithDialog`, and you should find some useful information from the search results.
Vinay Sajip