0
我是这个库的新手,但我找不到任何有关使用此库下载到文件流,我只能找到一个document.Save(文件路径)选项,这并不总是允许的。 我想创建一个文件流,以便将文件下载到定向下载文件夹。PDFSharp通过文件流下载文件
难道有人会指出我的直接权利?
我是这个库的新手,但我找不到任何有关使用此库下载到文件流,我只能找到一个document.Save(文件路径)选项,这并不总是允许的。 我想创建一个文件流,以便将文件下载到定向下载文件夹。PDFSharp通过文件流下载文件
难道有人会指出我的直接权利?
有一个Save
过载,它需要一个MemoryStream
对象而不是文件的路径。
的PDFSharp网站上有一个example展示如何做到这一点:
private void Page_Load(object sender, System.EventArgs e)
{
// Create new PDF document
PdfDocument document = new PdfDocument();
this.time = document.Info.CreationDate;
document.Info.Title = "PDFsharp Clock Demo";
document.Info.Author = "Stefan Lange";
document.Info.Subject = "Server time: " +
this.time.ToString("F", CultureInfo.InvariantCulture);
// Create new page
PdfPage page = document.AddPage();
page.Width = XUnit.FromMillimeter(200);
page.Height = XUnit.FromMillimeter(200);
// Create graphics object and draw clock
XGraphics gfx = XGraphics.FromPdfPage(page);
RenderClock(gfx);
// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();
}