[英]Using ABCPDF to generate document in memory instead of saving on physical drive
I was looking into example of ABCPDF using: Examples of ABC PDF 我正在使用以下方法研究ABCPDF的示例:ABC PDF的示例
The problem is: It always saves the document on the physical drive. 问题是:它总是将文档保存在物理驱动器上。 Is there any way to generate PDF document in memory and use content disposition to render the document
有什么方法可以在内存中生成PDF文档并使用内容处置来呈现文档
Thank you 谢谢
Looks like the Save()
function is able to take a Stream
. 看起来
Save()
函数能够获取Stream
。 Make a new MemoryStream
and save it to that. 制作一个新的
MemoryStream
并将其保存到该文件。
http://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/save.htm http://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/save.htm
Also, Attachment
takes a Stream
. 另外,
Attachment
需要一个Stream
。
So: 所以:
Attachment data = new Attachment(yourMemoryStream, MediaTypesNames.Application.Pdf);
ContentDisposition disposition = data.ContentDisposition;
Use Doc.GetData to get the PDF as an array of bytes. 使用Doc.GetData以字节数组的形式获取PDF。 If this type of raw data is what you want then this will be more efficient than using a MemoryStream.
如果您想要这种类型的原始数据,那么它将比使用MemoryStream更有效。
You can pass your PDF to a stream using the GetData()
function in ABCPDF. 您可以使用ABCPDF中的
GetData()
函数将PDF传递到流。 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.