1

I am wiriting HTML to PDF Conversion of Arabic Text from Itext 5.5.11 and ITextRenderer but the The letters are reversed

I tried to follow the answer of this question, Arabic characters from html content to pdf using iText

but the problem is always posed

My fonction is like :

public void createPdf(String templateName, Map map) throws Exception {
        Assert.notNull(templateName, "The templateName can not be null");
        Context ctx = new Context();
        if (map != null) {
            Iterator itMap = map.entrySet().iterator();
            while (itMap.hasNext()) {
                Map.Entry pair = (Map.Entry) itMap.next();
                ctx.setVariable(pair.getKey().toString(), pair.getValue());
            }
        }

        String processedHtml = templateEngine.process(templateName, ctx);
        FileOutputStream os = null;
        //String fileName = UUID.randomUUID().toString();
        try {
            // final File outputFile = File.createTempFile(fileName, ".pdf");
            os = new FileOutputStream(new File(directoryPathConfig.getPathDefaultDirectory("pdfOutput.path")).getAbsolutePath() + "/World.pdf");
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocumentFromString(processedHtml,new ClassPathResource("/static/").getURL().toExternalForm());
            renderer.getFontResolver().addFont("fonts/NotoNaskhArabic-Regular.ttf", "Noto Naskh Arabic", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);
            renderer.layout();
            renderer.createPDF(os, false);

            renderer.finishPDF();
            System.out.println("PDF created successfully");
        }
        finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) { /*ignore*/ }
            }
        }
    }

In my themplate I did it like this :

<p dir="rtl" style="font-family: Noto Naskh Arabic;text-align: center;text-decoration: underline; font-size: 18px;">الشباك الوحيد للجماعة</p>
AyoubMK
  • 526
  • 1
  • 4
  • 19
  • You are using a third party product that is not endorsed by iText Group. You should use the official iText software! Use iText 7 [the pdfHTML add-on](http://itextpdf.com/itext7/pdfHTML). You will also need the pdfCalligraph add-on for the Arabic text. – Bruno Lowagie Jun 17 '17 at 17:10
  • Also: Thymeleaf is Apache licensed; iText is AGPL licensed; and I suspect that you are using Flying Saucer which is LGPL licensed. Are you sure you don't have any licensing issues? – Bruno Lowagie Jun 17 '17 at 17:18

0 Answers0