我很幸运有一位专家在这里帮助我使用此代码,但我无法让它工作。我收到各种错误。首先,这是代码:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports EO.Pdf
Imports System.Collections.Specialized
Partial Class getParcels
Inherits System.Web.UI.Page
Public Function Download() As FileResult
// Populate list with urls
Dim urls = New List(Of String)() With { _
"C:\1.html", _
"C:\2.html" _
}
Dim documents = New List(Of EO.Pdf.PdfDocument)()
For Each url As var In urls
Dim doc = New EO.Pdf.PdfDocument()
EO.Pdf.HtmlToPdf.ConvertUrl(url, doc)
documents.Add(doc)
Next
Dim mergedDocument As EO.Pdf.PdfDocument = EO.Pdf.PdfDocument.Merge(documents.ToArray())
Dim ms = New MemoryStream()
mergedDocument.Save(ms)
ms.Position = 0
Return New FileStreamResult(ms, "application/pdf") With { _
.FileDownloadName = "download.pdf" _
}
End Function
此代码旨在允许我们同时使用多个网址,将它们与逗号分隔并将它们合并为一个pdf文档。它给出了fileResult未定义的错误。
以下内容:
C:\1.html
C:\2.html
它说name of field or property being initialized in an object initializer must start with ','
然后未定义类型var,必须声明url,未定义类型MemoryStream,未定义类型FileStreamResult。在我看来,缺少一个系统导入。这是Essential Objects html to pdf组件的一部分。
答案 0 :(得分:1)
使用From
,
Dim urls = New List(Of String)() From
{
"C:\1.html",
"C:\2.html"
}
或者
Dim urls = New List(Of String)(
{
"C:\1.html",
"C:\2.html"
})