Itext Ilist 转 pdf
我在c#中有一个IList
,我想通过IText将其放入PDF中。有什么办法可以做到这一点吗?我已经找了一段时间了。
我试图做的是:
s = BLLstudent.selectStudentById(Convert.ToInt16(Request.QueryString["s"]));
var data = BLLevk.selectEvkDetailsVanStudent(s.pk_studentID);
Document mySavedPDF = new Document();
FileStream fs = new FileStream(@"C:\Users\Toon\Documents\Visual Studio 2010\WebSites\LilyNoone-LessLes-503729a\prints\" + s.studentNaam + "_" + s.studentVoornaam + ".pdf", FileMode.Create);
PdfWriter.GetInstance(mySavedPDF, fs);
mySavedPDF.Open();
mySavedPDF.Add(data);
mySavedPDF.CloseDocument();
但这说
错误 2 参数 1:无法从“System.Collections.Generic.IList”转换为“System.IO.TextReader”C:\Users\Toon\Documents\Visual Studio 2010\WebSites\evk-applicatie-181211\web \admin\a_overzicht_student.aspx.cs 95 77 C:...\evk-applicatie-181211\
有没有办法直接插入列表?
提前谢谢
I have an IList
in c#, and I want to put it in PDF through IText. Is there any way to do this? I have been searching for it for a while now.
What i tried to do was:
s = BLLstudent.selectStudentById(Convert.ToInt16(Request.QueryString["s"]));
var data = BLLevk.selectEvkDetailsVanStudent(s.pk_studentID);
Document mySavedPDF = new Document();
FileStream fs = new FileStream(@"C:\Users\Toon\Documents\Visual Studio 2010\WebSites\LilyNoone-LessLes-503729a\prints\" + s.studentNaam + "_" + s.studentVoornaam + ".pdf", FileMode.Create);
PdfWriter.GetInstance(mySavedPDF, fs);
mySavedPDF.Open();
mySavedPDF.Add(data);
mySavedPDF.CloseDocument();
But this said
Error 2 Argument 1: cannot convert from 'System.Collections.Generic.IList' to 'System.IO.TextReader' C:\Users\Toon\Documents\Visual Studio 2010\WebSites\evk-applicatie-181211\web\admin\a_overzicht_student.aspx.cs 95 77 C:...\evk-applicatie-181211\
Is there any way to insert the list directly?
Thx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,无法直接将通用
IList
直接添加到Document
对象。如果您查看 Document.Add 方法,唯一有效的参数是 元素object - 这就是抛出Exception
的原因。如果您考虑一下,尝试将通用 IList 添加到 PDF 将非常困难 - 至少您必须考虑 IList 元素type
以及如何格式化每个成员PDF 中的属性(在使用Reflection
确定类型和成员之后)。所以你有几个选择。
第二个选择还不错,您可以完全控制如何展示您的收藏。这是一个简单的例子:
有一个像这样的简单类:
No, there's no way to directly add a generic
IList
to theDocument
object directly. If you take a look at the Document.Add method, the only valid parameter is an Element object - that's why theException
is thrown. If you think about it, trying to add a generic IList to a PDF would be very difficult - at the minimum you would have to take into consideration both the IList elementstype
, and also how to format each member property (after you determine both type and members usingReflection
) in the PDF.So you have a couple of choices.
The second choice isn't so bad, and you have complete control of how to display your collection. Here's a simple example:
With a simple class like this: