Welcome Guest Search | Active Topics | Sign In | Register

EO.Pdf.net and memory usage Options
Bernard
Posted: Monday, April 14, 2014 4:25:35 PM
Rank: Newbie
Groups: Member

Joined: 4/14/2014
Posts: 5
HI,
I am testing your product in a Web MVC application, on the shared hosting cloud server. (300 MB memory).
Method call here:

public bool CreatePDFFromUrl(String pUrlToConvert, String pPdfFilePhysicalPath, HttpContextBase pContext)
{
bool rValue = false;

HtmlToPdf.Options.PageSize = EO.Pdf.PdfPageSizes.Letter;
HtmlToPdf.Options.ZoomLevel = 95f;
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ScaleToFit;
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.None;

HtmlToPdf.Options.OutputArea = new RectangleF(0f, 0f, 8.5f, 11.5f);
HtmlToPdf.Options.RepeatTableHeaderAndFooter = false;
using (FileStream fs = File.Create(pPdfFilePhysicalPath, 1024, FileOptions.None))
{
EO.Pdf.HtmlToPdf.ConvertUrl(pUrlToConvert, fs);
rValue = true;
}
return rValue;

}
It works great in my dev machine, but get an out of memory exception on the shared cloud server. The pdf I am generating is 130 kb. So it is normal that I do not have enough with 300 MB memory for a so small pdf ?. I am the only one using the application on the shared hosting.
Thanks for your help.
eo_support
Posted: Monday, April 14, 2014 8:39:19 PM
Rank: Administration
Groups: Administration

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

That's probably not really an out of memory exception considering the relatively small size of the PDF file. Even if your server only has 300MB physical memory (which indeed is low of course), you still have 4GB logical memory space. When you are low on physical memory, Windows does disk/memory swap to satisfy memory allocation request, which basically runs things on disk instead of in memory. The net result is that everything becomes very slow but the benefit is so that your application won't get out of memory exception.

I would recommend you to check the full stack trace of the out of memory error. Particularly GDI+ is notorious for throw out of memory exception when the problem is something else. So if you can post the full stack trace of the error, we will look into it and see if we can figure out anything.

Thanks!
Bernard
Posted: Tuesday, April 15, 2014 8:40:05 AM
Rank: Newbie
Groups: Member

Joined: 4/14/2014
Posts: 5
Hi,
this is what I got from my logging email error:

Gallery Error - Convertion failed. System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Drawing.Graphics.FromHdc(IntPtr hdc) at EO.Pdf.Internal.df..ctor(Boolean A_0) at EO.Pdf.Internal.c8.a(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.b(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.a(hf A_0) at EO.Pdf.Internal.ln.c.a(hf A_0) at EO.Pdf.Internal.ln.c.a(Byte[] A_0)
Error information
Name Value
Message Convertion failed. System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Drawing.Graphics.FromHdc(IntPtr hdc) at EO.Pdf.Internal.df..ctor(Boolean A_0) at EO.Pdf.Internal.c8.a(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.b(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.a(hf A_0) at EO.Pdf.Internal.ln.c.a(hf A_0) at EO.Pdf.Internal.ln.c.a(Byte[] A_0)
Source EO.Pdf
TargetSite EO.Pdf.Internal.ln a(EO.Pdf.Internal.hf)
StackTrace at EO.Pdf.Internal.ln.a(hf A_0) at EO.Pdf.HtmlToPdfSession..ctor(HtmlToPdfOptions A_0) at EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc, HtmlToPdfOptions options) at EO.Pdf.HtmlToPdf.ConvertHtml(String html, String pdfFileName, HtmlToPdfOptions options) at KiskiBL.Tools.EOPdfMng.CreatePDFFromUrl(String pUrlToConvert, String pPdfFilePhysicalPath, HttpContextBase pContext) at KiskiBL.Tools.EOPdfMng.DownloadAsAttachementMvc(String pUrlToConvert, String pVirtualPath, HttpContextBase pContext) at KiskiWebApps.Areas.Admin.Controllers.PdfController.DownloadHuntReservation(Nullable`1 pId, Nullable`1 pLangId)
Base Exception (type) System.Exception
Base Exception (Message) System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Drawing.Graphics.FromHdc(IntPtr hdc) at EO.Pdf.Internal.df..ctor(Boolean A_0) at EO.Pdf.Internal.c8.a(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.b(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.a(hf A_0) at EO.Pdf.Internal.ln.c.a(hf A_0) at EO.Pdf.Internal.ln.c.a(Byte[] A_0)
Base Exception (StackTrace) at EO.Pdf.Internal.a.b(BinaryReader A_0) at EO.Pdf.Internal.ln.a(a A_0) at EO.Pdf.Internal.ln.a(ln A_0, a A_1) at EO.Pdf.Internal.ln.a(hf A_0, Boolean A_1) at EO.Pdf.Internal.ln.a(hf A_0)
Base Exception (Source) EO.Pdf
Inner Exception (type) System.Exception
Inner Exception (Message) System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Drawing.Graphics.FromHdc(IntPtr hdc) at EO.Pdf.Internal.df..ctor(Boolean A_0) at EO.Pdf.Internal.c8.a(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.b(HtmlToPdfOptions A_0, String A_1, Boolean A_2) at EO.Pdf.Internal.c8.a(hf A_0) at EO.Pdf.Internal.ln.c.a(hf A_0) at EO.Pdf.Internal.ln.c.a(Byte[] A_0)
Inner Exception (StackTrace) at EO.Pdf.Internal.a.b(BinaryReader A_0) at EO.Pdf.Internal.ln.a(a A_0) at EO.Pdf.Internal.ln.a(ln A_0, a A_1) at EO.Pdf.Internal.ln.a(hf A_0, Boolean A_1) at EO.Pdf.Internal.ln.a(hf A_0)
Inner Exception (Source) EO.Pdf


Hope this can help.
Thanks a lot.
eo_support
Posted: Tuesday, April 15, 2014 11:31:14 AM
Rank: Administration
Groups: Administration

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

Thanks for the additional information. We have located the corresponding source code of this error. The root of the problem is that we are calling Graphics.FromHdc using a screen HDC, which might cause GDI+ trying to allocate some screen buffer and fails due to limited resource on your system (we were not able to reproduce and verify this theory though). GDI+ is notorious for throwing out of memory error whenever it can not complete something successfully due to whatever reason.

A code review indicated that it is not necessary to call Graphics.FromHdc in this particular case. So we will make the change and provide a new build either today or tomorrow without this call --- that may not resolve the issue for you completely but if you run into another error, you can post the stack trace again and then we can then go from there. And if it still fails at the same place, we might be able to get a more specific error message/code that can bring us closer to the real problem.

We will post again when we have the new build.

Thanks!
Bernard
Posted: Tuesday, April 15, 2014 11:44:37 AM
Rank: Newbie
Groups: Member

Joined: 4/14/2014
Posts: 5
Ok thanks very much, I will wait for your new build. This can be a great help for all users within a cloud hosting with limited memory.
I am currently with Everleap Cloud: http://www.everleap.com (basic Cloud web sites)
eo_support
Posted: Tuesday, April 15, 2014 11:52:31 AM
Rank: Administration
Groups: Administration

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

You are very welcome. We do not know their specific yet. In addition to resource constrains, it is not uncommon that a cloud environment restricts certain permissions that might cause the application to fail (since the HTML to PDF makes a lot of low level API calls). So at this point we do not know whether it will eventually work for you or not in such environment. However we will work with you closely to find out the root of the problem and hopefully that will give you a definite answer very soon.

Thanks!
eo_support
Posted: Thursday, April 17, 2014 2:22:47 AM
Rank: Administration
Groups: Administration

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

We have posted a new build. Please see your private message for the download location.

Thanks!
Bernard
Posted: Thursday, April 17, 2014 9:29:22 AM
Rank: Newbie
Groups: Member

Joined: 4/14/2014
Posts: 5
Hi,
I make a try with the new build, unfortunately I got the same error:
I tried with very simple code in an MVC action , so the "out of memory" should not be the real problem like you mentioned.


public ActionResult TestPDF()
{

HtmlToPdf.Options.PageSize = EO.Pdf.PdfPageSizes.Letter;
HtmlToPdf.Options.OutputArea = new RectangleF(0f, 0f, 8.5f, 11.5f);

string htmlCode = @"<div style=""width:300px; margin:50px auto; font-size:20px"">Hello World</div>";
string pdfPath = this.Request.MapPath("~/pdfs/testSimpleHtml.pdf");
HtmlToPdf.ConvertHtml(htmlCode, pdfPath);

return new ContentResult();


}
Thanks very much for your time. Please let me know if you have some other solutions to test.
I will try to get some hints from the hosting team.

Stack trace:

[OutOfMemoryException: Out of memory.]
System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) +1149345
System.Drawing.Font.ToLogFont(Object logFont) +145
System.Drawing.Font.ToHfont() +98
EO.Pdf.Internal.el.a(j3 A_0) +85
EO.Pdf.Internal.el.b(j3 A_0) +177
EO.Pdf.Drawing.PdfFont..ctor(j3 A_0, Single A_1) +31
EO.Pdf.Internal.fn.b(ka A_0) +542
EO.Pdf.Internal.fn.a(j7[] A_0) +161
EO.Pdf.Internal.fn..ctor(lu A_0, Boolean A_1, Int32 A_2, kv A_3, Int32 A_4, Single A_5, Rectangle A_6, PdfPage A_7, d0 A_8, Int32 A_9, Graphics A_10, Dictionary`2 A_11) +1087
EO.Pdf.Internal.lu.a(PdfPage A_0, Boolean A_1, Int32 A_2, Rectangle A_3, kv A_4, ha A_5, Int32& A_6, Graphics A_7) +1133
EO.Pdf.Internal.lu.a(Int32 A_0, HtmlToPdfResult A_1, Int32& A_2) +2770
EO.Pdf.Internal.lu.d() +263

[HtmlToPdfException: Convertion failed. Out of memory.]
EO.Pdf.HtmlToPdfException.b(Exception A_0) +65
EO.Pdf.Internal.lu.d() +1282
EO.Pdf.HtmlToPdfSession.RenderAsPDF(PdfDocument doc) +55
EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc, HtmlToPdfOptions options) +105
EO.Pdf.HtmlToPdf.ConvertHtml(String html, String pdfFileName, HtmlToPdfOptions options) +50
KiskiWebApps.Areas.Admin.Controllers.PdfController.TestPDF() +152
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +156
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +50
System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +225
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690164
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155



eo_support
Posted: Thursday, April 17, 2014 10:17:02 AM
Rank: Administration
Groups: Administration

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

I do not know what system everleap uses to power their cloud website. However you might run into the same problem as Windows Azure WebSite user. Windows Azure offers several level of services: shared WebSite, Cloud Services (Roles) and Virtual Machine. You will run into this error if you use Windows Azure Shared WebSite because our product uses GDI and GDI is not well supported on Azure Shared WebSite. The only solution for this problem is to move to Azure Cloud Services or Virtual Machine. You can search online for Azure and FromHdcInternal you will see many third party products run into this problem. So you may want to confirm with everleap to see if their Shared WebSite is indeed Azure WebSite.

Thanks!
Bernard
Posted: Thursday, April 17, 2014 3:09:12 PM
Rank: Newbie
Groups: Member

Joined: 4/14/2014
Posts: 5
Hi,
Everleap confirms me that they use the exact same underlying technology as with Azure websites. :-(

Thanks very much for your time!
Bernard.
eo_support
Posted: Thursday, April 17, 2014 4:11:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
You are very welcome. I am sorry that even though the root of the problem has been identified but it still won't work in your environment. You might want to consider Azure Cloud service or Virtual Machine since this WebSite limitation affects pretty much everyone.

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.