itextsharp - write to web folder and write html to pdf

fwstealer
fwstealer used Ask the Experts™
on
Okay, i'd like to use the iTextsharp to:
1. write to a folder in my web site
2. write html to the pdf file.

I can write text to the pdf and store it locally. Any suggestions?
protected void Button1_Click(object sender, EventArgs e)
    {
        //Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
        Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
 
        try
        {
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
            //Open Document to write
            doc.Open();
 
            string msgbody = "Chunk line 1.\r\n";
            msgbody += "Chunk line 2.\r\n";
 
            //Write some content
            Paragraph paragraph = new Paragraph("Paragraph.\r\n\r\n");
 
            Phrase pharse = new Phrase("Phrase.\r\n\r\n");
 
            Chunk chunk = new Chunk(msgbody);
            
 
            // Now add the above created text using different class object to our pdf document
            doc.Add(paragraph);
            doc.Add(pharse);
            doc.Add(chunk);
        }
        catch (DocumentException dex)
        {
            //Handle document exception
            Response.Write(dex.Message.ToString());
        }
        catch (IOException ioex)
        {
            //Handle IO exception
            Response.Write(ioex.Message.ToString());
        }
        catch (Exception ex)
        {
            //Handle Other Exception
            Response.Write(ex.Message.ToString());
        }
        finally
        {
            doc.Close();
            //Close document
        }
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
Here's a starting point for doing so: http://blog.dmbcllc.com/2009/07/14/itextsharp-html-to-pdf-prerequisites/

Once you have created the PDF, you can store it locally. Make sure that the ASP.NET user has enough rights on the directory where you are writing to.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial