itextsharp错误:“该文档没有页面." [英] itextsharp error: "The document has no pages."

查看:102
本文介绍了itextsharp错误:“该文档没有页面."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将三个dll设置为参考:

I set as references three dlls:

  • itextsharp.dll: the core library
  • itextsharp.xtra.dll: extra functionality (PDF 2!)
  • itextsharp.pdfa.dll: PDF/A-related functionality This project is hosted on http://sourceforge.net/projects/itextsharp/ You can find the latest release here: http://sourceforge.net/projects/itextsharp/files/itextsharp/

执行此代码时出现错误:

I get an error when executing this code:

在pdfDoc.Close()上,文档没有页面."

On pdfDoc.Close(), "The document has no pages."

Imports iTextSharp.text
Imports iTextSharp.text.html.simpleparser
Imports iTextSharp.text.pdf


    gv.DataBind()
    gv.AllowPaging = "False"
    Response.ContentType = "application/pdf"
    Response.AddHeader("content-disposition", "attachment;filename=Export.pdf")
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Dim sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)
    Dim frm As New HtmlForm()
    gv.Parent.Controls.Add(frm)
    frm.Attributes("runat") = "server"
    frm.Controls.Add(gv)
    frm.RenderControl(hw)
    Dim sr As New StringReader(sw.ToString())
    Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
    Dim htmlparser As New HTMLWorker(pdfDoc)
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
    pdfDoc.Open()
    htmlparser.Parse(sr)
    pdfDoc.Close()
    Response.Write(pdfDoc)
    Response.[End]()

推荐答案

不推荐使用类HTMLWorker,并且不应再使用它. HTML到PDF的功能已被称为XML Worker的技术所取代.我看到您包括itextsharp.xtra和itextsharp.pdfa,这是您不需要的2个DLL.我看不到您包括xmlworker DLL.

The class HTMLWorker is deprecated and should no longer be used. HTML to PDF functionality has been replaced by technology called XML Worker. I see that you include itextsharp.xtra and itextsharp.pdfa which are 2 DLLs you don't need. I don't see you including the xmlworker DLL.

作为例外:当您收到消息文档没有页面"时,您正在尝试创建一个没有任何内容的文档(这没有意义).这怎么可能?好吧,这完全取决于sr的内容.该内容为空或包含HTMLWorker无法解释的HTML.

As for the exception: when you get the message "The document has no pages", you are trying to create a document without any content (and that doesn't make sense). How is this possible? Well, it all depends on the content of sr. That content is either empty or it contains HTML that can't be interpreted by HTMLWorker.

附加说明:,您写在itextpdf.xtra旁边(PDF 2!).虽然xtra软件包包含PDF 1.7中不存在的功能,但它不是PDF 2软件包. PDF 2规范最早有望在2015年底发布(更现实的估计是2016年).在iText上,我们已经基于规范的草案实现了PDF 2.0功能,但是该功能(1)不限于xtra软件包中的内容,并且(2)不属于已公开发布的规范的一部分尚未通过ISO.

Extra remark: next to itextpdf.xtra, you wrote (PDF 2!). While the xtra package contains functonality that didn't exist in PDF 1.7, it's not the PDF 2 package. The PDF 2 specification is to be expected at the earliest by the end of 2015 (a more realistic estimation is 2016). At iText, we've already implemented PDF 2.0 functionality based on the draft of the spec, but that functionality is (1) not limited to what is in the xtra package, and (2) not part of a specification that has been publicly released by ISO yet.

这篇关于itextsharp错误:“该文档没有页面."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆