Welcome Guest Search | Active Topics | Sign In | Register

ConvertHtml performance with images Options
Brian
Posted: Wednesday, March 26, 2014 7:15:04 PM
Rank: Newbie
Groups: Member

Joined: 3/26/2014
Posts: 3
Hello,

We have a simple method that converts an HTML document to PDF using the ConvertHtml method. When there are no images present in the HTML, the document is created almost instantly. When there are images, however, it consistently takes 3 minutes for the document to convert. The HTML document itself is small and results in a 1/2 to 1 page PDF. The image that is being loaded is also extremely small (just over 1k). After the 3 minutes, the PDF renders perfectly.

I'm not sure if it matters, but we're setting the path to the image to something like https://servername.com/images/image.gif instead of the actual path on the server's file system.

Here's the code we're using:

Code: C#
private byte[] ConvertHTMLToPDF(string textWriter)
        {
            EO.Pdf.HtmlToPdfOptions options = new EO.Pdf.HtmlToPdfOptions();
            options.FooterHtmlFormat = "<div style=\"text-align:right\">Page {page_number}</div>";
			
            System.IO.MemoryStream mm = new System.IO.MemoryStream();
			
			EO.Pdf.PdfDocument doc = new EO.Pdf.PdfDocument();
			EO.Pdf.HtmlToPdfResult result = EO.Pdf.HtmlToPdf.ConvertHtml(textWriter, doc);
			
			doc.Save(mm);
            byte[] barray = mm.ToArray();
            return barray;
}


This seems like it might be a networking issue, but there is nothing in the IIS logs and the image URL can be loaded successfully in the browser with no issues or delays. Any ideas what we might be missing here?

Any help would be greatly appreciated. Thanks!
eo_support
Posted: Wednesday, March 26, 2014 7:37:09 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

This is almost certainly a network or server issue. There are two most common scenarios. One is DNS error. See here for more details:

http://www.essentialobjects.com/doc/4/web/troubleshoot.aspx

Another scenario is the ASP.NET session lock. ASP.NET holds a session lock so that inside the same page you don't have to worry about synchronizations when accessing session variables. A typical deadlock scenario is like this:

1. You request page A (request A), ASP.NET acquires the session lock for request A;
2. Inside page A's code you request page B (request B), now ASP.NET tries to get the lock for request B;
3. It can not get the lock for request B because request A currently has it. So it has to wait for request A to finish;
4. Request A can't finish because your code is waiting for request B to finish in order to continue;

Now you have a deadlock. Eventually the deadlock will be able to resolve itself due to time out. The session lock issue does not happen as often as the DNS issue because in order for the deadlock to happen, request A and request B must belong to the same session (for example, carry the same session cookie), which usually does not happen automatically. While ASP.NET does hold session lock for multiple requests for the same session, it does not hold lock between multiple sessions (So that multiple sessions can be freely served by multiple threads, which is essential for a server application).

Your scenario looks more like a DNS issue since you mentioned there is nothing in IIS log. So I would recommend you to check that first.

Thanks!
Brian
Posted: Thursday, March 27, 2014 7:53:42 PM
Rank: Newbie
Groups: Member

Joined: 3/26/2014
Posts: 3
Thank you for the quick reply!

In reading the potential issues with the DNS, it seemed like that might be the issue. Unfortunately, when I log directly onto the web server and try to access the image using the same URL that is in the HTML, it works just fine. The image is accessible from the web server as well as from other machines. Also, the really strange thing is that the images *will* show up in the PDF file...it just takes almost exactly 3 minutes to render. It would almost make more sense if they failed to show up at all.

Any other areas I should be looking at?

Thanks again!
eo_support
Posted: Thursday, March 27, 2014 9:36:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Is your image served dynamically? Maybe it's in the image serving code? You can try to change it to a separate static image, or even an image from other servers to see if it works differently.
Brian
Posted: Friday, March 28, 2014 10:03:36 AM
Rank: Newbie
Groups: Member

Joined: 3/26/2014
Posts: 3
The method just takes a string that contains raw HTML (see below). Before the string gets to the method, there is some text-replacement code that replaces the text in square brackets with "real" data. The below HTML (minus the replacement text) is exactly what string the method receives. If the <img> tag is there, it takes 3 minutes to render, if it's not here, it renders in a matter of seconds.

I think I mentioned above that the path to the image was a web url...my mistake, it turns out it's actually the physical path on the file system. I'm not sure if that matters at all, but I thought I'd mention it.

Code: HTML/ASPX
<html>
	<body>
		<p>Purpose: [LoanPurpose]</p>
		<p>Status: [ApplicationStatus]</p>
		<p>MC Link: [MessageCenterLink]</p>
		<table width="100%">
			<tbody>
				<tr>
					<td><strong>[ProductName]</strong></td>
					<td style="text-align: right;">[Date]</td>
				</tr>
			</tbody>
		</table>
		<p>[BorrowerName]</p>
		<p>The following are the current to-do list items.</p>
		<h1 style="color: #4f6f19">To-Do List</h1>
		<h2 style="color: #4f6f19">Open</h2>
		[OpenToDoItems]
		<h2 style="color: #4f6f19">Completed</h2>
		<p>[CompletedToDoItems]</p>
		<img src="E:\physical_path_to_image_on_server\ncua.jpg" />
	</body>
</html>
eo_support
Posted: Friday, March 28, 2014 10:22:03 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

That doesn't make any sense at all unless your image is huge (please check the resolution and size of the image file). Are you sure it's ConvertHtml that's taking exactly 3 minutes? Do you have other JavaScript/invalid HTML/images in your HTML? The converter will try to wait for everything to be loaded in the HTML before starting conversion. So for example, if your HTML has two images, with one being your main image and another being an insignificant image (such as a 1 by 1 "spacer" image), then even if the main image loads fine very quickly but the spacer image is not, then that image can hold the whole thing up. You also want to check whether the image is on a network mapping drive or it is on a local drive. And do you get the same result if you run the same code on a different machine or under a different user account (for example, under an interactive user)?

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.