使用iTextSharp的PDF文件的创建 [英] Creation of PDF file using itextSharp

查看:120
本文介绍了使用iTextSharp的PDF文件的创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


 我创建一个ASP.net网站,一些文章可以上传。我需要我的用户可以通过点击一个按钮,得到它的PDF版本。对于这个功能,我使用iTextSharp的。
    我正在考虑以下两个选项。
1.我将创建PDF文件一次(第一次申请),并通过检查它的存在总是重用。
2.我将在飞行创建并尽快删除它作为PDF文件被传递到客户端。
第一种方法会导致更快的交付PDF,其中作为第二个方法将导致节省空间。谁能告诉我哪个选项是更好吗?

Hi I am creating an ASP.net website where some articles can be uploaded. I need that my users can get PDF version of it by clicking on a button. For this functionality I am using itextSharp. I am considering the following two options. 1. I will create the PDF file once(on first request) and reuse it always by checking for the existence of it. 2. I will create it on the fly and delete it as soon as the PDF file is delivered to the client. The first approach will lead to faster PDF delivery where as the second approach will lead to saving space. Can anyone please tell me which of the options is better?

我也想知道这是否可以不保存在服务器上的PDF首先是可能的。因此,谁能尽快回复我越好。

I am also wondering if this can be possible without saving the PDF on the server in the first place. So can anyone reply me as soon as possible.

谢谢
蒂帕

推荐答案

所以,你的代价是通过存储文件与通过始终生成它节省磁盘空间节省CPU周期。我会建议节省CPU周期,因为添加磁盘存储是廉价和容易(无需服务器脱机的情况下完成)。添加CPU相对更昂贵,通常要求服务器脱机(取决于您的环境)服用。

So your tradeoff is saving CPU cycles by storing the file versus saving disk space by always generating it. I would recommend saving CPU cycles because adding disk storage is cheap and easy (can be done without taking the server offline). Adding CPUs is relatively more expensive and usually requires taking the server offline (depends on your environment).

选项1:创建第一次请求PDF

优点:


  • 未创建PDF,除非有人下载,所以在创建PDF没有人不会浪费CPU就是了。

  • PDF是一个文件,所以IIS可以将其发送给客户端的文件,它是可用于IIS的缓存策略,等等。

缺点:


  • PDF文件占用的空间在磁盘上。

  • 需要标记的PDF(或删除)如果内容被改变,否则PDF版本可能不与文章同步。

选项2:在每次请求创建PDF

优点:


  • PDF始终是最新的文章的最新版本。

  • 磁盘空间最小化。

缺点:


    在服务器上
  • 重型CPU负载如果许多用户请求一个PDF下载。

  • 无法使用IIS或其他Web服务器的缓存策略。

这篇关于使用iTextSharp的PDF文件的创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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