用户单击导出后如何获取PDF文档显示 [英] How to get PDF document to show after user clicks export

查看:107
本文介绍了用户单击导出后如何获取PDF文档显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是一名初学者,并且有一个小问题.我有一个带有表格的网页,该表格可从数据库动态获取其信息.我有一个导出按钮,可以将表的数据导出为pdf格式(使用ITEXTSHARP).导出按钮将起作用,PDF文件将保存到项目的解决方案文件夹中.但是,如何在单击导出按钮后如何显示PDF文件,以便用户/查看者可以看到pdf,然后选择将其保存在何处.非常感谢您的帮助,在此先感谢您...

Hi all i am a beginner programmer, and have a small problem. I have a webpage with a table that gets its information dynamically from the database. I have a export button that exports the data of the table to pdf format (using ITEXTSHARP). The export button works and the PDF file is saved into the solution folder of the project. But how can i get the PDF file to show after the export button is clicked so the user/viewer can see the pdf and then select where to save it. Any help will be much appreciated, thanking you in advance...

推荐答案

1)有一个名为PDF.js的库,PDF JS [ ^ ],您也可以尝试一下.

2)PDF Object是一个也可以使用js呈现PDF的库. http://pdfobject.com/ [ ^ ]
-他们网站上的示例代码:
1) There is a library called PDF.js, PDF JS[^] you could give this a shot as well.

2) PDF Object is a library to render your PDF using js as well. http://pdfobject.com/[^]
-Sample code from their site:
<html>
  <head>
    <title>PDFObject example</title>
    <script type="text/javascript" src="pdfobject.js"></script>
    <script type="text/javascript">
      window.onload = function (){
        var success = new PDFObject({ url: "sample.pdf" }).embed();
      };
    </script>
  </head> 
  <body>
    <p>It appears you don't have Adobe Reader or PDF support in this web
    browser. <a href="sample.pdf">Click here to download the PDF</a></p>
  </body>
</html></html>




希望这会有所帮助.

David




Hope this helps.

David


感谢所有答复.但是我最终只使用了一个超链接,指向用户单击导出按钮时创建的pdf文件.
Thanks for all the responses. But i ended up just using a hyperlink that points to the pdf file that was created when the user clicked the export button.


当用户单击事件处理程序末尾的按钮时,您可以使用
When the user clicks the button at the end of the eventhandler you can use
Response.Redirect(urlToPDF);


为此,您需要将PDF放在用户可以浏览到的文件夹中.

如果您将内容类型保留为默认值,则浏览器可能会像平常一样打开文档,但是如果用户对此进行了设置,它可能会下载该文档.
如果要强制下载并将用户留在页面上,则必须将http content-type标头更改为application/octet-stream.

要更改http标头,可以使用以下代码.


For this to work you will need the PDF to be in a folder where the user can browse to.

If you leave the content-type default the browser will probably open the document like normal, but it might download it if the user has his settings on that.
If you want to force a download, and leave the user on your page, you will have to change the http content-type header to application/octet-stream.

To change the http header you can use the following code.

Response.ContentType = "application/octet-stream";


这篇关于用户单击导出后如何获取PDF文档显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆