Reverse Arabic for PDF printing

I am trying to print Arabic in some PDF documents using the Java code found here: http://www.java2s.com/Code/Java/PDF-RTF/ArabicTextinPDF.htm

The example works fine, except that the text goes backwards. For example, slightly changing the example:

String txt = "\u0623\u0628\u062c\u062f\u064a\u0629 \u0639\u0631\u0628\u064a\u0629";
System.out.println(txt);
g2.drawString(txt, 100, 30);

What is printed on the screen is the same characters, but in the opposite direction compared to PDF. Exit to the console is correct, PDF is not.

I don’t want to just change characters, because otherwise I will lose bidirectional support ...

Thank you so much

+3
source share
3 answers

IIRC, iText , drawString. ...

! ColumnText.showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions)

Element.ALIGN_*. PdfWriter.RUN_DIRECTION_*. - , ColumnText.AR_*

: , . CJKV, Arabic Latin, .

.

+2

, :

document.open();
java.awt.Font font = new java.awt.Font("times", 0, 30);
PdfContentByte cb = writer.getDirectContent();
java.awt.Graphics2D g2 = cb.createGraphicsShapes(PageSize.A4.width(), PageSize.A4.height());
g2.setFont(font);
String txt = "日本人 أبجدية عربية Dès Noël où";
System.out.println(txt);
java.awt.font.FontRenderContext frc = g2.getFontRenderContext();
java.awt.font.TextLayout layout = new java.awt.font.TextLayout(txt, font, frc);
layout.draw(g2, 15, 55);
g2.dispose();
document.close();

, . , / PDF-, . .

+1

Unicode Arabic ( - ) Java. PDF , . , , , , PDF , .

If I were you, I would start by studying some PDF document created in Arabic with some modern tool.

This “graphics" approach to building PDFs at best seems risky to me.

0
source

Source: https://habr.com/ru/post/1796185/


All Articles