iTextSharp生成pdf,编译和运行没有错误,但没有PDF出现 [英] iTextSharp generating pdfs, compiles and runs without error but no PDF appears

查看:149
本文介绍了iTextSharp生成pdf,编译和运行没有错误,但没有PDF出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了许多不同的变体来从内存中输出一个非常基本的PDF,但似乎都返回了相同的结果,也就是说它实际上并没有返回任何内容。代码编译并运行没有错误,但是当VS完成处理代码时没有任何反应。

I've tried a number of different variations to output a very basic PDF from memory but all seem to return the same result, which is to say it doesn't actually return anything. The code compiles and runs without error but when VS finishes processing the code nothing happens.

我正在使用VS2008和iTextSharp v5.1.1

I'm using VS2008 and iTextSharp v5.1.1

有人有任何建议吗?

这是我当前状态下的代码:

Here is my code in its current state:

MemoryStream ms = new MemoryStream();           
Document doc = new Document();        
PdfWriter writer = PdfWriter.GetInstance(doc, ms);
writer.CloseStream = false;

doc.Open();
doc.Add(new Paragraph("Test Content"));
doc.Add(new Paragraph(DateTime.Now.ToString()));
doc.Close();

Response.ContentType = "application/pdf";
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
Response.OutputStream.Flush();            
Response.OutputStream.Close();
ms.Close();


推荐答案

我找到了导致我的问题的原因,代码是在button_click事件中,按钮控件位于ajax更新面板内,只要我将按钮移到更新面板之外,它就能完美地工作。不确定这是我的一个根本性错误还是更新面板的错误,所以我想读一下它们。

I found what was causing my issue, the code was in a button_click event where the button control was inside an ajax update panel, as soon as i moved the button outside of the update panel it worked perfectly. Not sure if this is a fundamental mistake on my part or a bug with update panels so I'm off to have a read about them.

@Mark Storer,我很感激既然这不是ITextSharp的问题,但是当我写这篇文章时我相信它是,为所有人的错误道歉。

@Mark Storer, I appreciate now that this wasn't an ITextSharp problem, however when I wrote this I believed it to be, apologies to all for the mistake.

这篇关于iTextSharp生成pdf,编译和运行没有错误,但没有PDF出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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