开发者

Create pdf document in asp.net 2.0

开发者 https://www.devze.com 2023-01-07 05:58 出处:网络
I am using asp.net 2.0 with c#. I have to convert my label text into pdf. For this I have used this tutorial

I am using asp.net 2.0 with c#.

I have to convert my label text into pdf. For this I have used this tutorial http://www.codeproject.com/KB/aspnet/Creating_PDF_documents_in.aspx

now I am facing two problems:

  1. Every time it is creating 1.pdf, what if there are so many user wants to see the the pdf format of any page
  2. As my label text contains HTML content, it is showi开发者_高级运维ng a HTMl output. I don't want HTML to be display in the pdf.

please let me know if you have any other way to create a pdf.

Thanks in advance.


Creating a PDF with HTML-formatted content is not entirely trivial, and the CodeProject sample code isn't quite suitable for that. You'll most likely want to look into a (commercial) third-party solution for this: I myself use Siberix Report Writer: it's flexible, quite affordable, works in partial-trust scenarios (nice for shared web hosting environments) and most importantly doesn't require a per-server license, so you can embed it in your product without redistribution issues.


Item 1) You cache your pdf files to disk. When a request is made for a pdf check if the pdf has been created (i.e. there is a file on disk) and if not generate it. Then send the pdf using the response.writefile command

Item 2) If you are trying to print formatted html into pdf then you will need something that is capable of rendering html. There are a number of html to pdf converters however I have not found them to be all that good. If you are comfortable with php then there are some pretty good converters you can use. Joomla supports html to pdf, so whilst it may not be the exact solution it maybe a good starting point.


I would also suggest you take a look at Aspose PDF.


I would suggest using RDLC Report or Crystal Reports as suggested by @Jeroen


Cete Pdf Generator has HtmlTextArea element and supports some limited HTML

http://www.cete.com/support/net_help_library/html/ceTeDynamicPDFPageElementsHtmlTextArea.htm


ABCpdf is another commercial component which converts html to pdf. http://www.websupergoo.com/abcpdf-5.htm


You could try the itextsharp library. I've not used it but it has been highly commended by other developers I know. http://sourceforge.net/projects/itextsharp/

In regards to the caching issue. I would check the file system for a pdf named via a convention. If the file is found then serve it. Otherwise, call another method which generates the pdf and saves it to the drive. This way only the first ever request will cause the generation of the pdf. Naming conventions will be key here. The basic implementation wont be thread safe. But it's a good start.


I use CrystalReports. It can create a PDF on the fly and output it to disk or http directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消