Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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...
Posted
Updated 20-Sep-12 1:11am
v2

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
<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>



Hope this helps.

David
 
Share this answer
 
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.
 
Share this answer
 
When the user clicks the button at the end of the eventhandler you can use
C#
Response.Redirect(urlToPDF);

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.
C#
Response.ContentType = "application/octet-stream";
 
Share this answer
 
Comments
Ruwaldo 21-Sep-12 4:00am    
I tried the Rsponse.Redirect but nothing is happening. Im not getting any errors, but its not doing anything

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900