I want read a pdf file that contains Persian characters using itext . I read from this , but words are reverse. For example "ره" instead of "هر" . I split it with "\n" and read every text in every line from end , but i think that maybe there is a better solution to read from this Pdf . That is my code :
public class Main extends JFrame {
private static final int WIDTH = 600;
private static final int HEIGHT = 600;
/**
* by Shomeis
*/
private static final long serialVersionUID = 1L;
public Main() {
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int x = dim.width / 2 - WIDTH / 2;
int y = dim.height / 2 - HEIGHT / 2;
setBounds(x, y, WIDTH, HEIGHT);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new Dimension(600, 600));
//
File pdf = new File("E:\\guide1.pdf");
if (!pdf.canRead() || !pdf.isFile()) {
System.err.println("cannot read input file " + pdf.getAbsolutePath());
return;
}
try {
PdfReader reader = new PdfReader(pdf.getAbsolutePath());
String page;
String areaText = "";
System.out.println(reader.getNumberOfPages());
for (int k = 1; k <= reader.getNumberOfPages(); k++) {
System.out.println(k);
page = PdfTextExtractor.getTextFromPage(reader, k);
String[] b = page.split("\n");
for (int i = 0; i < b.length; i++) {
for (int j = (b[i].length() - 1); j >= 0; j--) {
areaText += b[i].charAt(j);
}
areaText += "\n";
}
}
JTextArea text = new JTextArea(areaText);
JScrollPane sc = new JScrollPane(text);
text.setWrapStyleWord(true);
text.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
this.setContentPane(sc);
this.setVisible(true);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
new Main().setVisible(true);
}
}