【问题标题】:PDF generation performance ASP.NETPDF 生成性能 ASP.NET
【发布时间】:2012-03-14 14:14:10
【问题描述】:

我现在正在构建一个 ASP.NET 站点,我们正在用下载 pdf 按钮替换每个打印按钮。原因很简单,我们希望所有浏览器的响应都是统一的,上面印有我们自己的品牌。

效果很好,生成的 pdf 文件非常完美 (EO.PDF)。但是,它似乎需要相当多的负载。

现在我想知道,有没有可以用来提高性能的好技术?节流、“通过电子邮件发送”等

我对多线程不太了解,但是有没有办法将一个线程分成两个虚拟线程并将一组特定的资源分配给一个?或者可能分配一个特定线程仅用于生成 PDF 并使其在任何其他事件中处于非活动状态?

谢谢

【问题讨论】:

    标签: asp.net performance pdf sharepoint-2010 pdf-generation


    【解决方案1】:

    虽然 EO.PDF 是“线程安全的”,但至少从 EO.PDF 2011/3.x 开始,它会序列化所有内容 - 这意味着,线程对 EO.PDF 性能毫无帮助。虽然将 EO.PDF 作为后台服务运行会阻止它“挂起”响应,但它也会将其更改为异步进程 - 这可能会也可能不会,但这是一种完全不同的方法。

    如果使用 EO.PDF 支持来转换另一个 ASP.NET 页面,则可以通过确保快速加载该页面来提高性能。 EO.PDF 确实支持缓存,但我不确定这是否在不同进程之间持续存在。在这方面,可以考虑分析 EO.PDF 生成的网络请求,看看是否存在可以改进的严重瓶颈。

    另外,请确保获取您的许可证允许的最新版本..

    【讨论】:

      【解决方案2】:

      用户在 asp.net 中生成 PDF 的代码如下:您必须下载 itextSharp.dll,然后在您的 Web 应用程序中提供参考。

      下面有一个完整的代码示例可以帮助您入门。 // 代码

      using System;
      using System.IO;
      using System.Diagnostics;
      
      using iTextSharp.text;
      using iTextSharp.text.pdf;
      
      public class iTextDemo 
      {
       public static void Main() 
       {
        Console.WriteLine("iText Demo");
      
        // step 1: creation of a document-object
        Document myDocument = new Document(PageSize.A4.Rotate());
      
        try 
        {
      
         // step 2:
         // Now create a writer that listens to this doucment and writes the document to desired Stream.
      
         PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf", FileMode.Create));
      
         // step 3:  Open the document now using
         myDocument.Open();
      
         // step 4: Now add some contents to the document
         myDocument.Add(new Paragraph("First Pdf File made by Salman using iText"));
      
        }
        catch(DocumentException de) 
        {
         Console.Error.WriteLine(de.Message);
        }
        catch(IOException ioe) 
        {
         Console.Error.WriteLine(ioe.Message);
        }
      
        // step 5: Remember to close the documnet
      
        myDocument.Close();
       }
      }
      

      如果您想保存格式化的 PDF,请在以下链接中使用以下代码: http://www.4guysfromrolla.com/articles/030911-1.aspx

      【讨论】:

      • 嗨,我已经可以生成PDF了。我正在寻找一种通过使用服务器端技术或优化使用多线程来提高性能的方法。
      猜你喜欢
      • 1970-01-01
      • 2015-11-22
      • 2018-08-08
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多