Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

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

$
0
0
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 = "<Html><font face=\"Arial Narrow\" size=50><u>"
                + "This is a test </u><i> for <strong> HTML </<strong> support </i>"
                + "<s> in Text paragraph. </s></font>";

        final aspose.pdf.Text text = new aspose.pdf.Text(sample2);
        text.isHtmlTagSupported(true);
        section.getParagraphs().add(text);

        pdf.save(new FileOutputStream("convertHtmlPdf.pdf"));

    }

}



Viewing all articles
Browse latest Browse all 3131

Trending Articles