Welcome Guest Search | Active Topics | Sign In | Register

Server-side print function after ASPXToPDF conversion Options
Tyler
Posted: Monday, July 15, 2013 12:06:29 PM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
I have several forms that are converted to PDF on submission using ASPXToPDF and after the final form is submitted I need to print the forms and then delete the forms from the directory. My issue is that I think the directory is deleted before the conversion finishes for that form so then it can't save the form because the directory doesn't exist. Is there some way to wait until the conversion is complete before code after is executed? Below is my code for the conversion and then the print function which deletes the folder with the pdf files after they have been printed.

Code: C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
    btnSubmit.Visible = false;
    ASPXToPDF.RenderAsPDF(false);
    ASPXToPDF.AfterRender += new EventHandler(ASPXToPDF_AfterRender);
    printPDF();
}

protected void ASPXToPDF_AfterRender(object sender, EventArgs e)
{
    HtmlToPdfResult htmlResult = (HtmlToPdfResult)ASPXToPDF.Result;
    htmlResult.PdfDocument.Save("C:\\Folder\\Document.pdf");
}
eo_support
Posted: Monday, July 15, 2013 12:26:01 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

No. The conversion ALWAYS happens at the LAST because it has to capture whatever changes your code made to your page. So it would be wrong to make it happen before your other code is executed.

Thanks!
Tyler
Posted: Monday, July 15, 2013 12:30:48 PM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
In that case, how would you recommend printing after the final form is converted?
eo_support
Posted: Monday, July 15, 2013 1:14:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Your code as to creating the PDF file is correct. As to why the folders is gone by the time the PDF file is created, that is related to your application logic and we would not know. All we can suggest is whatever you were doing before the conversion (for example, the code that deleted the directory), you need to restructure your code so that it does not happen before the conversion, for example, you may want to put that into a different background thread to do that. Obviously the exact detail is more about your application so we are not in a position to offer tech support on that.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.