Hi,
Hi Basil,
Thanks for your inquiry. Please note you need to install the intended fonts on your machine and set fonts folder path accordingly. Unix/Linux does not has Microsoft fonts by default. Please install these fonts locally and use as demonstrated below.
final aspose.pdf.Pdf pdf = new aspose.pdf.Pdf();
System.out.println(pdf.getTruetypeFontMapPath());
pdf.setTruetypeFontMapPath("/usr/share/fonts/truetype/msttcorefonts/");
final aspose.pdf.PageSetup pagesetup = pdf.getPageSetup();
final aspose.pdf.MarginInfo marginInfo = pagesetup.getMargin();
marginInfo.setLeft(5);
marginInfo.setRight(5);
marginInfo.setTop(5);
marginInfo.setBottom(5);
pagesetup.setPageHeight(aspose.pdf.PageSize.LETTER_HEIGHT);
pagesetup.setPageWidth(aspose.pdf.PageSize.LETTER_WIDTH);
pdf.setPageSetup(pagesetup);
pdf.isLandscape(true);
final aspose.pdf.Section section = pdf.getSections().add();
String sample2 = “<font face=“Arial” size=50>”
+ "This is a test for HTML </ support "
+ " in Text paragraph. ";
final aspose.pdf.Text text = new aspose.pdf.Text(sample2);
text.isHtmlTagSupported(true);
section.getParagraphs().add(text);
pdf.save(new FileOutputStream(“convertHtmlPdf.pdf”));
Please feel free to contact us for any further assistance.
Best Regards,
Hi,
Thank you for the response.
I have one issue here.I do not want to install these fonts .
Can I load the fonts from a specified location in Unix ? Please see below.
I am getting font not found exception in this case.Please help…This is again urgent…
final aspose.pdf.Pdf pdf = new aspose.pdf.Pdf();
pdf.setTruetypeFontMapPath("/home/server/conf/");
=============================================================
Also I am not able to load custom font from location in windows …please help…
I have set setTruetypeFontMapStream and setTruetypeFontMapPath
public class TestFontException {
/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
Locale locale1 = new Locale(“en”);
Locale.setDefault(locale1);
String sample2 = “<font face=“Roboto-Light” size=50>” +
"This is a test for HTML </ support " +
" in Text paragraph. ";
aspose.pdf.Pdf pdf1 = addHtml(sample2);
File file = new File(“C:\Users\ubpaul\Downloads\Roboto-Light.TTF”);
byte[] bFile = new byte[(int) file.length()];
pdf1.setTruetypeFontMapStream(bFile);
//pdf1.setTruetypeFontMapPath(“C:\Users\ubpaul\Downloads”);
pdf1.isCoreFontUsed(false);
System.out.println(pdf1.getTruetypeFontMapPath());
System.out.println(pdf1.isCoreFontUsed());
pdf1.save(new FileOutputStream(“fontException.pdf”));
}
private static aspose.pdf.Pdf addHtml(String sample) {
aspose.pdf.Pdf pdf = new aspose.pdf.Pdf();
aspose.pdf.Section sec = pdf.getSections().add();
aspose.pdf.Text text1 = new aspose.pdf.Text(sample);
text1.isHtmlTagSupported(true);
sec.getParagraphs().add(text1);
return pdf;
}
Hi Basil,
Hi,
Hi Basil,