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

Free Support Forum - aspose.com

Custom Font with BindXML

In our application we have a PDF we create from an XMl document. Code below.

pdf.BindXML(dataStream, xslStream);

We want to use AvenirLTStd-Black font when binding the XMl, but it throws as exception
"Font Not Found". We added the folder as a FolderFontSource. This lets the
FontRepository.FindFont("AvenirLTStd-Black") return a font. The XMl bind still fails though.
What do we need to change to support the font?

var fontSource2 = new Aspose.Pdf.Text.FolderFontSource(@"C:\CustomFonts\");
 Aspose.Pdf.Text.FontRepository.Sources.Add(fontSource2);
Aspose.Pdf.Text.FontRepository.LoadFonts();

Hi Josh,


Thanks for contacting support.

Can you please share the resource XML file and AvenirLTStd font file so that we can test the scenario in our environment. During XML to PDF conversion, if the referenced font is installed over system, it will be automatically referenced during XML to PDF conversion. We are sorry for this inconvenience.

The font is not installed on the system. We deploy the font with our application which works when we use a “FolderFontSource”. Except when we reference that font in our pdf xml, it throws an error.


We currently have call BindXML with “ArialMT” referenced. Then after that call loop through each text fragment and change the font to “AvenirLTStd-Light” because the BindXMl doesn’t use the FontRepository Sources.

var fontSource = new FolderFontSource(PathHelper.VirtualToPhysical(@"~\Content\Fonts"));
FontRepository.Sources.Add(fontSource);

pdf.BindXML(dataStream, xslStream);

var doc = new Aspose.Pdf.Document(pdf);
var absorber = new TextFragmentAbsorber(new TextEditOptions(TextEditOptions.FontReplace.RemoveUnusedFonts));

doc.Pages.Accept(absorber);
foreach (TextFragment textFragment in absorber.TextFragments)
{
if (textFragment.TextState.Font.FontName == “ArialMT”)
{
textFragment.TextState.Font = FontRepository.FindFont(“AvenirLTStd-Light”);
}
if (textFragment.TextState.Font.FontName == “Arial-BoldMT”)
{
textFragment.TextState.Font = FontRepository.FindFont(“AvenirLTStd-Black”);
}

}

doc.Save(outputStream);

Hi Josh,


Thanks for sharing the details.

Can you please share the source XML which you are using, so that we can test the scenario in our environment.