iTextSharp 创建 pdf 但只写英文 words/letters
iTextSharp creating a pdf but only the English words/letters are written
我想在 pdf 中包含乱码(希伯来语)单词和字母,但是,它创建的 pdf 没有希伯来语。
感谢您的帮助和帮手!!
这是我的代码
public void createPDF(DataTable dataTable, string destinationPath)
{
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationPath, FileMode.Create));
document.Open();
var Font = FontFactory.GetFont(“Tahoma”, 12);
PdfPTable table = new PdfPTable(dataTable.Columns.Count);
table.WidthPercentage = 100;
//Set columns names in the pdf file
for(int k = 0; k < dataTable.Columns.Count; k++)
{
PdfPCell cell = new PdfPCell(new Phrase(dataTable.Columns[k].ColumnName, Font));
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
cell.BackgroundColor = new iTextSharp.text.BaseColor(51, 102, 102);
table.AddCell(cell);
}
//Add values of DataTable in pdf file
for(int i = 0; i < dataTable.Rows.Count; i++)
{
for(int j = 0; j < dataTable.Columns.Count; j++)
{
PdfPCell cell = new PdfPCell(new Phrase(dataTable.Rows[i][j].ToString(), Font));
//Align the cell in the center
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
table.AddCell(cell);
}
}
document.Add(table);
document.Close();
}
您使用
var Font = FontFactory.GetFont(“Tahoma”, 12);
它使用许多默认设置检索字体对象,特别是编码 WinAnsiEncoding。这种编码类似于 Latin-1,特别是它不包含希伯来语字符。
要支持多种字符,请尝试使用 Identity-H:
var Font = FontFactory.GetFont(“Tahoma”, BaseFont.IDENTITY_H, 12);
此外,您必须确保您的字体副本包含希伯来字符(Tahoma 最有可能包含,但有许多字体不包含)。
我想在 pdf 中包含乱码(希伯来语)单词和字母,但是,它创建的 pdf 没有希伯来语。
感谢您的帮助和帮手!!
这是我的代码
public void createPDF(DataTable dataTable, string destinationPath)
{
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationPath, FileMode.Create));
document.Open();
var Font = FontFactory.GetFont(“Tahoma”, 12);
PdfPTable table = new PdfPTable(dataTable.Columns.Count);
table.WidthPercentage = 100;
//Set columns names in the pdf file
for(int k = 0; k < dataTable.Columns.Count; k++)
{
PdfPCell cell = new PdfPCell(new Phrase(dataTable.Columns[k].ColumnName, Font));
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
cell.BackgroundColor = new iTextSharp.text.BaseColor(51, 102, 102);
table.AddCell(cell);
}
//Add values of DataTable in pdf file
for(int i = 0; i < dataTable.Rows.Count; i++)
{
for(int j = 0; j < dataTable.Columns.Count; j++)
{
PdfPCell cell = new PdfPCell(new Phrase(dataTable.Rows[i][j].ToString(), Font));
//Align the cell in the center
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
table.AddCell(cell);
}
}
document.Add(table);
document.Close();
}
您使用
var Font = FontFactory.GetFont(“Tahoma”, 12);
它使用许多默认设置检索字体对象,特别是编码 WinAnsiEncoding。这种编码类似于 Latin-1,特别是它不包含希伯来语字符。
要支持多种字符,请尝试使用 Identity-H:
var Font = FontFactory.GetFont(“Tahoma”, BaseFont.IDENTITY_H, 12);
此外,您必须确保您的字体副本包含希伯来字符(Tahoma 最有可能包含,但有许多字体不包含)。