I'm working on building a POC where I compile an index.cshtml using razorlight then generate a pdf using dinktopdf, so far I got that part working fine.
Next, using vuejs and vue-qrcode, I was able to add a qrcode to the page where qr-code tag is converted into canvas and the qrcode is being displayed.
Now, the issue I'm running into is that during the generation of the pdf, vue-qrcode isn't being compiled into regular html (it should be a canvas tag) and nothing is being added to the pdf.
The solution is in the following Repository
page = await engine.CompileRenderAsync(path, model); shows the full string of the html and in there you can see the the qr-code tag still remains as it is.
public async Task<byte[]> PrintPDFAsync()
{
var engine = new RazorLightEngineBuilder()
.UseFileSystemProject(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location))
.UseMemoryCachingProvider()
.Build();
var model = new List<WeatherForecast>(Get());
string page = null;
try
{
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $"Views/Home/Index.cshtml");
page = await engine.CompileRenderAsync(path, model);
}
catch (Exception e)
{
Console.WriteLine(e);
}
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Landscape,
PaperSize = PaperKind.A4Plus
},
Objects = {
new ObjectSettings() {
PagesCount = true,
HtmlContent = page,
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }
}
}
};
byte[] pdf = null;
try
{
pdf = _pdfConverter.Convert(doc);
}
catch (Exception e)
{
Console.WriteLine(e);
}
return pdf;
}
I was able to solve the issue using pure JavaScript QRCode instead of vue-qrcode library.
The final view