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

Spacing or adjacency issue among Characters #2408

Open
mertgundoganx opened this issue Jan 24, 2024 · 3 comments
Open

Spacing or adjacency issue among Characters #2408

mertgundoganx opened this issue Jan 24, 2024 · 3 comments

Comments

@mertgundoganx
Copy link

I convert the value I write in HTML to a base64 PDF in the following method. While there is no issue with spacing among characters locally, there seems to be a problem with some characters being either adjacent or having gaps in the server environment.

Example

Screenshot 2024-01-24 at 09 43 39

Style

        html.AppendHtml("<!DOCTYPE html>");
        html.AppendHtml("<html lang='en'>");
        html.AppendHtml("<head>");
        html.AppendHtml("<meta charset=\"UTF-8\">");
        html.AppendHtml("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
        html.AppendHtml("<link rel=\"preconnect\" href=\"http://fonts.googleapis.com\">");
        html.AppendHtml("<link rel=\"preconnect\" href=\"http://fonts.gstatic.com\" crossorigin>");
        html.AppendHtml("<link href=\"http://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&subset=latin-ext&display=swap\" rel=\"stylesheet\">");
        html.AppendHtml("</head>");
        html.AppendHtml("<body style='font-family: Roboto, sans-serif !important; -webkit-font-smoothing: antialiased !important; font-variant: tabular-nums !important; letter-spacing: normal !important; font-feature-settings: \"tnum\" !important;'>");

Converter Method

try
        {
            using var browserFetcher = new BrowserFetcher();
            await browserFetcher.DownloadAsync();

            await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = false,
                Args = new[] { "--no-sandbox" },
                Timeout = 10000,
                IgnoreHTTPSErrors = true
            });

            await using var page = await browser.NewPageAsync();
            var html = ToHtmlString(htmlText);
            await page.SetContentAsync(html);

            var advertisementVehiclePdf = await page.PdfDataAsync(new PdfOptions
            {
                Scale = 1.7m,
                PrintBackground = true,
                Format = PaperFormat.A4,
                MarginOptions = new MarginOptions
                {
                    Top = "20px",
                    Bottom = "20px",
                    Left = "30px",
                    Right = "30px"
                }
            });

            return Convert.ToBase64String(advertisementVehiclePdf);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error generating pdf: " + e.Message);
            throw;
        }

private static string ToHtmlString(IHtmlContent builder)
    {
        using var writer = new StringWriter();
        builder.WriteTo(writer, HtmlEncoder.Default);
        return writer.ToString();
    }

Versions

  • PuppeteerSharp 13.0.2
  • net6.0
@kblok
Copy link
Member

kblok commented Jan 24, 2024

Do you have remove access to the server to run chrome there?

@mertgundoganx
Copy link
Author

Do you have remove access to the server to run chrome there?

yes, i have access permission

@kblok
Copy link
Member

kblok commented Jan 24, 2024

@mertgundoganx I bet there is some kind of font issue in the server or in the browser. Can you reproduce that printing to PDF in the server's browser?

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

2 participants