|
Rank: Newbie Groups: Member
Joined: 5/4/2012 Posts: 3
|
Hi,
After the export to pdf, i would like to close the current window and can anyone teach me how to do this? Where should i put my code? i tried to place the code in "AfterRender" event, but it cant work.
My code is as follow:
Protected Sub ASPXToPDF1_AfterRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ASPXToPDF1.AfterRender Dim ReturnVal As String = ""
Dim result As HtmlToPdfResult = CType(ASPXToPDF1.Result, HtmlToPdfResult)
result.PdfDocument.Save(Server.MapPath("\") & "abc.PDF")
ClientScript.RegisterStartupScript(Page.GetType(), "Close", "<script language='javascript'>alert('testing');window.returnValue = 'Done';self.close();</script>") End Sub
Thanks.
Cheers, Berk
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
Your code to save PDF file is correct.
Closing window is a bit tricky. First you must call RenderAsPDF(false) to instruct ASPXToPDF NOT to send the output the client (so that your page’s HTML, not PDF will be sent to the client). Note the added “false” argument when you call RenderAsPDF.
Second you must call RegisterClientScript earlier in your page’s life cycle. AfterRender occurs at the very late stage of the page’s life cycle so RegisterClientScript has no effect at that point. For example, you can call RegisterClientScript right after you call RenderAsPDF. The HTML to PDF converter will see the script you registered as well, however it has special handling for window.alert and window.close. So you do not need to worry about those code would mess up the HTML to PDF converter.
Hope this helps. Please let us know if that resolves the issue for you.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 5/4/2012 Posts: 3
|
Hi,
It works fine now. Thanks.
One more question, i would like to get the return value from that page to the parent page to determine whether the conversion is successful or not. I open the conversion page in Modal Dialog by using "showModalDialog" but i can't get the return value. Do you have any idea on this? Thanks in advance.
Cheers, Berk
|
|
Rank: Newbie Groups: Member
Joined: 5/4/2012 Posts: 3
|
Hi,
I got my solution. Thanks for your help.
Cheers, Berk
|
|