6
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 go up to the server the file is not generated, the page is processing eternally 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 implemented this solution but data type conversion error occurs:
cannot implicity convert type
hello Gypsy gives type conversion error, I edited the question and added error
– hard123
Oops, I messed up. Look now.
– Leonel Sanches da Silva
Blz! It works by running my local project, but after I publish and upload it to the server it does not generate the pdf and does not download.
– hard123
But does it make a mistake? Or does nothing happen?
– Leonel Sanches da Silva
Nothing happens.
– hard123
Then I think it’s a question of debug. I don’t know what can be.
– Leonel Sanches da Silva
OK thanks, the situation is difficult because during the debug in my note works correctly but after the site is published does not work, so I do not need any configuration in IIS beyond the Pechkin dlls to be able to generate the pdf.
– hard123
It depends on where you post it. If you go to Azure on Web Site it won’t work. It’s the same problem as Rotary.
– Leonel Sanches da Silva
It works correctly, but the PDF generates more than one page and when I download the page is not numbered, this is a normal behavior when PDF is generated by Pechkin ?
– hard123
I think so. But since Pechkin is a wkhtmltopdf envelope, there must be some option to define page numbering by Pechkin itself.
– Leonel Sanches da Silva