c# - PDF 格式的希伯来语文本

标签 c# winforms pdf itextsharp

我写了一个 PDF 文档,我尝试用希伯来语 (UTF-8) 编写,但我不能在 Windows 窗体中使用 C# 和 Visual Studio 2010 使用以下代码。

Document Doc = new Document(PageSize.LETTER);

//Create our file stream
using (FileStream fs = new FileStream("C:\\Users\\moshe\\Desktop\\Test18.pdf", FileMode.Create, FileAccess.Write, FileShare.Read))
{
    //Bind PDF writer to document and stream
    PdfWriter writer = PdfWriter.GetInstance(Doc, fs);

    //Open document for writing
    Doc.Open();

    //Add a page
    Doc.NewPage();

    //Full path to the Unicode Arial file
    string ARIALUNI_TFF = Path.Combine("C:\\Users\\moshe\\Desktop\\proj\\gold\\fop\\gold", "ARIAL.TTF");

    //Create a base font object making sure to specify IDENTITY-H
    BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

    //Create a specific font object
    iTextSharp.text.Font f = new iTextSharp.text.Font(bf, 12);

    //Write some text
    Doc.Add(new Phrase("מה קורה", f));

    //Write some more text
    Doc.Add(new Phrase("תודה לכולם", f));

    //Close the PDF
    Doc.Close();

我把字体放在文件夹里了。

我需要做什么?

最佳答案

使用PdfPTable,然后你可以设置从右到左的模式:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Document Doc = new Document(PageSize.LETTER);

            //Create our file stream
            using (FileStream fs = new FileStream(@"C:\Users\moshe\Desktop\Test18.pdf", FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                //Bind PDF writer to document and stream
                PdfWriter writer = PdfWriter.GetInstance(Doc, fs);

                //Open document for writing
                Doc.Open();

                //Add a page
                Doc.NewPage();

                //Full path to the Arial file
                string ARIALUNI_TFF = Path.Combine(@"C:\Users\moshe\Desktop\proj\gold\fop\gold", "ARIAL.TTF");

                //Create a base font object making sure to specify IDENTITY-H
                BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                //Create a specific font object
                iTextSharp.text.Font f = new iTextSharp.text.Font(bf, 12);

                //Use a table so that we can set the text direction
                PdfPTable T = new PdfPTable(1);
                //Hide the table border
                T.DefaultCell.BorderWidth = 0;
                //Set RTL mode
                T.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                //Add our text
                T.AddCell(new Phrase("מה קורה", f));

                //Add table to document
                Doc.Add(T);

                //Close the PDF
                Doc.Close();

            }
        }
    }
}

关于c# - PDF 格式的希伯来语文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6130470/

相关文章:

c# - 通过箭头键限制按钮之间键盘焦点的移动

.net - 将所选行从 DataGridView 复制到另一个,包括图像列

javascript - 在 adobe pro 中复制粘贴动态图章

javascript - PDF 到可编辑文档

mysql - 使用 Node.js 搜索 PDF 文本并返回片段

c# - 计算 Windows 文件夹大小的最快方法是什么?

javascript - 如何在 ASP.NET WebForm 上通过 jQuery $.get() 方法访问 URL?

c# - 从 C# ASP WEB 应用程序测试 SQL 连接

c# - MySQL 返回列名而不是它们的内容

c# - 如果只关闭一个窗口,如何防止应用程序终止?