【发布时间】:2012-03-28 06:40:31
【问题描述】:
我正在使用 jquery ajax 从 web 服务调用函数。
在该函数中,我正在使用 itextsharp 工具创建一个 pdf 文件。 我希望我创建的 pdf 文件在返回时应该在浏览器中打开。
谁能帮助我的返回类型应该是什么
下面是我在webservice中使用的代码
public void GeneratePDf(string ID) {
string attachment = "attachment; filename=" + ID + ".pdf";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
htextw.AddStyleAttribute("font-size", "12px");
htextw.AddStyleAttribute("color", "Black");
Page pg = new Page();
HtmlForm frm = new HtmlForm();
pg.EnableEventValidation = false;
pg.RenderControl(htextw);
Document document = new Document();
document = new Document(PageSize.A4, 10, 10, 0, 0);
PdfWriter.GetInstance(document, HttpContext.Current.Response.OutputStream);
document.Open();
Font verdana = FontFactory.GetFont("Verdana", 10, Font.BOLD, new CMYKColor(75, 68, 67, 90));
PdfPCell blank1 = new PdfPCell(new Phrase("Hello ", verdana));
document.Add(blank1);
//document.Add(tablegrid);
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
document.Close();
HttpContext.Current.Response.Write(document);
}
谁能告诉我我做错了什么
【问题讨论】:
标签: asp.net web-services c#-4.0 jquery itextsharp