Free Support Forum - aspose.com

Failing to save document as PDF

I’m currently evaluation the latest Aspose.Words java library using a ruby interface (using rjb).


My code is really simple:

doc = Rjb::import(“com.aspose.words.Document”).new
builder = Rjb::import(“com.aspose.words.DocumentBuilder”).new
builder.setDocument(doc)
builder.write(“Hello world!”)
doc.save("/tmp/out.pdf")

When trying to save to a “.doc” or “.docx” or “.odt” it works fine. But as soon as I try to save to “.pdf” it fails with “Fail: unknown method name `to_str’”. :frowning:

Hello

Thanks for your request. When you render documents to PDF, XPS or convert to EPUB that requires embedding of fonts into a document, then Aspose.Words needs to have access to TrueType fonts. If you run Aspose.Words on a Windows system, then by default it will search for fonts in the system Windows\Fonts folder. But if you run Aspose.Words on a Linux system, it does not have a default location for fonts and you need to specify it explicitly.

Use the new com.aspose.words.FontSettings class and setFontsFolder/setFontsFolders methods to specify the location of TrueType fonts.


FontSettings.setFontsFolder("C:\\Users\\Andrey\\IdeaProjects\\awtest");

DocumentBuilder b = new DocumentBuilder();

b.getFont().setName("Water on the Oil");

b.getFont().setSize(72);

b.writeln("Hello World!");

b.getDocument().save("TestHelloWorld Out.pdf");

http://www.aspose.com/documentation/java-components/aspose.words-for-java/specifying-font-locations-when-converting-to-fixedpage-formats.html

Best regards,

Thanks, now it’s working :slight_smile: