Not able to convert Html to PDF in Unix machine [Urgent]

Hi,


I am using aspose 4.5 to generate PDF. I have a requirement to convert HTML to PDF and using the code as per aspose forum http://www.aspose.com/community/forums/thread/523123.asp

My issue is that code is deployed in Unix environment (Working in windows) and UNIX does not have Arial/Arial-Narrow as default font. The code is throwing font not found exception.I tried to give true type font map path to the aspose.pdf.Pdf object, but found that the fonts are not loading.

Please find the code snippet to test from your side

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Locale;

import aspose.pdf.MarginInfo;
import aspose.pdf.PageSetup;
import aspose.pdf.PageSize;

public class TestHtmlToPdfFont {

/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
Locale locale1 = new Locale(“en”);
Locale.setDefault(locale1);
final aspose.pdf.Pdf pdf = new aspose.pdf.Pdf();

System.out.println(pdf.getTruetypeFontMapPath());
pdf.setTruetypeFontMapPath(“/usr/share/fonts/truetype”);

final PageSetup pagesetup = pdf.getPageSetup();
final MarginInfo marginInfo = pagesetup.getMargin();

marginInfo.setLeft(5);
marginInfo.setRight(5);
marginInfo.setTop(5);
marginInfo.setBottom(5);

pagesetup.setPageHeight(PageSize.LETTER_HEIGHT);
pagesetup.setPageWidth(PageSize.LETTER_WIDTH);

pdf.setPageSetup(pagesetup);

pdf.isLandscape(true);

final aspose.pdf.Section section = pdf.getSections().add();

String sample2 = “<font face="Arial Narrow" 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”));

}

}


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,


Thanks for your inquiry. We have noticed the reported font issue when loading another font and logged this issue as PDFNEWJAVA-34090 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Thanks for the reply.
I have not got reply for my first part of the question.(Loading font from a specified location in Linux)

Your reply means to me that html to PDF conversion works only on installed fonts…Is that correct.Please reply back immediately


Hi Basil,


Thanks for your feedback. Aspose.Pdf for Java works with the all the fonts available on the system. I meant with install the missing font (Arial) to make available the font on system. We have replicated the issue and will keep you updated about the issue progress.

Moreover as you stated you don’t want to install the font, Can you please share some more details and a sample font? so we will provide you more information.

Best Regards,