Welcome Guest Search | Active Topics | Sign In | Register

Inconsistent Crashing (in EO.Pdf) Options
CWoods
Posted: Thursday, August 7, 2014 1:10:09 PM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 40
I'm noticing some inconsistent behavior with EO.Pdf (v5.0.87.2). I'm reading the HTML file to convert into a string buffer and then appending another file (containing Javascript that I want to execute in order to modify the HTML before printing) and then calling HtmlToPdf.ConvertHtml(). This was failing (even though it works in the browsers) with various error messages and so I was trying to determine why by cutting down my script file and then trying to reinstate content until it fails (i.e. divide and conquer).

What I've discovered while doing this though is inconsistent behavior in that for a given fixed input file and script file, successive executions of my test application give me one of three different results!

Result #1
[0.00:00:00.0010] 461753 bytes of content from file: C:\Temp\Test.html
[0.00:00:00.0020] 3076 bytes of content from footer: C:\Temp\Footer.js
[0.00:00:00.0020] 464829 total bytes to convert...
[0.00:00:35.0600] Conversion Completed!

Result #2
[0.00:00:00.0000] 461753 bytes of content from file: C:\Temp\Test.html
[0.00:00:00.0010] 3076 bytes of content from footer: C:\Temp\Footer.js
[0.00:00:00.0010] 464829 total bytes to convert...
[0.00:00:28.0266] EO.Pdf.HtmlToPdfException: Convertion failed. Unable to read beyond the end of the stream. ---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.MemoryStream.InternalReadInt32()
at EO.Pdf.Internal.bg.a(Byte[] A_0, Single A_1, Single A_2, Single A_3, Single& A_4, Double A_5, Double A_6)
at EO.Pdf.Internal.lu.a(String A_0, Single& A_1)
at EO.Pdf.Internal.lu.d()
--- End of inner exception stack trace ---
at EO.Pdf.HtmlToPdfException.b(Exception A_0)
at EO.Pdf.Internal.lu.d()
at EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc, HtmlToPdfOptions options)
at ProblemWithAppendingScript.Program.Main(String[] args) in c:\Projects\Source\ThrowAways\ProblemWithAppendingScript\Program.cs:line 81

Result #3
[0.00:00:00.0000] 461753 bytes of content from file: C:\Temp\Test.html
[0.00:00:00.0010] 3076 bytes of content from footer: C:\Temp\Footer.js
[0.00:00:00.0010] 464829 total bytes to convert...
[0.00:00:24.2613] EO.Pdf.HtmlToPdfException: Convertion failed. This session is no longer valid. If you wish to reuse the session later, please consider calling GetCookies to retain the session cookies, then reuse these cookies through HtmlToPdfOptions.Cookies with another session. (5) ---> EO.Pdf.Internal.k0: This session is no longer valid. If you wish to reuse the session later, please consider calling GetCookies to retain the session cookies, then reuse these cookies through HtmlToPdfOptions.Cookies with another session. (5)
at EO.Pdf.Internal.ln.l()
at EO.Pdf.Internal.ln.a(a A_0)
at EO.Pdf.HtmlToPdfSession.a(a A_0)
at EO.Pdf.Internal.lu.a(String A_0, Single& A_1)
at EO.Pdf.Internal.lu.d()
--- End of inner exception stack trace ---
at EO.Pdf.HtmlToPdfException.b(Exception A_0)
at EO.Pdf.Internal.lu.d()
at EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc, HtmlToPdfOptions options)
at ProblemWithAppendingScript.Program.Main(String[] args) in c:\Projects\Source\ThrowAways\ProblemWithAppendingScript\Program.cs:line 81

I've also noticed that if the last statement in the JavaScript ends with a semi-colon (;) character, in addition to the three results above, I've also seen a fourth result as well:

Result #4
[0.00:00:00.0000] 461753 bytes of content from file: C:\Temp\Test.html
[0.00:00:00.0010] 1955 bytes of content from footer: C:\Temp\Footer2.js
[0.00:00:00.0010] 463708 total bytes to convert...
[0.00:00:24.9204] EO.Pdf.HtmlToPdfException: Exception of type 'System.OutOfMemoryException' was thrown.
at EO.Pdf.HtmlToPdfException.b(Exception A_0)
at EO.Pdf.Internal.lu.d()
at EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc, HtmlToPdfOptions options)
at ProblemWithAppendingScript.Program.Main(String[] args) in c:\Projects\Source\ThrowAways\ProblemWithAppendingScript\Program.cs:line 80

My test application is built with VS2012 targeting .NET 4.5, Any CPU (uncheck Prefer 32-bit) and run on Window 7 64-bit.

I will follow this post with an e-mail containing the test project as I know that you'll need this to try and reproduce the errors.
eo_support
Posted: Friday, August 8, 2014 3:10:08 PM
Rank: Administration
Groups: Administration

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

We have looked into this problem. All the four different results are in fact the same as result #4. The root of the problem is you have a few large pictures in your HTML page. One of them particularly (PAGE14 at the end of your file) is more than 5000 pixels wide. This effectively increased the page width 10 folds (the default page width is 6.5 inch * 72 DPI = 468 pixels), this basically increase the page screen buffer 10 folds and significantly increase the memory needed for the conversion. This combine with the size of your HTML file causes out of memory error and crashes the conversion engine.

The reason that you receive different error messages is because the crash can occurs at random locations. If the out of memory exception occurred while executing managed code, then the engine can catch it and send a clear error message back (#4). However if it occurred while executing unmannaged code, then it just crashes and depends on the exact location of the crash, you will get different error message.

I would recommend you to scale down those images to avoid such errors. There is no silver bullet for us to fix a crash caused by out of memory --- particularly if it occurs in unmanaged code.

Hope this helps.

Thanks!
CWoods
Posted: Friday, August 8, 2014 3:47:44 PM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 40
The HTML file alone must be just under the memory limits then as I could never get it to crash if I didn't tack on any script at all...

The irony here is that the [full] script is being added in part to actually scale down any images wider than 2x the page width. We don't author most of these files so we don't have control over the files. I noticed for some files that the text was scaled down way too much due to ridiculously wide images and brought this up with Jack via e-mail previously. He suggested the JavaScript approach to check image sizes and resize.

Any suggestions as to another alternative?

Any way to say add a new HtmlToPdfOptions that would say pass to the browser a max screen width to cap rendering?
Or maybe add a "HtmlToPdfAutoFitMode.ShrinkToFitIgnoringImages" that would scale based on non-image widths?

...
eo_support
Posted: Friday, August 8, 2014 5:36:00 PM
Rank: Administration
Groups: Administration

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

You can try to increase HtmlToPdf.Options.MinWaitTime to give your JavaScript some time to run and see if that works. Theoretically if the JavaScript is given enough time to run, it will reduce the amount of memory consumed during the conversion. However please keep in mind that the big images are still in the memory even if you scale it down with JavaScript, so as soon as you have huge images like this, you can still run into memory problems.

Thanks!
CWoods
Posted: Thursday, August 14, 2014 11:54:11 AM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 40
Increasing the MinWaitTime isn't going to help here. The footer in the test project that I sent via e-mail did not even have all of the code in it and wasn't actually even getting called to be executed...

What about a new setting to cap max screen width? Would that be possible? That would keep the buffers smaller and at least allow the rest of the document to be reasonably layed out/rendered/resized. Content over that max would still get resized as part of the shrink to fit but whatever doesn't actually fit on the page would just "fall off the page".
eo_support
Posted: Thursday, August 14, 2014 4:07:58 PM
Rank: Administration
Groups: Administration

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

It's not as simple as that. The engine always layout all contents at the full size first. Only after that it can decide what to do. So I do not believe a cap max screen width will resolve the problem for you.

Thanks
CWoods
Posted: Thursday, August 14, 2014 6:00:59 PM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 40
It's never "as simple as" :)

I just didn't know what information you pass down to the engine to start with - i.e. maybe some dimensions of a "virtual" browser window - that might be able to be exposed/controlled. Something like that would allow most of the content to stay constrained within a reasonable limit and then that limit would be the upper bound to use in the fit calculations as well.

I'd had some discussions about this previously via e-mail but it was focused on limiting the zoom/fit. That wouldn't work in this case because the layout of the HTML is using the whole width of these crazy wide images - so limiting zoom wouldn't be effective as lots of textual content would have fallen off.

Whereas this is more about limiting the "virtual window" that the engine is using for layout/rendering to so that the layout/rendering is more reasonable (and then letting the rest fall off) and the resulting fit therefore doesn't have to do some crazy zoom/scale factor to get the contents to fit the page (excluding the crazy wide images).
eo_support
Posted: Thursday, August 14, 2014 9:42:39 PM
Rank: Administration
Groups: Administration

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

We understand that you want our product to work with potentially huge images but we feel that you are really asking for the impossible. It's like we make 4 seats passenger car but you insist that it has to fit 10 people. The reason that the car only sits 4 are tied to a lot of factors, the engine size, the frame, etc. So it's not possible for us to flip a switch and magically make it fit 10 people. Besides, in order to maintain a stable product, we can not afford to tweak our product to fit individual extreme scenarios. So please consider this issue closed. We apologize that we can not accommodate your specific scenario at this time.

Thanks!
CWoods
Posted: Friday, August 15, 2014 9:27:03 AM
Rank: Advanced Member
Groups: Member

Joined: 7/14/2014
Posts: 40
Actually what it's currently doing is stuffing 10 people into a 4 person car. I just want the car to fit 4-6 people even though 10 want to climb in... those other four people just have to wait.

Issue closed.
eo_support
Posted: Friday, August 15, 2014 10:49:56 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
We appreciate you understanding on this matter and once again we are sorry that we were not able to accommodate your specific scenario. Please feel free to let us know if there is anything else.

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.