Problem converting .doc to .pdf using Linux

Hi Anthony,

Thanks for your request. Could you please also describe your environment? Which version of Aspose.Words do you use?

Best regards.

Hi Alexey,

I’m using the 4.0.1 Beta.
The PDF output is key for the application I’m developing.
We’re using Word documents as “templates” populating them using MailMerge and then returning a PDF as the result.

A Question: How critical are the TTF fonts to the PDF generation?

Regards,

Anthony

Hi

Thanks for your inquiry. During rendering Aspose.Words needs to read all fonts to create map of font name to font file names. Then, when you convert some document to PDF the appropriate font files are read in order to create font subset, which will be stored in the file. So there is no way to generate PDF without fonts.

Best regards.

Hi Alexi,

I don’t currently have access to a Windows dev environment.
Both hsp2000 and I are using *nix environments (I’m actually on OS X) - does the behaviour change when using Windows (which I imagine you are developing on given the .Net version)

Thanks,

Anthony

abuckton:

does the behaviour change when using Windows

When we are using the Aspose.Words API with on a windows enviroment everything works fine! The problem only seems to be when using Linux or OS X enviroment.

the problem is because you need the ms ttype fonts on your linux system

$sudo apt-get install msttcorefonts
$sudo fc-cache -fv

and

opt.setTrueTypeFontsFolder("/usr/share/fonts/truetype/msttcorefonts");

should fix the issue on a ubuntu box

HTH

Radu

Hi

Thank you for additional information. I also just installed OpenSuse 11 on Virtual Machine. I successfully converted document to PDF using the following code:

Document doc = new Document("/home/user/Einfach+vorlage.doc");
PdfOptions opt = new PdfOptions();
opt.setTrueTypeFontsFolder("/home/user/fonts");
doc.saveToPdf(0, doc.getPageCount(), "/home/user/out.pdf", opt);

/home/user/fonts folder contains true type fonts.

Best regards.

Hi

I now installed MicrosoftFonts-1-jen15.src.rpm (install dir /usr/share/fonts/truetyps) and restartet the X font server but I still get the error message: <>

Then I installed msttcorefonts-2.0-1.noarch.rpm (install dir /usr/share/fonts/msttcorefonts) and restart the X font server and let’s see IT WORKS!!!

Thanks all for your support!!!

Alexey,

On most linux systems (not to mention unix) ms tt fonts don’t come preinstalled with the original distribution. They might be installed as dependencies by other packages but not by default. Probably you have to add this to the documentation

HTH

Radu

Hi Radu,

Thank you for your suggestion. We will mention this in the documentation.

Best regards.

I now installed MicrosoftFonts-1-jen15.src.rpm (install dir /usr/share/fonts/truetyps) and restartet the X font server but I still get the error message: <>

If anything, you have to use .noarch.rpm as you did with msttcorefonts. The .src.rpm won’t get you anywhere.

Hi

Thanks for your request. Please make sure that you specified correct TrueTypeFontsFolder:

Document doc = new Document("/home/user/Einfach+vorlage.doc");
PdfOptions opt = new PdfOptions();
opt.setTrueTypeFontsFolder("/home/user/fonts");
doc.saveToPdf(0, doc.getPageCount(), "/home/user/out.pdf", opt);

The specified folder should contain valid True Type fonts.

Best regards.

I have exactly the same problem
Has this been resolved ?

Hi

Thanks for your inquiry. I just answered your question here: <A href="https://forum.aspose.com/t/66342

Best regards.

I am getting an exception while creating a pdf from doc. Exception is related to fonts.

My code and exception is giving below.

public void createPDFDocument(String companyName, String docId)
{
    try
    {
        IDocumentLibraryService documentLibraryService = DocumentLibraryServiceFactory.getInstance();

        IFile file = documentLibraryService.getFileByPath(System.getProperty("JBOSS_HOME_DIR")
            +"/FileSystem/" + companyName, IDocumentLibraryService.FILESYSTEM_REPOSITORY_CLASSNAME,
        docId, EMPTY_STRING);

        InputStream in = file.getFileStream();

        Document returnFile = new Document(in);

        PdfOptions opt = new PdfOptions();

        try
        {
            if (System.getProperty("path.separator").equals(":"))
            {
                opt.setTrueTypeFontsFolder("/u02/Cobra/Authoring/JBOSS/Fonts");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        int pageCount = returnFile.getPageCount();

        OutputStream outStream = new ByteArrayOutputStream();

        returnFile.saveToPdf(0, pageCount, outStream, opt);

        // returnFile.sav
        byte[] bytesInFile = ((ByteArrayOutputStream)outStream).toByteArray();
        Properties prop = new Properties();

        Map<String, String> mapData = new HashMap<String, String>();
        mapData.put("databaseName", companyName);

        IDocumentLibraryService documentLibraryServiceToWriteNewFile = DocumentLibraryServiceFactory
            .getInstance();
        IFile ff = documentLibraryServiceToWriteNewFile.addFile(System.getProperty("JBOSS_HOME_DIR")
            +"/FileSystem/" + companyName, RepositoryFactory.FILESYSTEM_REPOSITORY_CLASSNAME_FACTORY,
        prop, docId, bytesInFile, EMPTY_STRING, mapData);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
java.lang.IllegalStateException: Cannot find any fonts installed on the system.
2010-09-09 09:09:46,408 ERROR [STDERR] at asposewobfuscated.qx.B(TTFontFiler.java:81)
2010-09-09 09:09:46,408 ERROR [STDERR] at asposewobfuscated.oa.hc(PalFont.java:24)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.xk.Ho(SpanPr.java:231)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.sl.rs(Span.java:730)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.sl.getWidth(Span.java:593)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.zy.JJ(LineBuilder.java:95)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.zy.JI(LineBuilder.java:30)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.bx.V(LinePart.java:281)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.k.c(ColumnBuilder.java:481)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.k.a(ColumnBuilder.java:163)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.k.a(ColumnBuilder.java:97)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.mz.a(PageBuilder.java:119)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.mz.a(PageBuilder.java:60)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.ajt.b(SectionReflower.java:40)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.io.nG(MainTextSectionLayout.java:757)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.qr.nG(StoryLayoutBase.java:88)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.mx.nG(PageLayoutModel.java:124)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.zh.a(LayoutDocument.java:33)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.Document.updatePageLayout(Document.java:1637)
2010-09-09 09:09:46,408 ERROR [STDERR] at com.aspose.words.Document.IF(Document.java:1590)
2010-09-09 09:09:46,409 ERROR [STDERR] at com.aspose.words.Document.getPageCount(Document.java:1618)

Hi

Thanks for your request. TrueTypeFontDirectory should contain fonts, which are using in your document. At least this folder should contain one valid TrueType font. Please try creating folder, put there few valid MS TrueType fonts (Arial and Times New Roman, for example) and specify this folder as TrueTypeFontDirectory. Please let me know if this helps.

Also, please make sure that you application can read fonts from this folder.

Best regards,