PDF file download question.

Last post 03-10-2008, 4:23 PM by Saul. 5 replies.
Sort Posts: Previous Next
  •  03-06-2008, 5:05 PM 37659

    PDF file download question.

    Hi everyone this is my first time in this forum. First of all I am very impressed with cute editor, its amazing!
     
    I got Cute editor to convert a string into PDF and it works grate, the file downloads to my hardDrive no problems. but what I actually need is the pdf to be created dynamically and then have the file downloaded into the end-user PC (like downloading any other file) and not the server.
     
    is this possible?
     
    Thank you for your time.
  •  03-06-2008, 6:00 PM 37660 in reply to 37659

    Re: PDF file download question.

    Here's my code.  GetHTMLForm is a function call to a routine that gets the HTML to convert so you can replace that with your stirng.
     

    // here is where we'll get the HTML for the form

    string strFormContent = GetHTMLForm(pnlForm);

    Stream sPDFForm = new MemoryStream();

    try

    {

    // Create the PDF
     
    CuteEditor.Convertor.PDF.HTML2PDF objConverter = new CuteEditor.Convertor.PDF.HTML2PDF(strFormContent);

    objConverter.Save(sPDFForm);

    sPDFForm.Position = 0;

    }

    catch (Exception ex)

    {

    // We bombed creating PDF, move on

    lblMessage.Text += "Error generating the PDF.<br/>Exception Details: " + ex.Message;

    }

     

    Response.ContentType = "application / pdf";

    Response.AddHeader("Content-Disposition", "attachment; filename = somefile.pdf");

    Byte[] Holder = new Byte[sPDFForm.Length];

    sPDFForm.Read(Holder, 0, Convert.ToInt32(sPDFForm.Length));

    Response.BinaryWrite(Holder);

    Response.End();

    sPDFForm.Close();

  •  03-06-2008, 6:16 PM 37663 in reply to 37660

    Re: PDF file download question.

    Thanks for your response quackmire. I'll will give it a try.
     
    I have another question, what happens if multiple users try to generate PDF files at the same time?
  •  03-06-2008, 6:19 PM 37664 in reply to 37663

    Re: PDF file download question.

    it shouldn't be a problem, that method doesn't actually create and store a file on the machine (it's all done in memory), and thus, doesn't create any conflicts.
  •  03-06-2008, 7:07 PM 37667 in reply to 37664

    Re: PDF file download question.

    It's important to leave the error trapping in there by the way, see my other thread (http://cutesoft.net/forums/thread/37251.aspx).  The converter appears to be somewhat unstable.  I updated the comments in my example slightly too, since I had copied my code from an earlier routine that attached the file to an email.  I was lazy and didn't update my comments in the download function :)
     
    Good luck!
     
     
  •  03-10-2008, 4:23 PM 37733 in reply to 37667

    Re: PDF file download question.

    Thanks a lot Quackmire! This seem to fix my problems for now.
     
    If something else comes up I'll be sure to check back with you.
     
    Thank you again.

View as RSS news feed in XML