我正在使用以下方法研究 ABCPDF 示例:ABC PDF 示例
问题是:它总是将文档保存在物理驱动器上。有没有办法在内存中生成 PDF 文档并使用内容配置来呈现文档
谢谢
看起来该Save()
功能能够采用Stream
. 制作一个新的MemoryStream
并将其保存到该位置。
http://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/save.htm
此外,Attachment
需要一个Stream
.
所以:
Attachment data = new Attachment(yourMemoryStream, MediaTypesNames.Application.Pdf);
ContentDisposition disposition = data.ContentDisposition;
使用 Doc.GetData 将 PDF 作为字节数组获取。如果这种类型的原始数据是您想要的,那么这将比使用 MemoryStream 更有效。
You can pass your PDF to a stream using the GetData()
function in ABCPDF.
Then write the bytes out to the browser with the appropriate header information.
Dim pdfbytestream as Byte() = oPDF.GetData()
oPDF.Dispose() 'free up unused object
Dim myRandomID As String = Year(Now()).ToString + Month(Now()).ToString + Day(Now()).ToString + Hour(Now()).ToString + Minute(Now()).ToString + Second(Now()).ToString
'Write it out to the browser.
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
If pdfbytestream Is Nothing Then Response.AddHeader("content-length", 0) Else Response.AddHeader("content-length", pdfbytestream.Length.ToString())
Response.AddHeader("content-disposition", "inline; filename=" & myRandomID & ".pdf?" & Now.Millisecond)
Response.BinaryWrite(pdfbytestream)