iTextSharp格式保留在pdf上

时间:2014-12-13 15:25:12

标签: html pdf

我正在尝试使用iTextSharp.dll将html转换为pdf。虽然在输出pdf文档中,它呈现没有格式化文本的html标记。请告诉我我错过了什么。

        Document pdfDoc = new Document(PageSize.A4, 50, 50, 25, 25);
        var textInput = Label1.Text;
        try
        {
        var output = new MemoryStream();
        var writer = PdfWriter.GetInstance(pdfDoc, output);
        pdfDoc.Open();
        var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Image/image1.jpg"));
        logo.SetAbsolutePosition(400, 750);
        pdfDoc.Add(logo);
        Paragraph para = new Paragraph(textInput);
        para.Alignment = Element.PARAGRAPH;
        pdfDoc.Add(para);
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Doc-{0}.pdf", TextBox3.Text));
        Response.BinaryWrite(output.ToArray());
        }
        catch (DocumentException dex)
        {
            throw (dex);
        }
        catch (IOException ioex)
        {
            throw (ioex);
        }
        finally
        {
            pdfDoc.Close();
        }
    }

我非常感谢任何帮助。

0 个答案:

没有答案