We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to set custom Font-size with HtmlFragment

Hi Team,
We are using the latest version ( of Aspose.pdf and we tried to set font-size to 11 for HTML content. But in the generated Pdf the font size is 36 instead of 11. Can you please assist to resolve this? For your reference the sample code is below here.

        Aspose.Pdf.Document samplePDF = new Aspose.Pdf.Document();

        samplePDF.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
        samplePDF.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;            
        Aspose.Pdf.Page mainSection = samplePDF.Pages.Add();            
        HtmlFragment htmlFragment = new HtmlFragment(" <p align='center'>123456789</p></n><p align='center'>ARON</p>");             
        htmlFragment.Margin.Right = 5;
        htmlFragment.Margin.Top = 40;
        htmlFragment.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
        htmlFragment.TextState = new TextState();
        htmlFragment.TextState.Font = FontRepository.FindFont("Tahoma");
        htmlFragment.TextState.FontSize = 11;



Thanks for contacting support.

We have tested the scenario in our environment and were able to notice the issue which you have mentioned. Furthermore, we have also tried specifying inline style for HTML string but font size was not still correct in the resultant PDF. Please check following code which we have tried in our environment and the screenshot of resultant PDF file.

HtmlFragment htmlFragment = new HtmlFragment("<p align='center' style='fontsize:11pt;'>123456789</p></n><p align='center' style='fontsize:11pt;'>ARON</p>");

FontSizeIssue.png (15.4 KB)

Hence, we have created an issue as PDFNET-45838 in our issue tracking system for the sake of detailed investigation. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.


I am using latest Aspose.PDF API and this issue still persists. Were you able to resolve this issue in some other way?


W are afraid that a workaround may not be available yet. However, we have recorded your concerns and will let you know once it is resolved.


Try this –

To use HtmlFragment just try to reduce the

htmlFragment.TextState.FontSize = 11; //Generated PDF font size is 36


htmlFragment.TextState.FontSize = 3; //Generated PDF font size is 11


Yes, you can specify font size using TextState Class. However, the API is generating issue when font size is specified in HTML string. Nevertheless, we encourage that you have shared this suggestion. We will update here as soon as the issue is resolved.


I want to ask one thing FontSize in TextState is in points or pixels? I couldnt find this in online documentation.



The measurement unit in the Aspose.PDF is point where 72 points = 1 inch.