views:

328

answers:

2

Hi,

Is there a way to close a pop up window after the page writes binary data (PDF) to the browswer?

Here are the details:

Whenever my web appilcation needs to print, it will pass some parameters over to a pop up window, which will display the print options. When the user clicks on the Print button, it will set the src of a iframe that will call the page that does the printing.

I have PDFConverter to convert URL / HTML to a pdf file. At the end of the converting, it will write the binary to the browser. Here are some code:

response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition",
"inline; filename=" + fileName + ".pdf; size=" + pdfBytes.Length.ToString());
response.Flush();
response.BinaryWrite(pdfBytes);
response.Flush();

After this is done, i will need to close the pop up window. However it seems like you can't do anything after the response is flushed. Any ideas?

Thanks in advanced!

Angela

A: 

Instead of creating the iframe in the popup window, you could create it in the parent window. This way once the user clicks the print button, you could safely close the popup without interupting the printing process. But instead of going through all the pain of creating new popups windows which might be blocked by some browsers, I would simply create some placeholder in the main page so that the user could choose printing options and then print the document.

Darin Dimitrov
i think that would work. However, i want to show the list of print options. so there's a 3 step process. 1. The user clicks on something on the parent page to print. 2. A pop up shows the list of print options. 3. Print and close the pop up.
Angela
There are nice plugins for jQuery that allow you to simulate popups by showing modal dialogs (http://docs.jquery.com/UI/Dialog).
Darin Dimitrov
Yes, i have tried the jquery modal dialogs. however i cannot close the dialog after the pdf is generated.
Angela
A: 

Just in case anyone else is having the same problem. This is the solution that seems to work for me.

I use the juqery Simple Modal to show my option list page. On this page, i have a window timer running every 1 second to check against the server if the print job is done. I use ajax for that. Once the job is done, i update the session variable, and the ajax call to the server will pick up the session value and close the pop up window.

Angela