Reputation: 265
I'm currently working on a print service hosted in an Azure service fabric (kind of the new product that will replace web and worker roles). I'm using wkhtmltopdf and NReco.PDFGenerator.LT as its wrapper, it's working fine in local dev cluster but fails when it's online.
The only exception I got was Exception thrown: 'System.Exception' in NReco.PdfGenerator.LT.dll
which I find really hard to debug as it does not tell what is failing.
Reading this I'm thinking that maybe some things are missing on the cluster, but the local environment is suposed to be a replica of the online one.. Moreover I was using phantomjs with NReco wrapper in same cluster before switching to wkhtmltopdf and it was working both online and in local and I believe they both use the same core engine (though different fork)?
Here is my code, while in remote debug I checked that the licence, the .exe path and the file had correct value.
[HttpGet]
public ActionResult Get(string target)
{
var wktohtmlPath = Path.Combine(_hostingEnvironment.WebRootPath, "lib");
var htmlToPdf = new HtmlToPdfConverter() {
Quiet = false,
CustomWkHtmlArgs = "--print-media-type",
PdfToolPath = wktohtmlPath,
Margins = new PageMargins() { Left = 17, Right = 17, Top = 17, Bottom = 17 }
};
htmlToPdf.License.SetLicenseKey(
_optionsAccessor.Value.LicenceOwner,
_optionsAccessor.Value.LicenceKey
);
try
{
var fileBytes = htmlToPdf.GeneratePdfFromFile(target, null);
var fileStream = new MemoryStream(fileBytes);
return new FileStreamResult(fileStream, "application/pdf");
}
catch
{
return BadRequest();
}
}
Thanks for your answers
Upvotes: 1
Views: 518
Reputation: 265
For the records : there was two problems
Upvotes: 1