Hi, I am trying to convert text (.txt) files to pdf. RTL langauges (Hebrew and Arabic) and LTR language (English). The text in the converted pdf file is alligned to the left for both RTLand LTR languages which is not the expected result.
I saw a ticket that similar to my issueL Bug in converting Text file (RTL-Hebrew language) to PDF format and I have tried to add it to my code. The RTL text are now alligned to the right but the LTR text was also alligned to the right.
I don’t want to detect the language of each file and then choose the direction. Can you please help me with this issue?
I am using Aspose.Words for Java 19.7 and have 30 day trial license.
Here are my files: files.zip (48.9 KB) and here is my code:
private static void convertDocToPdf(File file) {
String outputPdfFile = new StringBuilder().append(OUTPUT_PDF_FOLDER).append(File.separator).append(FilenameUtils.removeExtension(file.getName())).append(".pdf").toString();
try {
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.TEXT);
Document doc = new Document(file.getAbsolutePath(), loadOptions);
PageSetup ps = doc.getFirstSection().getPageSetup();
ps.setLeftMargin(0.36 * 72); // 0.5 inch
ps.setRightMargin(0.36 * 72);
for(Object para : doc.getChildNodes(NodeType.PARAGRAPH, true)){
((Paragraph)para).getParagraphFormat().setBidi(true);
}
doc.save(outputPdfFile, new PdfSaveOptions());
} catch (final Exception e) {
System.out.println(e);
}
}