WordToPDF not working with AlternateFontStream.

I have this error duringvar pdfText = render.ConvertToPDF(wordDocument);

This only happens whenever the code set a stream to argsAlternateFontStream.

if (args.OriginalFontName.ToLower() == fontName.ToLower() && isFontStyle){

var fs= File.OpenRead(@"lobster.woff2");

args.AlternateFontStream = fs;
}

Error details.

System.NullReferenceException

HResult=0x80004003

Message=Object reference not set to an instance of an object.

Source=Syncfusion.DocIORenderer.Portable

StackTrace:

at Syncfusion.DocIORenderer.Drawing.FontExtension.get_Name()

at Syncfusion.DocIO.DLS.FontSettings.GetFont(String fontName, Single fontSize, FontStyle fontStyle)

at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.UpdateAlternateFont(WCharacterFormat charFormat, String fontName, Font& font)

at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.GetFont(WTextRange txtRange, WCharacterFormat charFormat, String text)

at Syncfusion.DocIO.DLS.WTextRange.CreateLayoutInfo()

at Syncfusion.DocIO.DLS.WidgetBase.Syncfusion.Layouting.IWidget.get_LayoutInfo()

at Syncfusion.Layouting.LCContainer.CreateNextChildContext()

at Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)

at Syncfusion.Layouting.LCLineContainer.DoLayoutChild(LayoutContext childContext)

at Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)

at Syncfusion.Layouting.LCContainer.DoLayoutChild(LayoutContext childContext)

at Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)

at Syncfusion.Layouting.LCContainer.DoLayoutChild(LayoutContext childContext)

at Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)

at Syncfusion.Layouting.Layouter.Layout(IWidgetContainer widget, ILayoutProcessHandler handler, IDrawingContext dc)

at Syncfusion.DocIO.DLS.Rendering.DocumentLayouter.LayoutPages()

at Syncfusion.DocIO.DLS.Rendering.DocumentLayouter.Layout(IWordDocument doc)

at Syncfusion.DocIORenderer.DocIORenderer.ConvertToPDF(WordDocument wordDocument)

at C2C.SfTemplateEditorAPI.Domain.Services.DocumentTemplateService.d__35.MoveNext() in C:\***-documents-domain\api\Domain\Services\DocumentTemplateService.cs:line 713


1 Reply 1 reply marked as answer

MJ Mohanaselvam Jothi Syncfusion Team February 8, 2021 11:02 AM UTC

Hi Ronald,

Thank you for contacting Syncfusion support.

On further checking the given details, we have found that your are using *. woff2 format font files for font substitution. DocIO supports *.ttf and *.otf format font files only. So, it rises exception while using the given improper font file for Word to PDF conversion process.

To resolve this problem, we recommend you to use *.ttf or *.otf font files for substitution.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J 


Marked as answer
Loader.
Up arrow icon