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

Free Support Forum - aspose.com

Use a certain Font for a PDF

Test_Data.zip (39.9 KB)


I’m trying to genrate PDFs with a certain Font.
But the Font is not beeing used.
Can you please take a look?

My TestCode (you will find the xml template and the Font-File attached):

	static void Main(string[] args) {


		String xmlTemplate = File.ReadAllText(@"TestTemplate.xml", Encoding.UTF8);

		XmlDocument doc = new XmlDocument();

		XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
		nsManager.AddNamespace("Aspose.Pdf", "Aspose.Pdf");

		Aspose.Pdf.Generator.Pdf report = new Aspose.Pdf.Generator.Pdf();
		report.BindXML(doc, null);

		MemoryStream output = new MemoryStream();

		SaveMemoryStream(output, "Test.pdf");

	public static void SaveMemoryStream(MemoryStream ms, string FileName) {
		FileStream outStream = File.OpenWrite(FileName);

	private static void SetLicense() {
		Aspose.Pdf.License license = new Aspose.Pdf.License();

		using (Stream fs = File.OpenRead(@"Aspose.Total.lic")) {


Thank you for contacting support.

We have noticed your working with quite old and outdated version of the API. Would you please upgrade to Aspose.PDF for .NET 19.1 and make necessary modifications in your XML file to ensure that it must follow Aspose.PDF for .NET Schema. Install required font on your machine and then specify font name under TextState tag.

We have attached sample XML file and generated PDF file along with the code snippet. You may also visit Generate PDF from XML for your kind reference.

// Instantiate Document object
Document doc = new Document();
// Bind source XML file
doc.BindXml(dataDir + "XML.xml");
// Save resultant PDF file
doc.Save(dataDir + "XMLToPDFfont_19.1.pdf");


We hope this will be helpful. Please feel free to contact us if you need any further assistance.

thank you for your answer.
I just realized that I provided the wrong xml-template in my example (I’m terribly sorry :-().
Could you please check the code snippet again with the following template?

Kind regards and thank you


<?xml version="1.0" encoding="utf-8" ?>
<Pdf xmlns="Aspose.Pdf">
				<cell Alignment="left">
						<segment FontName="Arial" IsUnicode="true" FontSize="12">Arial-Test-Text</segment>
				<cell Alignment="left">
						<segment FontName="PostSans-Regular" IsUnicode="true" FontSize="12">PostSans-Regular</segment>


Please note that the support is offered based on latest version of the API and your XML file does not follow Schema of latest version. For example, PDF documents now contain Pages instead of Sections. The XML template we have shared with you previously is basic and simple example for XML to PDF conversion.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.