【发布时间】:2011-12-07 08:12:24
【问题描述】:
我使用 Sharepoint 2010,我正在开发一个 Web 部件,在该部件中,在按钮单击事件中,需要生成并直接打开一个 pdf 文件。不应保存到磁盘上。 我试过下面的代码
protected void Button1_OnClick(object sender, EventArgs e)
{
Document myDoc = new Document(PageSize.A4.Rotate());
try
{
PdfWriter.GetInstance(myDoc, new FileStream(@"C:\Directory\Test.pdf", FileMode.Create));
myDoc.Open();
myDoc.Add(new Paragraph("Hello World"));
}
catch (DocumentException ex)
{
Console.Error.WriteLine(ex.Message);
}
myDoc.Close();
}
我也尝试了下面的代码,它也在服务器上生成了我不想要的文件。
Document document = new Document(PageSize.A4);
PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("~/Test.pdf"), FileMode.Create));
document.Open();
var WelcomePara = new Paragraph("Hello World");
document.Add(WelcomePara);
document.Close();
这个在桌面上创建pdf文件,我需要它以pdf格式打开。请有人帮助我。
【问题讨论】:
标签: asp.net sharepoint pdf-generation itextsharp