![](/img/trans.png)
[英]Create FileStream in memory instead of saving a physical file on disk
[英]Using ABCPDF to generate document in memory instead of saving on physical drive
看起來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更有效。
您可以使用ABCPDF中的GetData()
函數將PDF傳遞到流。 然后使用適當的標題信息將字節寫出到瀏覽器。
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.