C# iTextSharp “该文档没有页面。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19278623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 14:35:10  来源:igfitidea点击:

iTextSharp "The document has no pages."

c#itextsharp

提问by witchlightning

I'm using iTextSharp to update A PDF's file properties:

我正在使用 iTextSharp 更新 PDF 的文件属性:

FileStream fs = File.Open(@"C:\Developer\C#Projects\BylawSearch
document.Add(new Paragraph("Hello World!"));
01.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. Any help appreciated.

我收到“文档没有页面”的提示。来自 iTextSharp 的错误。任何帮助表示赞赏。

回答by noelicus

You haven't added any information to put on a page ... !!

你还没有添加任何信息放在页面上......!

##代码##

... 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.

查看这个介绍性示例,它似乎涵盖了您所追求的内容。