Welcome to the WinForms feedback portal. We’re happy you’re here! If you have feedback on how to improve the WinForms, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

0
Votes

Hi,

Currently, I'm working with webkit htmlrenderingengine to convert html to pdf, font is currently "times new roman" on the pdf output file. Is there a way I can change the default font programmatically?

Seems I cannot change input font format. I tried to change it after conversion but I got an error that font is already embedded. Thank you for usual support.

Here is the code.


                        //Initialize HTML to PDF converter

                        HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);


                        //Initialize WebKit converter settings

                        WebKitConverterSettings settings = new WebKitConverterSettings();


                        //Set the WebKit path.

                        settings.WebKitPath = Environment.CurrentDirectory + "/QtBinaries/";


                        //Set PDF page margin

                        settings.Margin = new Syncfusion.Pdf.Graphics.PdfMargins { Top = 30, Left = 30, Right = 30, Bottom = 30 }


                        //other settings

                        settings.AspectRatio = AspectRatio.None;

                        settings.EnableHyperLink = true;

                        settings.HtmlEncoding = Encoding.UTF8;


                        settings.WebKitViewPort = new Size(1220, 0);


                        //Set page size

                        settings.PdfPageSize = PdfPageSize.A4;


                        //Assign WebKit settings to the HTML converter.

                        htmlConverter.ConverterSettings = settings;


                        //Convert URL to PDF.

                        PdfDocument document = htmlConverter.Convert(oFile);


                        //Save and close the PDF document.

                        document.Save(oFile + ".pdf");

                        document.Close(true);


                        //Creates a new PDF document.

                        PdfLoadedDocument loadedDocument = new PdfLoadedDocument(oFile + ".pdf");


                        //Replace font

                        loadedDocument.UsedFonts[0].Replace(new PdfStandardFont(PdfFontFamily.Courier
, 12));


                        //Save the document

                        loadedDocument.Save(oFile + ".pdf");

                        loadedDocument.Close(true);