EO.PDF 2013
Visual Studio 2010 SP1
Windows 7 SP1
We have been trying to use your MVC to PDF functionality so far without success.
First approachWe tried
[RenderAsPDF(AutoConvert=false)]
//Trigger the conversion only when m.ExportToPDF is true
if (m.ExportToPDF)
{
string filename = string.Format("{0} {1}", brandTitle, model.Subtitle);
MVCToPDF.ResultFileName = filename;
MVCToPDF.RenderAsPDF();
}
First problem
We have some custom icons that produce this error
System.Exception was unhandled
HResult=-2146233088
Message=The font file 'icomoon' does not have 'glyf' or 'loca' table. Please check whether the file is a true type font file. EO.Pdf does not support post script font file.
Source=EO.Pdf
StackTrace:
at EO.Pdf.Internal.lr.a(Object A_0, ThreadExceptionEventArgs A_1)
at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
We have temporarily set them to Arial but then...
Second problem is that we are using
Cassette | Asset bundling for .NET web apps
http://getcassette.net/In the Web.Config file we require this setting
<cassette rewriteHtml="true" />
http://getcassette.net/documentation/v2/web-config"When true (the default), Cassette will rewrite HTML page output to allow bundles to be referenced in the <head> even after it has been rendered."
However, this does not play nicely with MVCToPDF and we lose all our styling. Setting it to false gets round this issue but is not ideal. Is there a way of getting your tool to play nicely with Cassette?
Second approachWe tried HtmlToPdf.ConvertHtml()
// Grab the html from the view
string html = RenderViewToString(this, "Area", model);
The above call is
private string RenderViewToString(Controller controller, string viewName, object model)
{
controller.ViewData.Model = model;
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindView(controller.ControllerContext, viewName, "_Layout");
ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.ToString();
}
}
//Set the response header
HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.ClearHeaders();
response.ContentType = "application/pdf";
//Convert to the output stream
HtmlToPdf.ConvertHtml(html, response.OutputStream);
response.End();
However, in this case, we again lose all our styling. i asume we should really be using ConvertUrl here but the url is either localhost in dev or an authenticated url.