本文介绍了如何在Sharepoint服务器端生成pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是SharePoint开发的新手.我想在其中添加自定义按钮sharepoint 2013中的view.aspx.通过单击按钮,它将使用ipdfSharp生成pdf文件,我可以在客户端看到并下载该文件.
Hi, I 'm new in sharepoint development. I want to add a custom button in a view.aspx in sharepoint 2013. By clicking in the button it will generate a pdf file using ipdfSharp that i can see and download in the client side.
推荐答案
此处是示例脚本供您参考.
protected void btn_GeneratePDF(object sender, EventArgs e)
{
PdfDocument pdf = new PdfDocument();
pdf.Info.Title = "My First PDF";
PdfPage pdfPage = pdf.AddPage();
XGraphics graph = XGraphics.FromPdfPage(pdfPage);
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
graph.DrawString("This is my first PDF document", font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.Center);
string pdfFilename = "firstpage.pdf";
using (MemoryStream ms = new MemoryStream())
{
pdf.Save(ms, false);
byte[] buffer = new byte[ms.Length];
ms.Seek(0, SeekOrigin.Begin);
ms.Flush();
ms.Read(buffer, 0, (int)ms.Length);
byte[] docBytes = ms.ToArray();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + pdfFilename + "");
Response.Write("<b>File Contents: </b>");
Response.BinaryWrite(docBytes);
}
}
最好的问候,
Lee
这篇关于如何在Sharepoint服务器端生成pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!