question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PDF font size growing up after creating the pdf [.NET CORE 2.0]

See original GitHub issue

I 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 }
        }
    }
};

pdf font issue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
rdvojmoccommented, Mar 22, 2018

Please check this issue.

2reactions
c0deflowcommented, Mar 23, 2018

@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! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I increase the font size while generating a PDF ...
To increase the font size, just change 12 (for a 12pt font) into a bigger number, e.g. 24 (to make it double as...
Read more >
How to Easily Create a PDF Document in ASP.NET Core ...
In this article, we are going to show how to use the DinkToPDF library to easily generate PDF documents while working on the...
Read more >
How to create a PDF with font information and embed ...
I would like to create PDFs which only embed font information, not the full font. Then when I merge these PDFs into a...
Read more >
Converting HTML to PDF with WebKit engine
Learn how to convert HTML to PDF using WebKit rendering engine with various features like TOC, partial web page to PDF etc.
Read more >
PDF File Writer C# Class Library (Version 2.0.0)
NET class library allowing applications to create PDF files. The code was developed ... There are two exceptions: font size and resolution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found