Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
c0deflow opened this issue Mar 21, 2018 · 5 comments
Closed

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

c0deflow opened this issue Mar 21, 2018 · 5 comments

Comments

@c0deflow
Copy link

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: #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

@rdvojmoc
Copy link
Owner

Where do you deploy your application in Release?

@c0deflow
Copy link
Author

Hi @rdvojmoc I am using docker with Debian stretch

@rdvojmoc
Copy link
Owner

Please check this issue.

@c0deflow
Copy link
Author

c0deflow commented 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! :)

@BROROZCO
Copy link

BROROZCO commented Oct 1, 2021

ya son 3 años tarde jajaja pero tenes que definir el PDI, el estandar es 300 que es lo mismo que el men de arriba xd
saludos desde el futuro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants