|
Rank: Member Groups: Member
Joined: 1/16/2012 Posts: 17
|
As the subject states our issue is the ASPXToPDF1.RenderAsPDF(FileName); call works fine in Debug Mode(win 64bit) but as soon as our project is switched to Release mode we get the following error when trying to generate a PDF: Quote:Server Error in '/' Application. Value cannot be null. Parameter name: type Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: type
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null. Parameter name: type] System.Activator.CreateInstance(Type type, Boolean nonPublic) +12730854 EO.Web.ASPXToPDF.a(String A_0, Stream A_1) +68 EO.Web.Internal.mb.a(b[] A_0) +148 System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +754 System.Web.HttpResponse.FilterOutput() +121 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +168 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
I have tried: 1) I created a simple pdf.aspx with sample HTML in there (the same HTML that is created in the most simplistic instance of my broken page in question) - and it generates fine - no problem. Obviously really hard to figure out on my own when I cant debug it :) Any help would be appreciated.
|
|
Rank: Member Groups: Member
Joined: 1/16/2012 Posts: 17
|
UPDATE: I was able to get the exact same page working in Release mode by using EO.Pdf.HtmlToPdf.ConvertHtml instead: Quote: protected override void Render(HtmlTextWriter writer) { if (PrintPreview) { base.Render(writer); } else { EO.Pdf.HtmlToPdf.Options.BaseUrl = "MyURL"; var FileName = "FileNameHere"; EO.Pdf.Runtime.AddLicense("EOLicenseKey");
StringBuilder sb = new StringBuilder(); HtmlTextWriter tw = new HtmlTextWriter(new System.IO.StringWriter(sb)); //Render the page to the new HtmlTextWriter which actually writes to the stringbuilder base.Render(tw);
//Get the rendered content string sContent = sb.ToString();
//Create a new document PdfDocument doc = new PdfDocument(); EO.Pdf.HtmlToPdf.ConvertHtml(sContent, doc);
HttpResponse response = HttpContext.Current.Response; response.Clear(); response.ClearHeaders(); response.ContentType = "application/pdf"; response.AddHeader("content-disposition", "attachment;filename=" + FileName);
doc.Save(response.OutputStream);
response.End(); } }
Any other benifits of RenderAsPDF that would make me want to use it instead (besides being a lot less code)
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
The most important benefits for RenderAsPDF is it automatically intercepts the result HTML and then pass that HTML to ConvertHtml ---- basically the same thing that you did. It does appear that part failed in your application. Usually it fails when somebody else in the page that is also trying to do the same ---- for example, some AJAX panels (ASP.NET UpdatePanel should be fine) also need to intercept page output.
In addition to capturing HTML, RenderAsPDF also automatically set HtmlToPdf.Options.BaseUrl. This is important if your page also has images.
Hope this helps. If you can identify what in your page triggered the problem, we would be happy to look into it and see if we can make sense out it.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/16/2012 Posts: 17
|
OK thanks for the quick response and info. We utilize a series of custom controls so it probably is the AJAX panel collision you mention. I just found it odd that is only blows in RELEASE mode. We will stick with the long hand version then - in the long run probably would have to use it anyway for finer control.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Yes. The long hand version does give you ultimiate control on everything.
Please feel free to let us know if you need anything else.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/16/2012 Posts: 17
|
One last thing - I think this code sample should be in your web example download. Having your other product (Web Control Downloader) mixed in the sample slowed me down and caused me confusion on were the generic code ended and your EO.Web calls kicked in - if nothing else add the explicit path to the calls.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Thank you very much for the feedback. We will think about it. We have users of all levels ---- some are advanced users as you that would rather go straight to the real thing, while many others are more used to drag and drop, click and point and do not want to deal with much code at all. Thus one of the priorities of the samples is to show user a working solution with the least amount of code. Maybe we can add different samples that targeting different user levels --- some with the least amount of code, some with more code and more flexibilities, etc.
|
|