pdf file generated byiText7 does not show Chinese characters.

  • Thread starter Thread starter AndieDu
  • Start date Start date
A

AndieDu

Guest
Hi team,

I am using iText7 to generate a pdf file, and there are 2 issues i am not able to figure out:

1. I am using below code to generate the pdf file that contains Chinese characters, while i am getting below link that looks like addressing the similar issue: Display Chinese,Japanese Characters in pdf in itextSharp in c#

but unfornaturely it was in old version of iText and the current version iText7 has lots of difference, below are the code i used generate pdf file, and it is not able to show any Chinese characters

string pdfFilePath = @"D:\temp\test.pdf";
if (dgvFeedbackDetails.Rows.Count > 0)
{
Table pdfTable = new Table(dgvFeedbackDetails.Columns.Count - 1);
pdfTable.SetPadding(3);
pdfTable.SetBorder(Border.NO_BORDER);
pdfTable.SetWidth(UnitValue.CreatePercentValue(100));
pdfTable.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.LEFT);

for (int i = 0; i < dgvFeedbackDetails.Columns.Count -1; i++)
{
Cell cell = new Cell().Add(new Paragraph(dgvFeedbackDetails.Columns.HeaderText));
cell.SetBorderTop(new SolidBorder(ColorConstants.RED, 1));
cell.SetBorderBottom(new SolidBorder(ColorConstants.BLUE, 1));
pdfTable.AddCell(cell);
}

foreach (DataGridViewRow dr in dgvFeedbackDetails.Rows)
{
pdfTable.AddCell(dr.Cells[0].Value.ToString());
pdfTable.AddCell(dr.Cells[1].Value.ToString());
pdfTable.AddCell(dr.Cells[2].Value.ToString());
pdfTable.AddCell(dr.Cells[3].Value.ToString());
pdfTable.AddCell(dr.Cells[4].Value.ToString());
pdfTable.AddCell(dr.Cells[5].Value.ToString());
}

PdfWriter writer = new PdfWriter(pdfFilePath);
PdfDocument pdfDoc = new PdfDocument(writer);
Document doc = new Document(pdfDoc, PageSize.A4);
doc.Add(new Paragraph("学生详情: " + txtTesterDetails.Text));
doc.Add(new Paragraph("测试问题数:" + txtTotalQuiz.Text + ". 答对问题数:" + txtCorrectAns.Text + ". 答错问题数:" + txtIncorrectAns.Text + ". 学生分数:" + txtScore.Text));
doc.Add(new Paragraph("开始时间:" + txtStartTime.Text + ". 结束时间:" + txtFinishTime.Text + ". 用时:" + txtDuration.Text));
doc.Add(new Paragraph());
doc.Add(pdfTable);
doc.Close();
MessageBox.Show("Opening test report now...", "Test Report", MessageBoxButtons.OK, MessageBoxIcon.Information);
Process.Start(pdfFilePath);
}

2. I have a blank pdf file that has company title, and i would like to merge the data into the pdf file with company title, i tried to search such scenario but with no luck, is there anyone in here had the similar scenario done?

Continue reading...
 
Back
Top