System.InvalidOperationException:从iTextSharp 5.3.3更新到5.4.2后已关闭
我收到一个System.InvalidOperationException:从iTextSharp 5.3.3更新到5.4.2后已关闭,exception,pdf-generation,itextsharp,document,corruption,Exception,Pdf Generation,Itextsharp,Document,Corruption,我收到一个System.invalidoOperationException:从v更新后已关闭异常。5.3.3至5.4.2 我打电话时会发生这种情况: Document doc = new Document(PageSize.A4); . . . doc.Close(); // Document is already closed hence the exception 需要注意的是,这段代码在iTextSharp 5.3.3上运行得非常完美 我对该行和PDF进行了注释,但随后iTextSh
System.invalidoOperationException:从v更新后已关闭
异常。5.3.3至5.4.2
我打电话时会发生这种情况:
Document doc = new Document(PageSize.A4);
.
.
.
doc.Close(); // Document is already closed hence the exception
需要注意的是,这段代码在iTextSharp 5.3.3
上运行得非常完美
我对该行和
PDF
进行了注释,但随后iTextSharp
开始输出损坏的PDF
文件,Adobe Reader或Windows 8内置PDF Reader无法打开这些文件。在Visual Studio中使用代码并利用IntelliSense,我研究了各种可能的方法在文档
对象上。我看到还有一个名为CloseDocument()
的附加方法,所以我更改了这一行:
doc.Close();
到
你猜怎么着?这东西又开始工作了。没有例外。太棒了
希望它能帮助将来可能遇到同样问题的人
好吧,好吧。。。在尝试不同的输入选项后,我又开始出现异常 我明确地说:
pdfReader.Close();
在
附录文档
方法中。这是在调用doc.Close()之前发生的代码>。在Visual Studio中使用代码并利用IntelliSense,我查看了文档
对象上的各种可能方法。我看到还有一个名为CloseDocument()
的附加方法,所以我更改了这一行:
doc.Close();
到
你猜怎么着?这东西又开始工作了。没有例外。太棒了
希望它能帮助将来可能遇到同样问题的人
好吧,好吧。。。在尝试不同的输入选项后,我又开始出现异常
我明确地说:
pdfReader.Close();
在附录文档
方法中。这是在调用doc.Close()之前发生的代码>。刚刚注释了上面的行,异常就消失了。使用此代码
private void ceratepdf()
{
using (FileStream msReport = new FileStream(Server.MapPath("~") + "/App_Data/" + DateTime.Now.Ticks + ".pdf", FileMode.Create))
{
//step 1
Document doc = new Document(PageSize.A4, 2f, 2f, 10f, 15f);
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, msReport);
PdfPCell cell;
PdfPTable table = new PdfPTable(4);
cell = new PdfPCell(new Phrase("Incident Details"));
cell.Colspan = 4;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
cell.VerticalAlignment = 1;
table.AddCell(cell);
doc.Open();
doc.Add(table);
doc.Close();
}
}
使用此代码
private void ceratepdf()
{
using (FileStream msReport = new FileStream(Server.MapPath("~") + "/App_Data/" + DateTime.Now.Ticks + ".pdf", FileMode.Create))
{
//step 1
Document doc = new Document(PageSize.A4, 2f, 2f, 10f, 15f);
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, msReport);
PdfPCell cell;
PdfPTable table = new PdfPTable(4);
cell = new PdfPCell(new Phrase("Incident Details"));
cell.Colspan = 4;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
cell.VerticalAlignment = 1;
table.AddCell(cell);
doc.Open();
doc.Add(table);
doc.Close();
}
}