I am trying to create a report in arabic and english for shane content report has a table , in case of arabic report table is printing properly RTL if i save word file to PDF but it is not working in case of Savind word file in word format. see below are the templates i am using to generate report.
AuditDocReport_ar.docx (26.3 KB)
AuditDocReport_en.docx (25.9 KB)
below iare the output files in word and pdf format. PDF is correct .
application (8).docx (19.5 KB)
application (7).pdf (41.5 KB)
Below is the code i am saving both the file.
if (downloadWord)
{
wordDoc.save(os, SaveFormat.fromName("DOCX"));
report.setBase64(Base64.getEncoder().encodeToString(os.toByteArray()));
report.addAttribute(new Attribute<Integer>("r_content_size", os.size()));
report.setType("legal_doc");
report.setDoc_extension(contMeta.getDosExtension());
report.setContentMimetype(contMeta.getMimeType());
}
else
{
//To save word template to PDF file
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
wordDoc.save(os, pdfSaveOptions);
//report.setBase64(Base64.getEncoder().encodeToString(((ByteArrayOutputStream)os).toByteArray()));
report.setBase64(Base64.getEncoder().encodeToString(os.toByteArray()));
report.addAttribute(new Attribute<Integer>("r_content_size", os.size()));
report.setType("legal_doc");
report.setDoc_extension("pdf");
report.setContentMimetype("application/pdf");
}
@rakeshramesh
Can you please specify which Aspose.Words method you are using to save the Word file, and what specific issues you are encountering with the table direction when saving in Word format?
@rakeshramesh You should set table direction in you template to RTL:
Here is an update template: AuditDocReport_ar.docx (26.7 KB)
Alternatively you can set table direction in the code:
Document doc = new Document("C:\\Temp\\in.docx");
Table t = doc.getFirstSection().getBody().getTables().get(0);
t.setBidi(true);
doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf");
Hi @alexey.noskov,
I have already changed the table direction in my template, but it is still not working.
I am saving the Word document using the save
function of the Word Document class.
Could you please help me figure out what might be going wrong?
Regards,
@rakeshramesh Have you tried changing table direction in your template before passing it to Aspose.Words?
yes, please find attached.
AuditDocReport_ar.docx (27.4 KB)
@rakeshramesh I cannot reproduce the problem on my side using the following simple code:
Document doc = new Document("C:\\Temp\\AuditDocReport_ar.docx");
doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf");
out.docx (22.7 KB)
out.pdf (41.9 KB)
@alexey.noskov ,
Please find my code below. I am saving the Word file to a Java output stream, while you have saved it directly to a file. Could this be the reason it is not working for me?
Java Code .zip (6.6 KB)
@rakeshramesh It looks like the problem occurs when bidi
property is set in the table style. The problem can be reproduced with the following simplified code:
Document doc = new Document("C:\\Temp\\AuditDocReport_ar.docx");
Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
// Set table style.
TableStyle tableStyle = (TableStyle) table.getDocument().getStyles().add(StyleType.TABLE, "SLCAuditStyle");
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
tableStyle.setBidi(true);
table.setStyle(tableStyle);
// set table properties to bidi
table.setBidi(true);
doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf");
If comment the following line ofcode:
tableStyle.setBidi(true);
the table looks correct.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28209
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@alexey.noskov .
Thank you very much for your kind support. I sincerely appreciate your help and the time you have dedicated.
Regards,
1 Like