使用itextsharp版本5.5.5.0将html页面转换为pdf文件

时间:2015-04-28 16:55:54

标签: c# .net pdf itext

我想将HTML页面转换为PDF页面。我有一个Windows应用程序。

我看到很多文章,但没有找到任何正确的解决方案。我也面临图像路径问题和一些其他问题,如输入字符串格式不正确。请求帮助我找到解决方案,以便我可以在我的Windows应用程序中使用它。

我正在使用以下代码

Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
    Dim document As New Document()
    Try
        PdfWriter.GetInstance(document, New FileStream(AppDomain.CurrentDomain.BaseDirectory + "\SCRA_Resources\SCRA.pdf", FileMode.Create))
        document.Open()
        Dim wc As New WebClient()
        Dim htmlText As String = wc.DownloadString(AppDomain.CurrentDomain.BaseDirectory + "\SCRA_Resources\SCRA.html")
        Dim htmlarraylist = HTMLWorker.ParseToList(New StringReader(htmlText), Nothing)
        For k As Integer = 0 To htmlarraylist.Count - 1
            document.Add(DirectCast(htmlarraylist(k), IElement))
        Next
        document.Close()
    Catch
    End Try
End Sub

当我运行此代码时,我收到错误找不到文件' C:\ TestProjects \ MergePDfs \ MergePDfs \ bin \ Debug \ help.gif'。

我将这些图像放在我的html文件保存的位置。但是html工作者之前切断了两个文件夹的路径。而且它没有完全采用CSS。

0 个答案:

没有答案
相关问题