Html To pdf conversion - Embed Font

I am evaluating Aspose for support for Khmer, and if it is fit for use for our purpose

We need to convert html into pdf. The html contains styles to embed fonts as below



<style type=“text/css”>

@font-face{
font-family: ‘KhmerOS’;
src: url(“KhmerOS.ttf”);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
@font-face{
font-family: ‘KhmerOSmuollight’;
src: url(‘KhmerOSmuollight.ttf’);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}

.khmertext {
font-family: “Khmer OS”,“KhmerOS”, “KhmerOSmuollight”,sans-serif;
}





<div class=“khmertext”>This is Khmer = វិញ្ញាបនប័ត្ររបស់កេ




And I am trying to convert it using the following code

String basePath = “c:\basePath\”;
com.aspose.pdf.HtmlLoadOptions htmloptions = new com.aspose.pdf.HtmlLoadOptions(basePath);
String basePath = “c:\basePath\”;
com.aspose.pdf.HtmlLoadOptions htmloptions = new com.aspose.pdf.HtmlLoadOptions(basePath);
// htmloptions.setInputEncoding(“UTF-8”);
// TextState txtState = new TextState();
// txtState.setFont(FontRepository.openFont(basePath + “KhmerOS.ttf”));
// htmloptions.getPageInfo().setDefaultTextState(txtState);


// Load HTML file
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(basePath+“test.html”, htmloptions);

// Save HTML file
doc.save(“c:\basePath\result.pdf”);

Is something like this even possible using Aspose? Given that the font has been embedded in the html, ideally there should be no need to specify the font again in java at the time of conversion. Even if I do it doesn’t work

Is there an example that I can look at?

Thanks

Hi Latika,

Thanks for your inquiry. Please note while converting HTML to PDF the referenced font should be installed on the machine, otherwise Aspose.Pdf will use system default font. After converting HTML to PDF you can embed fonts as suggested in this documentation link. Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,