DinkToPdf
DinkToPdf copied to clipboard
Azure Functions - black squares
After publishing v2 function into Azure, my pdf file contains black squares instead of correct font. I'm not setting font explicitly so I assume that default one should be taken on Azure instance. On local machine everything works fine, as always.
Code was deployed to azure before and worked fine for a long time. Have you got any ideas what can be wrong? I'm running out of ideas.
After publishing v2 function into Azure, my pdf file contains black squares instead of correct font. I'm not setting font explicitly so I assume that default one should be taken on Azure instance. On local machine everything works fine, as always.
Code was deployed to azure before and worked fine for a long time. Have you got any ideas what can be wrong? I'm running out of ideas.
Hello. Have you solved it? I have the same problem
Sorry for very late response. Problem was in Azure Function settings - after deployment service plan changed to 'Consumption'. At least Basic is required.
Hello @rybczak !
I'm also trying to implement a HTML to PDF converter with Azure Functions v2 NET Core and DinkPDF, I get no runtime exceptions, but the execution of the function gets terminated once I hit the convert method of the converter.
[FunctionName("GeneratePDF")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
if (name != null)
{
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary($"{Directory.GetCurrentDirectory()}/Dependencies/libwkhtmltox.dll");
var converter = new BasicConverter(new PdfTools());
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Landscape,
PaperSize = PaperKind.A4Plus,
},
Objects = {
new ObjectSettings() {
PagesCount = true,
HtmlContent = $@" <!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
Hello, ${name}
</body>
</html>",
WebSettings = {
DefaultEncoding = "utf-8"
},
HeaderSettings = {
FontSize = 9,
Right = "Page [page] of [toPage]",
Line = true,
Spacing = 2.812
}
}
}
};
var bytes = converter.Convert(doc);
return new FileContentResult(bytes, "application/pdf");
}
return new BadRequestResult();
}
No exceptions popping out, no information.
Could you please lend a hand to me? Thank you!
Hello @rybczak !
I'm also trying to implement a HTML to PDF converter with Azure Functions v2 NET Core and DinkPDF, I get no runtime exceptions, but the execution of the function gets terminated once I hit the convert method of the converter.
[FunctionName("GeneratePDF")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; if (name != null) { CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary($"{Directory.GetCurrentDirectory()}/Dependencies/libwkhtmltox.dll"); var converter = new BasicConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = $@" <!DOCTYPE html> <html> <head> <meta charset='utf-8' /> <title></title> <meta name='viewport' content='width=device-width, initial-scale=1'> </head> <body> Hello, ${name} </body> </html>", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; var bytes = converter.Convert(doc); return new FileContentResult(bytes, "application/pdf"); } return new BadRequestResult(); }
No exceptions popping out, no information.
Could you please lend a hand to me? Thank you!
Regarding this issue, I could manage to make it work changing var converter = new BasicConverter(new PdfTools());
to var converter = new SynchronizedConverter(new PdfTools());
Hello @rdvojmoc ,
I'm also facing the issue that the converted PDF file has black squares. azure plan is : consumption plan. but it works in local.
Hello @rdvojmoc
After publishing v2 function into Azure, my pdf file contains black squares instead of correct font. I'm not setting font explicitly so I assume that default one should be taken on Azure instance. On local machine everything works fine, as always.
Code was deployed to azure before and worked fine for a long time. Have you got any ideas what can be wrong? I'm running out of ideas.
Any work around in consumption plan?
@nrajasekar7 you ever find a fix? I prefer staying in consumption plan as there is better performance. Hoping you figured out a solution. I'm getting black boxes / black squares...
@markti I am sorry. I didn't get any work around
The sandbox limitation is not in place for Linux. I deployed to a Linux comsumer plan / serverless and it worked fine.
Hello all, same as you guys, I got black square for tiny html but with bigger Html the solution goes TimeOut ! I am working on a PDF solution from 1 month now, did somebody has a solution ?
I use Azure Function Y plan with DinkToPdf. In local its work perfectly but then in Azure server its always breaking the service !