PDF font size growing up after creating the pdf [.NET CORE 2.0]
See original GitHub issueI am preparing some PDF Layouts. But at some point I get confused. If I run the .net core application on DEBUG Mode, I get the size that I want. If I run the the application in Release (Production) Mode I get a total different pdf (with a bigger font size) back. Is this an issue? I included the CSS (both templates are using the same css) and the pdf can load successfully the font (RNS Sanz) but no luck with the font size. I tried it also without my css, plain example code. But there is the same situation. Is there a setting for that? thanks.
I am using this code
Controller
string html = "<!DOCTYPE html>" +
"<html lang = \"en\">" +
"<head>" +
"<meta charset = \"UTF-8\">" +
"<title> Check </title>" +
// "<link href='" + cssPath + "' rel='stylesheet' type='text/css' media='screen'>" +
"</head>" +
"<body>" +
"<div style = \"text-align: center; margin-top:16px;\">" +
"<p style=\"font-family: 'RNS Sanz'; font-size: 70px;\"> Hi! I am RNS Sanz font. (70px, Release)</p>" +
"</div>" +
"<div style = \"text-align: center; margin-top:16px;\">" +
"<p style =\"font-family: 'Roboto'; font-size: 30px;\"> This is roboto font. (30px, Release)</p>" +
"</div>" +
"</body>" +
"</html>";
var pdf = new HtmlToPdfConverterService(_converter, _env).Convert(html);
var path = Path.Combine(_env.WebRootPath, "micr.pdf");
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
fs.Write(pdf, 0, pdf.Length);
}
return new FileContentResult(pdf, "application/pdf");`
HtmlToPdfConverterService
public class HtmlToPdfConverterService
{
private IConverter _converter;
readonly IHostingEnvironment _env;
public HtmlToPdfConverterService(IConverter converter, IHostingEnvironment env)
{
_converter = converter;
_env = env;
}
public byte[] Convert(string html)
{
string cssPath = Path.Combine(_env.WebRootPath, "static/css/app.css");
HtmlToPdfDocument doc = new HtmlToPdfDocument()
{
GlobalSettings = {
Orientation = Orientation.Portrait,
PaperSize = PaperKind.Letter,
Margins = new MarginSettings() { Top = 10 , Bottom = 0, Left = 10, Right = 10},
},
Objects = {
new ObjectSettings() {
HtmlContent = html,
WebSettings = new WebSettings { MinimumFontSize = 12, UserStyleSheet = cssPath }
}
}
};
return _converter.Convert(doc);
}
}
I followed this ticket here: https://github.com/rdvojmoc/DinkToPdf/issues/24 The PDF can Read the font “RNS Sanz” but the font size is growing automatically up in Release.
If I don’t use any css, I get the same result. Also with this example:
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Landscape,
PaperSize = PaperKind.A4Plus,
},
Objects = {
new ObjectSettings() {
PagesCount = true,
HtmlContent = "<h1>Hello World</h1>",
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }
}
}
};
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Please check this issue.
@rdvojmoc Thank you very much for this post! Changing the Default value of DPI (in GlobalSettings) from 96 to 300 solved my problem. Issue can be closed. Thanks! 😃