I tried to convert txt file to pdf
These are my codes:
Document doc = new Document(inputFile);
File file = new File(outputFile);
FileOutputStream fileOS = new FileOutputStream(file);
String s = System.getProperty("file.separator");
String fontPath = systemUtilService.getServletRunningPath() + s + "WEB-INF" + s + "resources" + s + "fonts" + s;
// Retrieve the array of environment-dependent font sources that are searched by default.
// For example this will contain a "Windows\Fonts" source on a Windows machines.
// We add this array to a new ArrayList to make adding or removing font entries much easier.
ArrayList fontSources = new ArrayList(Arrays.asList(FontSettings.getFontsSources()));
// Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
com.aspose.words.FolderFontSource folderFontSource = new com.aspose.words.FolderFontSource(fontPath, true);
// Add the custom folder which contains our fonts to the list of existing font sources.
fontSources.add(folderFontSource);
// Convert the Arraylist of source back into a primitive array of FontSource objects.
com.aspose.words.FontSourceBase[] updatedFontSources = (com.aspose.words.FontSourceBase[])fontSources.toArray(new com.aspose.words.FontSourceBase[fontSources.size()]);
// Apply the new set of font sources to use.
FontSettings.setFontsSources(updatedFontSources);
// FontSettings.setFontsFolder(fontPath, false);
doc.save(fileOS, com.aspose.words.SaveFormat.PDF);
fileOS.close();
result = true;
but I got the wrong output
The out put are garbled text.
Do I need to set encoding format when I load the input file?
If yes, How to set it ?