0

我很幸运在这里有一位专家帮助我处理这段代码,但我无法让它工作。我收到各种错误。首先,这里是代码:

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

此代码旨在允许我们同时访问多个 url,用逗号分隔它们并将它们合并到一个 pdf 文档中。它给出了 fileResult 未定义的错误。

关于以下内容:

C:\1.html
C:\2.html

它说name of field or property being initialized in an object initializer must start with ','

那么类型var未定义,urls必须声明,类型MemoryStream未定义,类型FileStreamResult未定义。在我看来,缺少一个系统导入。这是 Essential Objects html to pdf 组件的一部分。

4

1 回答 1

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"
            })
于 2012-07-25T03:05:23.000 回答