Pdf text size differences

Hi, the html > pdf conversion works but text sizes will be different on Windows 7 (larger) and Windows 10 (smaller).

You can see here (100% view both): https://imgur.com/a/kunxQ

Sample code:

namespace pdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.DocumentText = @"<html lang='en'>
            <head>
                <meta charset='utf-8'>
                <title></title>
                <style type='text/css'>
                    body
                    {
                        font-family: Arial;
                        font-size: 40px;
                        color: #282828;
                        cursor: default;
                        padding: 1px;
                    }
                </style>

                <body>
                html html html
                </body>
                </html> ";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
            WebKitConverterSettings settings = new WebKitConverterSettings();
            settings.PdfPageSize = PdfPageSize.A4;
            settings.SplitTextLines = false;

            PdfMargins margin = new PdfMargins();
            margin.All = 40;
            settings.Margin = margin;


            string htmlText = @"";

            string baseUrl = "";

            //Set WebKit path
            settings.WebKitPath = Directory.GetCurrentDirectory() + "\\QtBinaries";
           
            //Assign WebKit settings to HTML converter
            htmlConverter.ConverterSettings = settings;

            try
            {
                var document = htmlConverter.Convert(webBrowser1.DocumentText, baseUrl);

                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "Files(*.pdf)|*.pdf";
                saveFileDialog.AddExtension = true;
                saveFileDialog.DefaultExt = ".pdf";
                saveFileDialog.FileName = "file.pdf";

                if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.CheckPathExists)
                {
                    document.Save(saveFileDialog.FileName);
                    document.Close();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }
    }
}

What could be the problem?

3 Replies

PV Prakash Viswanathan Syncfusion Team March 5, 2018 04:51 AM UTC

Hi Mate, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the given code snippet and screenshot, text size in the PDF document may changed due to WebKitViewPort size. Our WebKit HTML converter internally using system viewport size to convert HTML to PDF. System viewport size may differ based on the system. So, if you need a fixed content size in all system, you can set WebKitViewPort size in WebKitConverterSettings. Please refer below code snippet to set WebKitViewPort size.   
 
//Set WebKit Viewport  
settings.WebKitViewPort = new Size(1024, 0); 
 
Refer below KB and UG for more details about WebKitViewPort size,  
 
Please let us know if you need any further assistance on this.  
 
Regards, 
Prakash V 



VH Vhalaky March 5, 2018 01:59 PM UTC

Thank you! It's OK now.


PV Prakash Viswanathan Syncfusion Team March 6, 2018 03:53 AM UTC

Hi Mate, 

Thanks for your update. 
Please let us know if you need any further assistance on this. 

Regards, 
Prakash V 


Loader.
Up arrow icon