PDF にヘブライ文字を書き込むと、左から右に表示されます。
どうすれば方向を変えることができますか?
を使用してParagraph
います。
この例を見てください:
Document document = new Document(PageSize.A4);
String filename = ""; // Set the relative path and name for the output file
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
// Fix the path to the font if needed
BaseFont bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, true);
Font font = new Font(bf, 14);
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(36, 770, 569, 36);
column.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
String text = "הטקסט שלך בעברית"; // Your text in hebrew
column.addElement(new Paragraph(text, font));
column.go();
document.close();
この問題を処理するためにいくつかの簡単な関数を作成しました。テキストを反対側に反転し、ドキュメントに追加できるフレーズとして返します。列の問題は、書き込む場所の正確な情報が必要なことです。また、より正確な場所に書き込むために PdfContentByte を使用することをお勧めします。
public Phrase makingPhrases(string toPhrase, bool toReverse,int SF)
{
BaseFont unicode = BaseFont.CreateFont(Server.MapPath("font/mriam.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font bold = new Font(unicode, SF);
if (toReverse)
return new Phrase(revertText(toPhrase), bold);
else
return new Phrase(toPhrase, bold);
}
public string revertText(string revertTo)
{
string toret = "";
for (int i = 0; i < revertTo.Length; i++)
{
toret += revertTo[revertTo.Length - i - 1];
}
return toret.ToString();
}