Page 1 of 1

Konvertieren Sie die koreanische Sprache in PDF [geschlossen]

Posted: 21 Mar 2025, 10:00
by Anonymous
Ich möchte ein DataTable in PDF konvertieren, aber meine Spaltenüberschriften für DataTable befinden sich in koreanischer Sprache. Wenn ich dies in PDF konvertiere, wird der koreanische Sprachtext nicht angezeigt. Wie kann ich das lösen? < /P>

Code: Select all

public void pdfdata()
{
try
{
int totalrecord = dt.Rows.Count;
//Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
string[] columnNames = (from dc in dt.Columns.Cast()
select dc.ColumnName).ToArray();
int count = columnNames.Length;
object[] array = new object[count];
dt.Rows.Add(array);
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
System.IO.MemoryStream mStream = new System.IO.MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);
pdfDoc.Open();

table = new PdfPTable(1);
table.TotalWidth = 700f;
table.LockedWidth = true;
table.SetWidths(new float[] { 0.7f });
cell = ImageCell("../images/Aksharalogo.png", 100f, PdfPCell.ALIGN_CENTER);
table.AddCell(cell);
pdfDoc.Add(table);

iTextSharp.text.Table pdfTablehead = new iTextSharp.text.Table(2, 1);
pdfTablehead.BorderWidth = 0; pdfTablehead.Width = 100;
pdfTablehead.Padding = 1; pdfTablehead.Spacing = 4;

Cell cellRowshead = new Cell();
iTextSharp.text.Font RowFonthead = FontFactory.GetFont("Arial", 15, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.GRAY);
Chunk chunkRowshead = new Chunk(Name + " : ", RowFonthead);
cellRowshead.HorizontalAlignment = Element.ALIGN_LEFT;
cellRowshead.BorderColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#fff"));
cellRowshead.Add(chunkRowshead);
pdfTablehead.AddCell(cellRowshead);

Cell cellRowshead1 = new Cell();
iTextSharp.text.Font RowFonthead1 = FontFactory.GetFont("Arial", 15, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.GRAY);
Chunk chunkRowshead1 = new Chunk("Total Records:" + totalrecord, RowFonthead1);
cellRowshead1.HorizontalAlignment = Element.ALIGN_RIGHT;
cellRowshead1.BorderColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#fff"));
cellRowshead1.Add(chunkRowshead1);
pdfTablehead.AddCell(cellRowshead1);

pdfDoc.Add(pdfTablehead);
int cols = dt.Columns.Count;
int rows = dt.Rows.Count;

iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(cols, rows);
pdfTable.BorderWidth = 1; pdfTable.Width = 100;
pdfTable.Padding = 1; pdfTable.Spacing = 4;
pdfTable.CellsFitPage = true;

for (int i = 0; i < cols; i++)
{
Cell cellCols = new Cell();
if (i == 0)
cellCols.Width = 10f;
Chunk chunkCols = new Chunk();
iTextSharp.text.Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 14, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.WHITE);
cellCols.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#4bb75f"));
chunkCols = new Chunk(dt.Columns[i].ColumnName, ColFont);

cellCols.Add(chunkCols);
pdfTable.AddCell(cellCols);

cellCols.BorderColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"));
pdfTable.BorderColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"));
}

for (int k = 0; k < rows; k++)
{
for (int j = 0; j < cols;  j++)
{
Cell cellRows = new Cell();
if (k % 2 == 0)
{
cellRows.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"));
cellRows.BorderColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"));
cellRows.Width = 25f;
}
else
{
cellRows.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#ffffff"));
cellRows.BorderColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"));
}
iTextSharp.text.Font RowFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);
Chunk chunkRows = new Chunk(dt.Rows[k][j].ToString(), RowFont);
cellRows.Add(chunkRows);
pdfTable.AddCell(cellRows);
}
}
pdfDoc.Add(pdfTable);
pdfDoc.Close();
HttpContext.Current.Response.ContentType = "application/octet-stream";
// HttpContext.Current.Response.ContentType = "application/pdf";
//HttpContext.Current.Response.ContentType = "application/octet-stream;charset=utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + Name + ".pdf");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BinaryWrite(mStream.ToArray());
HttpContext.Current.Response.End();

}
catch (Exception ex)
{

}
}