Use a certain Font for a PDF

Test_Data.zip (39.9 KB)

Hi,

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) {

		SetLicense();

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

		XmlDocument doc = new XmlDocument();
		doc.LoadXml(xmlTemplate);

		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();
		report.Save(output);

		SaveMemoryStream(output, "Test.pdf");
	}

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


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

		using (Stream fs = File.OpenRead(@"Aspose.Total.lic")) {
			license.SetLicense(fs);
		}
	}

@Daniel81

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");

XMLToPDFfont_19.1.pdf
XML.zip

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

Hi,
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

Daniel


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

@Daniel81

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.