将html转换为pdf时应用css

时间:2012-11-02 13:35:20

标签: css vb.net itextsharp

将html转换为pdf时,我的代码出现问题。即使我正在使用

,也不会应用css
StyleSheet.LoadStyle("class_name", "font-size", "24px")

然后转到此

Dim parsedHtmlElements = HTMLWorker.ParseToList(New StringReader(content), obj)

现在,当创建pdf文件时,不会应用css。

1 个答案:

答案 0 :(得分:0)

这是我在转换时动态插入CSS文件的方式。

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    If Not Page.IsPostBack Then
        ' If we are in print mode, it's time to format the page for PDF generation
        If Not String.IsNullOrEmpty(Request.QueryString("print")) Then
            ' Dynamically add a LINK element to the page that points to the 
            ' print-ready CSS styles
            Dim printCSS As New HtmlLink
            printCSS.Href = "~/Framework/Styles/pdf.css"
            printCSS.Attributes.Add("rel", "stylesheet")
            printCSS.Attributes.Add("type", "text/css")
            Page.Header.Controls.Add(printCSS)
        End If
    End If
End Sub