Welcome to the ASP.NET Core feedback portal. We’re happy you’re here! If you have feedback on how to improve the ASP.NET Core, 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!

1
Vote

I would like to use underline /strikethrough styles with custom fonts in writing PDF documents.

This is possible by using PdfTrueTypeFont constructors that take a System.Drawing.Font or a filePath string , a size (float) and a PdfFontStyle as parmeters,  though these consructors are not cross-platform. (I assume because rely on GDI(+) APIs under the hood. - In case of System.Drawing.Font, this is directly confirmed in Microsoft's documentation. ( https://docs.microsoft.com/en-us/dotnet/api/system.drawing?#remarks ) )

I am writing a PDF document from within a Windows Service, where (using APIs) relying on GDI(+) is not recommended, so the only way to use a custom font will be the constructor taking a Stream as an input. However, this constructor has no overload that takes a PdfFontStyle enum as additional parameter.

Is there a way to still apply underline/strikethrough with custom (OTF/TTF) fonts given this restriction? (having to manually draw lines is not really a solution) 


At first sight, this seems to work for me in a test application:

                var str = File.OpenRead(@"C:\windows\fonts\times.ttf");
                var ctor = typeof(PdfTrueTypeFont).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[]
                {
                    typeof(Stream), // fontStream,
                    typeof(float), // size,
                    typeof(string), // metricsName,
                    typeof(bool), // isEnableEmbedding,
                    typeof(PdfFontStyle) // fontStyle)
                }, null);
                var font2 = (PdfFont)ctor.Invoke(new object[] { str, 12f, string.Empty, true, PdfFontStyle.Underline | PdfFontStyle.Strikeout });