简体   繁体   English

iTextSharp “该文档没有页面。”

[英]iTextSharp “The document has no pages.”

I'm using iTextSharp to update A PDF's file properties:我正在使用 iTextSharp 更新 PDF 的文件属性:

FileStream fs = File.Open(@"C:\Developer\C#Projects\BylawSearch\0001.pdf", FileMode.Open);
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
document.AddSubject("Blah");
document.AddTitle("Blah blah");
document.AddKeywords("Blah blah blah");
document.Close();

I'm getting a "The document has no pages."我收到“文档没有页面”的提示。 error from iTextSharp.来自 iTextSharp 的错误。 Any help appreciated.任何帮助表示赞赏。

You haven't added any information to put on a page ... !!你还没有添加任何信息放在页面上......!

document.Add(new Paragraph("Hello World!"));

... for example. ……例如。

Your title etc are part of the document properties (rather than something that's "printed" to the pdf).您的标题等是文档属性的一部分(而不是“打印”到 pdf 的内容)。

Check out this introductory example , that seems to cover what you're after.查看这个介绍性示例,它似乎涵盖了您所追求的内容。

In my case, I had added a paragraph, but specified a font that was null.就我而言,我添加了一个段落,但指定的字体为空。

document.Add(new Paragraph("Hello World!", nullFont));

Either make sure the font is valid, or else don't use the Paragraph constructor with the Font argument.要么确保字体有效,要么不要使用带有 Font 参数的 Paragraph 构造函数。

(This does not apply to the poster's scenario, but may be helpful to someone else.) (这不适用于海报的场景,但可能对其他人有帮助。)

I had the same issue with Xamarin, .NET.我对 Xamarin、.NET 也有同样的问题。 For me the error message was misleading, because it happened when i tried to create fonts from local files.对我来说,错误消息具有误导性,因为它发生在我尝试从本地文件创建字体时。

Project settings > Android Options > Additional supported encodings.项目设置 > Android 选项 > 其他支持的编码。 Set this to West and it solved my problem.将其设置为 West,它解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iTextSharp “该文档没有页面。” 错误 - iTextSharp "The document has no pages." error ITextSharp错误-文档无页面 - ITextSharp Error - The document has no pages 当我有锚标记时,itextsharp“文档没有页面”错误 - itextsharp “the document has no pages” error when i have anchor tag iTextSharp.tool.xml.XMLWorkerHelper.GetInstance()。ParseXHtml()引发异常,因为在Windows应用程序中使用WebBrowser的文档没有页面 - iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml() throwing exception as the document has no pages using WebBrowser in windows application Mailkit:使用 iTextSharp XMLWorker 将 HtmlBody 转换为 pdf 抛出“文档没有页面” - Mailkit: Converting HtmlBody to pdf using iTextSharp XMLWorker throws “The document has no pages” 在iTextSharp中更改PDF文档的订单页面 - Change order pages of PDF document in iTextSharp itextsharp 修剪 pdf 文档的页面 - itextsharp trimming pdf document's pages iTextSharp错误文档打开前没有页面 - iTextSharp error document has no page before open it 将子文件夹中的所有图像作为新页面添加到iTextSharp中的PDF文档中? - Add all images in subfolders to PDF document in iTextSharp as new pages? 使用itextsharp向新的pdf文档添加新页面和标签 - adding new pages and labels to new pdf document using itextsharp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM