Need help with creating PDF from HTML using itextsharp

Posted by Steven on Stack Overflow See other posts from Stack Overflow or by Steven
Published on 2010-04-07T14:09:09Z Indexed on 2010/04/07 14:13 UTC
Read the original article Hit count: 481

Filed under:
|
|

I'm trying to crate a PDF out of a HTML page. The CMS I'm using is EPiServer.

This is my code so far:

    protected void Button1_Click(object sender, EventArgs e)
    {
        naaflib.pdfDocument(CurrentPage);
    }


    public static void pdfDocument(PageData pd)
    {
        //Extract data from Page (pd).
        string intro = pd["MainIntro"].ToString(); // Attribute
        string mainBody = pd["MainBody"].ToString(); // Attribute

        // makae ready HttpContext
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/pdf";

        // Create PDF document
        Document pdfDocument = new Document(PageSize.A4, 80, 50, 30, 65);
        //PdfWriter pw = PdfWriter.GetInstance(pdfDocument, HttpContext.Current.Response.OutputStream);
        PdfWriter.GetInstance(pdfDocument, HttpContext.Current.Response.OutputStream);  

        pdfDocument.Open();
        pdfDocument.Add(new Paragraph(pd.PageName));
        pdfDocument.Add(new Paragraph(intro));
        pdfDocument.Add(new Paragraph(mainBody));
        pdfDocument.Close();
        HttpContext.Current.Response.End();
    }

This outputs the content of the article name, intro-text and main body. But it does not pars HTML which is in the article text and there is no layout.

I've tried having a look at http://itextsharp.sourceforge.net/tutorial/index.html without becomming any wiser.

Any pointers to the right direction is greatly appreciated :)

© Stack Overflow or respective owner

Related posts about itextsharp

Related posts about .NET