Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Sep 24, 2014 8:42 pm

Hi I'm using LoadFromHTML to generate a pdf of an HTML response. In most cases this is working well but many times some of the images are not rendered to the page at all. Is there a way to set a delay to allow the image to be downloaded fully or is there some other problem that might be causing this?

Here is the bulk of the code. The images are there because they are displayed on the same page that the download to pdf button is on and they display some of the time.

Any assistance would be appreciated.

Code: Select all
var t = new Thread(() =>
                {
                    try
                    {
                        using (var doc = new PdfDocument())
                        {
                            var format = new PdfHtmlLayoutFormat()
                            {
                                FitToPage = Clip.None,
                                FitToHtml = Clip.None,
                                Layout = PdfLayoutType.OnePage
                            };
                            var settings = new PdfPageSettings(PdfPageOrientation.Portrait)
                            {
                                Size = PdfPageSize.A3,
                                Margins = new PdfMargins(10, 30)
                            };
                            doc.LoadFromHTML(html, true, settings, format);
                            doc.DocumentInformation.Author = "blah";
                            doc.DocumentInformation.CreationDate = DateTime.Now;
                            string fileName = "Filename.pdf";
                            doc.SaveToHttpResponse(fileName, response, HttpReadType.Save);
                            doc.Close();
                        }
                        // There is a memory leak on the nuget version of this library...
                        // GC.Collect();
                    }
                    catch (Exception ex)
                    {
                        response.ContentType = "text/html";
                        viewBag.Message = ex.ToString();
                    }
                });
                t.SetApartmentState(ApartmentState.STA);
                // synchronous execution
                t.Start();
                t.Join();

drewg
 
Posts: 5
Joined: Mon Sep 22, 2014 4:30 pm

Thu Sep 25, 2014 3:45 am

Dear drewg,

Thanks for your inquiry.

Yes. You can set these two properties that might help you:
Code: Select all
PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat
{
     //........
     IsWaiting=true,
     LoadHtmlTimeout=30000 //Default is 30000
};

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Sep 26, 2014 7:57 am

Dear drewg,

Has your problem been resolved?
If not, please send your html file to help us resolve your problem.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Thu Oct 16, 2014 4:28 pm

Thanks for your response. No this does not seem to fix the problem. I have set the timeout all the way up to 50000 and the pdf still loads at the same speed and some images may or may not be drawn.

This is a business project that I cant post publicly. I'll need an address to email you the HTML.

drewg
 
Posts: 5
Joined: Mon Sep 22, 2014 4:30 pm

Fri Oct 17, 2014 1:06 am

Dear drewg,

Please send the document and code snippet to burning.liu@e-iceblue.com.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Oct 17, 2014 4:20 am

burning.liu wrote:Dear drewg,

Please send the document and code snippet to burning.liu@e-iceblue.com.

Best regards,
Burning
E-iceblue Support Team


Ok I have emailed you the html and a basic code snippet that should reproduce if you run it a couple times. Thanks!

drewg
 
Posts: 5
Joined: Mon Sep 22, 2014 4:30 pm

Fri Oct 17, 2014 9:36 am

Dear Drew,

Thanks for your code snippet and html file.

I'm sorry that I cannot reproduce the issue you encountered.
For the code snippet and html file, I used two different way to load html(one is load original html file, the other is load html source code) which got the same result: the result pdf file is ok, no image missing.

Also I tried them several times(5+) and they turned out to be ok. Perhaps it is something about the system infomation.
Would you mind sending us your develop information and system information to help us reproduce this issue?

Best Regards,
Burning
E-iceblue support team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Oct 17, 2014 1:59 pm

burning.liu wrote:Dear Drew,

Thanks for your code snippet and html file.

I'm sorry that I cannot reproduce the issue you encountered.
For the code snippet and html file, I used two different way to load html(one is load original html file, the other is load html source code) which got the same result: the result pdf file is ok, no image missing.

Also I tried them several times(5+) and they turned out to be ok. Perhaps it is something about the system infomation.
Would you mind sending us your develop information and system information to help us reproduce this issue?

Best Regards,
Burning
E-iceblue support team


I guess I over simplified my example then.. I'll send you a sample project which reproduces the issue.

drewg
 
Posts: 5
Joined: Mon Sep 22, 2014 4:30 pm

Sat Oct 18, 2014 12:43 am

After setting up a separate project I have noted that this only happens when run on a server. I have tried it on 3 different Windows 2012 Servers with the same results. In the end, I think we will use wkhtml for the conversion and spire for manually drawing headers and footers, watermarks, etc.

drewg
 
Posts: 5
Joined: Mon Sep 22, 2014 4:30 pm

Mon Oct 20, 2014 1:14 am

Dear drewg,

Thanks for your reply.
Please feel free to contact us if you have any problems.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Return to Spire.PDF