Only supports regular fonts (such as simsun) does not support bold and italic effects
superboy1984 opened this issue · 2 comments
superboy1984 commented
private readonly string _htmlstr1 = "<div id=\"contract\" style=\"width:210mm;\"><div id=\"page1\" class=\"contractPage\"><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:22pt;font-weight:bold;line-height:1.2;text-align:center;\">Guangdong Province</p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:22pt;font-weight:bold;line-height:1.2;text-align:center;\">Real Estate Contracts</p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:16pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:16pt;line-height:1.8;text-align:center;\">Guangdong Provincial Construction Department</p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:16pt;letter-spacing:1pt;line-height:1.8;text-align:center;\">Guangdong Provincial Administration for Industry and Commerce</p><p style=\"margin:0;padding:0;font-family:SimSun;font-size:26pt;\"> </p></div></div>";
var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
var _browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
});
var _pdfOptions = new PdfOptions
{
Format = PaperFormat.A4,
//MarginOptions = new MarginOptions
//{
// Top = "10mm",
// Right = "10mm",
// Bottom = "10mm",
// Left = "10mm",
//}
};
using var page = await _browser.NewPageAsync();
await page.SetContentAsync(_htmlstr1);
var data = await page.PdfDataAsync(_pdfOptions);
await page.CloseAsync();
var fileResult = new FileContentResult(data, "application/pdf");
fileResult.FileDownloadName = $"htmltopdf{DateTime.Now:yyMMddHHmmssffff}.pdf";
### Expected behavior:
“Guangdong Province” and "Real Estate Contracts" has css style "font-weight:bold;" then pdf string render bold effects
### Actual behavior:
pdf string not bold effects, After checking, I found that the Arial font was correct, and then I checked C:\Windows\Fonts and found that the Simsun font only support regular.
but word and Select.HtmlToPdf.NetCore can achieve bold effect, hope PuppeteerSharp can support.
### Versions
* PuppeteerSharp 18.0.4 .NET6
kblok commented
Did you try loading that HTML in a regular chrome browser and printing to PDF? That's what we do.
superboy1984 commented
has the same problem when I use Chrome to load the above HTML string and print it as PDF. I can only use CSS to simulate the bold effect.