tuespetre / TuesPechkin

A .NET wrapper for the wkhtmltopdf library with an object-oriented API.
326 stars 116 forks source link

Random results when adding many objects to HtmlToPdfDocument #167

Closed MacMcDell closed 6 years ago

MacMcDell commented 6 years ago

Howdy. Been a long time since I pulled out this library. Wondering if I am doing something wrong here.. I am adding a bunch of objects to a single document to return a very large byte[] sometimes 250mb. here is the method

 public static byte[] ConvertPagesToPdf(List<string> urls)
        {
            var  webSettings = new WebSettings()
            {
                PrintBackground = true,
                LoadImages = true,
                EnableJavascript = true,
                EnablePlugins = false,
            };

           var document = new HtmlToPdfDocument
            {
                GlobalSettings = globalSettings //this is just a static property
            };

            List<ObjectSettings> objects = new List<ObjectSettings>();
            foreach (var url in urls) //Assume maybe 60 urls possible some of them 15mb in size
            {
                document.Objects.Add(new ObjectSettings(){PageUrl = url, WebSettings = webSettings});
            }

           byte[] result = converter.Convert(document);
            return result;
        }

When i do not include my obnoxiously large images I get the correct number of pages back. 64 urls, 64 pages. When I include the massive images I end up with random pages.. sometimes 10, sometimes 15. Is there a way to pause and wait for the page to finish loading?

I should note I am running this from localhost / webforms project. As such I am using

private static IConverter converter =
               new ThreadSafeConverter(
                   new RemotingToolset<PdfToolset>(
                       new Win32EmbeddedDeployment(
                           new TempFolderDeployment())));
MacMcDell commented 6 years ago

I am pretty sure this problem is related to the images being monstrous. after scaling them the problems wend away.