簡體   English   中英

使用ABCPDF在內存中生成文檔,而不是保存在物理驅動器上

[英]Using ABCPDF to generate document in memory instead of saving on physical drive

我正在使用以下方法研究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更有效。

您可以使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM