显示在ASP.net页面的PDF文档 [英] Displaying a PDF Document in ASP.net page
问题描述
任何人都可以建议我这是在一个aspx页面显示PDF文档的最佳方式。我希望用户使用缩放功能在查看PDF文档。
Can anyone suggest me which is the best way of displaying a PDF document in an aspx page. I want users to use zoom functionality while viewing the pdf document.
在此先感谢
推荐答案
如果您在内存中的PDF使用流对象之一进行分解为一个字节数组(可能使用的MemoryStream的.ToArray()函数类)。在字节数组下面这个例子被称为数据
If you have the PDF in memory use one of the Stream objects to break it down to a byte array (possibly using the .ToArray() function of the MemoryStream class). In this example below the byte array is called data:
Response.ContentType = "Application/pdf";
Response.OutputStream.Write(data, 0, data.Length);
编辑:这种方法效果很好,如果你想要做的是服务于一个PDF。阅读一些评论后,我意识到问题是更侧重于展示网页的段中的PDF文件。我用另一种方法是嵌入标记引用了codeFile的功能。在这种情况下,如果你有一个磁盘上的PDF驱动器可以使用
This approach works well if all you want to do is serve up a PDF. After reading some of the comments I realized the question was more focused on showing a PDF inside a section of a webpage. Another alternative I have used is an embed tag that references a codefile function. In this case, if you have the PDF on a disk drive you can use
<embed id="Embed1" src='<%# pdfLocation() %>' runat="server" name="pdfLoad"></embed>
当函数pdfLocation返回一个字符串重新PDF文件的位置presentation。
Where the function pdfLocation returns a string representation of the location of the PDF file.
这篇关于显示在ASP.net页面的PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!