iTextSharp pdfWriter.GetInstance错误 [英] iTextSharp pdfWriter.GetInstance error

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

问题描述

我使用的是iTextSharp pdf创建器,过去没有问题,但是在最新的项目中,当我设置GetInstance调用时,出现错误.我正在Visual Studios C#中工作

I'm using the iTextSharp pdf creater, I've used it in the past without issue, but on the newest project when I set the GetInstance call, I get an error. I'm working in Visual Studios C#

我的代码是:

Document ManagementReportDoc = new Document(PageSize.A4, 15f, 15f, 75f, 75f);

FileStream file = new FileStream(Server.MapPath("~/Pdf/PdfSample") + DateTime.Now.ToString("ddMMyyHHmmss") + ".pdf", System.IO.FileMode.OpenOrCreate);

PdfWriter writer = PdfWriter.GetInstance(ManagementReportDoc, file);

...

Visual Studio报告说,与'iTextSharp.text.pdf.PdfWriter.GetInstance(iTextSharp.tesxt.Document,System.IO.Stream)匹配的最佳重载方法"具有一些无效的参数'

Visual Studio reports that 'The best overloaded method match for 'iTextSharp.text.pdf.PdfWriter.GetInstance(iTextSharp.tesxt.Document, System.IO.Stream)' has some invalid arguments'

我已经尝试过使用dll和类文件,但两者都不起作用.当我添加其他代码(例如"ManagementReportDoc.Open();")时我收到更多错误文档"不包含打开"的定义.我相信我已经声明了正确的使用库.

I've tried using the dll and the class files and neither makes a difference. When I add further code such as 'ManagementReportDoc.Open();' I get further errors 'Document' does not contain a definition for 'Open'. I believe I've declared the correct using libraries.

它可以在其他两个项目上使用令人沮丧,但我似乎无能为力,可以在这些项目上使用它.

It's frustrating that it works on two other projects, but nothing I do seems to get it to work on these projects.

非常感谢您的帮助.

谢谢

G

推荐答案

感谢克里斯·哈斯(Chris Haas)在评论中进行回复,并为我提供了答案.

Thank you to Chris Haas for replying in the comments and essentially providing me with the answer.

使用完全解析的类名可以解决该错误,因此现在我的代码为

Using the fully resolved class names resolved the error, so now my code reads

iTextSharp.text.Document ManagementReportDoc = new iTextSharp.text.Document(PageSize.A4, 15f, 15f, 75f, 75f);

FileStream file = new FileStream(Server.MapPath("~/pdf/management-report/") + "management-report-" + DateTime.Now.ToString("dd-MMMM-yy") + ".pdf", System.IO.FileMode.OpenOrCreate);

iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(ManagementReportDoc, file); // PdfWriter.GetInstance(ManagementReportDoc, file);

ManagementReportDoc.Open();

一切似乎都有效.

再次感谢克里斯

这篇关于iTextSharp pdfWriter.GetInstance错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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