Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用ABCPDF将网站集中在一个页面上_C#_Asp.net_Memory Leaks_Application Pool_Abcpdf - Fatal编程技术网

C# 使用ABCPDF将网站集中在一个页面上

C# 使用ABCPDF将网站集中在一个页面上,c#,asp.net,memory-leaks,application-pool,abcpdf,C#,Asp.net,Memory Leaks,Application Pool,Abcpdf,我有一些代码可以很好地将html集中在abcpdf的一个页面中。这是创建abcpdf的websupergoo公司提供给我的。但是,我的应用程序池不断关闭,我认为这是一个性能问题。我甚至启用了缓存。是否有任何方法可以优化此代码。基本上,代码对html页面进行调用,并计算出边界尺寸来设置浏览器宽度,从而使其适合pdf尺寸。这样做会一次又一次地调用html页面,但有人告诉我,如果它被缓存,它不会发出实际请求,而是读取缓存。必须有一种更简单的方法来实现这一点,因为渲染确实需要一段时间。当多个请求同时指向

我有一些代码可以很好地将html集中在abcpdf的一个页面中。这是创建abcpdf的websupergoo公司提供给我的。但是,我的应用程序池不断关闭,我认为这是一个性能问题。我甚至启用了缓存。是否有任何方法可以优化此代码。基本上,代码对html页面进行调用,并计算出边界尺寸来设置浏览器宽度,从而使其适合pdf尺寸。这样做会一次又一次地调用html页面,但有人告诉我,如果它被缓存,它不会发出实际请求,而是读取缓存。必须有一种更简单的方法来实现这一点,因为渲染确实需要一段时间。当多个请求同时指向使用abcpdf的url时,似乎会发生此问题

            using (var doc = new Doc())
            {
                doc.HtmlOptions.Timeout = 60000;
                doc.HtmlOptions.PageCacheEnabled = true;
                doc.HtmlOptions.PageCacheExpiry = 600000;

                doc.HtmlOptions.Engine = Engine;
                doc.Rect.Inset(PageInsetHorizontal, PageInsetVertical);
                doc.Color.String = "255, 255, 255";

                const double heightTolerance = 18; // in points, the max allowed space at the bottom
                const int widthIncrement = 96; // in pixels, just an appropriate initial browser width increment
                var tallWidth = 0; // the lower browser width
                var wideWidth = 0; // the upper browser width
                Debug.WriteLine("Adding Url: " + Url);
                var id = doc.AddImageUrl(Url);
                var scrollWidth = doc.GetInfoInt(id, "ScrollWidth");
                var contentWidth = doc.GetInfoInt(id, "ContentWidth");
                var toContentWidth = contentWidth - scrollWidth;

                while (true)
                {
                    var width = doc.GetInfoInt(id, "ContentWidth");
                    var height = doc.GetInfoInt(id, "ContentHeight");

                    Debug.WriteLine("Initial Content Width: " + width);
                    Debug.WriteLine("Initial Content Height: " + height);

                    var tooTall = false;
                    var docScrollWidth = doc.GetInfoInt(id, "ScrollWidth");

                    Debug.WriteLine("Scroll Width: " + docScrollWidth);

                    if (docScrollWidth < scrollWidth)
                    {
                        scrollWidth = docScrollWidth;
                        contentWidth = scrollWidth + toContentWidth;

                        Debug.WriteLine("New Scroll Width: " + scrollWidth);
                        Debug.WriteLine("New Content Width: " + contentWidth);
                    }

                    Debug.WriteLine("Width: " + width);

                    if (width + 1 < contentWidth)
                    {
                        Debug.WriteLine("Too Tall: " + Url);
                        tooTall = true;
                    }
                    // assuming doc.Rect originally specifies the maximum bounding area
                    if (tooTall || doc.Rect.Width * height > doc.Rect.Height * width)
                    {
                        Debug.WriteLine("TOO TALL");
                        Debug.WriteLine("Delete Html: " + id);

                        // too tall
                        doc.Delete(id);

                        Debug.WriteLine("Browser Width: " + doc.HtmlOptions.BrowserWidth);

                        if (doc.HtmlOptions.BrowserWidth == 0)
                        {
                            doc.HtmlOptions.BrowserWidth = Convert.ToInt32(height*doc.Rect.Width/doc.Rect.Height);
                            Debug.WriteLine("New BrowserWidth: " + doc.HtmlOptions.BrowserWidth);
                        }
                        else
                        {
                            tallWidth = doc.HtmlOptions.BrowserWidth;

                            Debug.WriteLine("Tall Width: " + tallWidth);
                            Debug.WriteLine("Wide Width: " + wideWidth);

                            if (wideWidth == 0)
                            {
                                doc.HtmlOptions.BrowserWidth = tallWidth + widthIncrement;
                                Debug.WriteLine("New Browser Width: " + doc.HtmlOptions.BrowserWidth);
                            }
                            else if (tallWidth + 1 < wideWidth)
                            {
                                doc.HtmlOptions.BrowserWidth = (tallWidth + wideWidth)/2;
                                Debug.WriteLine("New Browser Width: " + doc.HtmlOptions.BrowserWidth);
                            }
                            else
                            {
                                doc.HtmlOptions.BrowserWidth = wideWidth;
                                Debug.WriteLine("New Browser Width: " + doc.HtmlOptions.BrowserWidth);
                                Debug.WriteLine("Adding Url: " + Url);
                                Debug.WriteLine("Found Fit");
                                doc.AddImageUrl(Url);
                                break;
                            }
                        }
                    }
                    else if (doc.Rect.Width * height < (doc.Rect.Height - heightTolerance) * width)
                    {
                        Debug.WriteLine("TOO WIDE");
                        Debug.WriteLine("Browser Width: " + doc.HtmlOptions.BrowserWidth);

                        // too wide
                        if (doc.HtmlOptions.BrowserWidth == 0)
                        {
                            doc.HtmlOptions.BrowserWidth = Convert.ToInt32(height * doc.Rect.Width / doc.Rect.Height);
                            Debug.WriteLine("New Browser Width: " + doc.HtmlOptions.BrowserWidth);
                        }
                        else
                        {
                            wideWidth = doc.HtmlOptions.BrowserWidth;

                            Debug.WriteLine("Tall Width: " + tallWidth);
                            Debug.WriteLine("Wide Width: " + wideWidth);

                            if (tallWidth == 0)
                            {
                                doc.HtmlOptions.BrowserWidth = wideWidth >= 2 * widthIncrement ? wideWidth - widthIncrement : wideWidth / 2;
                                Debug.WriteLine("New Browser Width: " + doc.HtmlOptions.BrowserWidth);
                            }
                            else if (tallWidth + 1 < wideWidth)
                            {
                                doc.HtmlOptions.BrowserWidth = (tallWidth + wideWidth)/2;
                                Debug.WriteLine("New Browser Width: " + doc.HtmlOptions.BrowserWidth);
                            }
                            else
                            {
                                Debug.WriteLine("Found Fit");

                                break;
                            }
                        }

                        Debug.WriteLine("Delete Html: " + id);

                        doc.Delete(id);
                    }
                    else
                        break;

                    Debug.WriteLine("Adding Url: " + Url);

                    id = doc.AddImageUrl(Url);
                }

                using (var ms = new MemoryStream())
                {
                    doc.Save(ms);
                    if (ms.CanSeek)
                    {
                        ms.Seek(0, SeekOrigin.Begin);
                    }
                    return ms.GetBuffer();
                }
            }
使用(var doc=new doc())
{
doc.HtmlOptions.Timeout=60000;
doc.HtmlOptions.PageCacheEnabled=true;
doc.HtmlOptions.pageCacheExpirement=600000;
doc.HtmlOptions.Engine=引擎;
doc.Rect.Inset(pageinserthorizontal,pageinsertvertical);
doc.Color.String=“255、255、255”;
const double heightTolerance=18;//以点为单位,底部允许的最大空间
const int widthIncrement=96;//以像素为单位,只是适当的初始浏览器宽度增量
var tallWidth=0;//浏览器的较低宽度
var wideWidth=0;//浏览器上部的宽度
Debug.WriteLine(“添加Url:+Url”);
var id=doc.AddImageUrl(Url);
var scrollWidth=doc.GetInfoInt(id,“scrollWidth”);
var contentWidth=doc.GetInfoInt(id,“contentWidth”);
var toContentWidth=contentWidth-scrollWidth;
while(true)
{
var-width=doc.GetInfoInt(id,“ContentWidth”);
var height=doc.GetInfoInt(id,“ContentHeight”);
Debug.WriteLine(“初始内容宽度:“+Width”);
Debug.WriteLine(“初始内容高度:“+Height”);
var-tooTall=false;
var docScrollWidth=doc.GetInfoInt(id,“ScrollWidth”);
Debug.WriteLine(“滚动宽度:+docScrollWidth”);
if(docScrollWidthdoc.Rect.height*Width)
{
Debug.WriteLine(“太高”);
Debug.WriteLine(“删除Html:+id”);
//太高
单据删除(id);
Debug.WriteLine(“浏览器宽度:+doc.HtmlOptions.BrowserWidth”);
如果(doc.HtmlOptions.BrowserWidth==0)
{
doc.HtmlOptions.BrowserWidth=Convert.ToInt32(高度*doc.Rect.Width/doc.Rect.height);
Debug.WriteLine(“新BrowserWidth:+doc.HtmlOptions.BrowserWidth”);
}
其他的
{
tallWidth=doc.HtmlOptions.BrowserWidth;
Debug.WriteLine(“高宽:+tallWidth”);
Debug.WriteLine(“宽宽度:+wideWidth”);
如果(宽度==0)
{
doc.HtmlOptions.BrowserWidth=tallWidth+widthIncrement;
Debug.WriteLine(“新浏览器宽度:+doc.HtmlOptions.BrowserWidth”);
}
否则如果(tallWidth+1using (var doc = new Doc())
{
  if(!EnableCache)
    doc.HtmlOptions.PageCacheClear();

    if (MakeLandscape)
    {
      var w = doc.MediaBox.Width;
      var h = doc.MediaBox.Height;
      var l = doc.MediaBox.Left;
      var b = doc.MediaBox.Bottom;

      doc.Transform.Rotate(90, l, b);
      doc.Transform.Translate(w, 0);

      doc.Rect.Width = h;
      doc.Rect.Height = w;
    }

    doc.HtmlOptions.Timeout = 60000;
    doc.HtmlOptions.PageCacheEnabled = EnableCache;
    doc.HtmlOptions.PageCacheExpiry = 600000;

    doc.HtmlOptions.Engine = Engine;
    doc.Rect.Inset(PageInsetHorizontal, PageInsetVertical);
    doc.Color.String = "255, 255, 255";

    doc.HtmlOptions.Paged = false;
    doc.HtmlOptions.BrowserWidth = (MakeLandscape ? PageWidth + PageInsetHorizontal : PageHeight + PageInsetVertical) * Convert.ToInt32(doc.Rect.Width / doc.Rect.Height);

    var id = doc.AddImageUrl(Url);

    if (MakeLandscape)
    {
      var scrollWidth = doc.GetInfoInt(id, "ScrollWidth");
      var contentWidth = doc.GetInfoInt(id, "ContentWidth");

      if (scrollWidth > contentWidth)
      {
        var scrollHeight = doc.GetInfoInt(id, "ScrollHeight");
        doc.Delete(id);
        doc.HtmlOptions.BrowserWidth = Convert.ToInt32(scrollHeight * doc.Rect.Width / doc.Rect.Height);

        id = doc.AddImageUrl(Url);
      }
    }
    else
    {
      var scrollHeight = doc.GetInfoInt(id, "ScrollHeight");
      var contentHeight = doc.GetInfoInt(id, "ContentHeight");

      if (scrollHeight > contentHeight + (PageInsetVertical *2))
      {
        var scrollWidth = doc.GetInfoInt(id, "ScrollWidth");
        doc.Delete(id);
        doc.HtmlOptions.BrowserWidth = Convert.ToInt32(((double)scrollHeight / contentHeight) * scrollWidth);
        id = doc.AddImageUrl(Url);
      }
    }

    if (MakeLandscape)
    {
      doc.SetInfo(doc.GetInfoInt(doc.Root, "Pages"), "/Rotate", "90");
    }

    using (var ms = new MemoryStream())
    {
      doc.Save(ms);
      if (ms.CanSeek)
      {
        ms.Seek(0, SeekOrigin.Begin);
      }
      return ms.GetBuffer();
    }
  }