Is there any specific configuration to generate pdf file on the server? The problem is that locally in my local project works perfectly and when I upload to the server the file is not generated, the page is rendered forever until it reaches the timeout, the code snippet is this:
protected string GerarPDF(string html)
{
//Nome arquivo
string nome = "Laudo_" + System.DateTime.Now.ToString().Replace(" ", "_").Replace("/", "_").Replace(":", "_") + ".pdf";
var path = Path.Combine(Server.MapPath("~/Content/Uploads/Laudos"), nome);
try
{
var pechkin = Factory.Create(new GlobalConfig());
var pdf = pechkin.Convert(new ObjectConfig()
.SetLoadImages(true)
.SetPrintBackground(true)
.SetScreenMediaType(true)
.SetCreateExternalLinks(true)
.SetAllowLocalContent(true), html);
using (FileStream file = System.IO.File.Create(path))
{
file.Write(pdf, 0, pdf.Length);
}
//Return the PDF file to download
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=" + nome + ", size={0}", pdf.Length));
Response.BinaryWrite(pdf);
Response.Flush();
Response.End();
return nome;
}
catch
{
nome = string.Empty;
return nome;
}
}
I have implemented this solution but a data type conversion error occurs:
cannot implicity convert type