java - PdfPcell empty output of Arabic strings -
I have that part of the code:
// string // title font Base font titlebf = null; {TitleBf = BaseFont.createFont (BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.imbed) Try it; } Hold (IOException e) {System.out.println (e.getMessage ()); } Com.itextpdf.text.Font titleFont = new com.itextpdf.text.Font (titleBf, 24); TitleFont.setColor (new basecolor (0, 0, 204)); / * * PDF creation * / document document = new document (); PdfWriter.getInstance (Document, New FileOutputStream (fc.getSelectedFile) + ".pdf")); document.open (); / * * Title * / Paragraph P = New paragraph ("Ù ?? Ø ± ØØ¨Ø§ ب٠?? Ù ??", title font); p.setSpacingAfter (20); P.setAlignment (1); // center document.ed (p); // staff document.close (); The output was empty Even when I tried to add simple pdfpcell I found the same result, Here's the way: com.itextpdf.text.font fontNormal = FontFactory.getFont (base for "Arialuni.ttf"), BaseFonts: CP1252, BaseFont.Emband, 8, Com.EtexPDF .text.fonts.Normal); Chunk bran Arabic = new chakra ("Ù ?? Ø ± ØØØØ§ ا٠?? Ø § § ?? Ù ??", font normal); InfoTab.addCell (new PDFPCL (new phrase (Chunker Arabic)); Document.add (infoTab);
Different problems may occur on play.
- Encoding: You are placing Arabic text in your source code. If you use the wrong encoding of your Java file, that text will be corrupted. If you compile your Java file using incorrect encoding, that text will get corrupted. And so on. I hope you get this idea to avoid problems like this:
"\ u0644 \ u0648 \ u0631 \ u0627 \ u0646 \ u0633 \ u0627 \ u0644 \ u0639 \ u0631 \ u0628" to avoid this Avoid the way. - As documented, right-to-left writing and Arabic ligature are only supported in the context of
PdfPCell and ColumnText . I think you are using PdfPCell , but I'm not seeing you using the cell.setRunDirection (PdfWriter.RUN_DIRECTION_RTL); Anywhere it is wrong. - You are using an object
fontNormal , but you are not telling us what font you are actually using. For example: If you are using standard type 1 font helvetica, no text will be shown, because Helvicika does not know how to present the Arabic text. Revision: You have now updated your question, showing that you are using "arialuni.ttf" Are there. However, you are using the wrong encoding: encoding for CP1252. You BaseFont.IDENTITY_H . Update should be used: By looking at the additional comment updates along with your question, I see two major errors. - You are assuming that the name of the font is
"arialuni.ttf" . This is the font file , but not the font name. Apart from this: You are asking FontFactory for this font, but have you asked FontFactory to look for fonts? Are you sure you can locate FontFactory to: c: / windows / fonts / or the file arialuni.ttf which is stored in the directory . - You are declaring a font, but you are not using it:
paragraph P = new paragraph ("\ u062D \ u064A \ u0633 \ u0648"); creates a paragraph using the default font. This is the code that works:
BaseFont bf = BaseFont.createFont ("c: // windows / fonts / Arialuni.ttf", BaseFont Identity_H, BaseFont.mbedded); Font font = new font (bf, 8); PDFPTables table = new PDFPTable (1); PDFPCL cell = new PDFPCL (new phrase ("\ u062d \ u064a \ u0633 \ u0648", font)); cell.setRunDirection (PdfWriter.RUN_DIRECTION_RTL); table.addCell (cell); document.add (table); The result looks like (zoom in):
Comments
Post a Comment