Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Mar 13, 2024 6:56 am

First of all, I am sorry for using a translator because I am not good at English.
I made a pdf on .net now.
But if you say "hangul", the letters are broken.
I've looked for support for the utf-8 format, but I can't see it, so I'm inquiring.
Does utf-8 format support when creating a pdf?

tlarmsdud111
 
Posts: 3
Joined: Wed Mar 13, 2024 6:52 am

Wed Mar 13, 2024 8:28 am

Hello,

Thanks for your inquiry.
Sorry, our Spire.PDF currently does not have a specific method to specify the character set as utf-8 when creating a PDF. But we suspect that the problem with you is not caused by the character set. To help us further investigation, please provide us with your complete test code. Thank you in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Wed Mar 13, 2024 8:50 am

There are no other special settings. The English section works fine. However, Hangul's handwriting is broken. Here are the currently working codes. From the letters in the title section "테스트" to Hangul in the data table, all the letters are broken. Is there a way?

PdfDocument doc = new PdfDocument();
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;

PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

float yy = 10;
PdfBrush brush1 = PdfBrushes.Black;
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Times New Roman", 16f, FontStyle.Bold));
PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

page.Canvas.DrawString("Report", font1, brush1, page.Canvas.ClientSize.Width / 2, yy, format1);
page.Canvas.DrawString("테스트", font1, brush1, page.Canvas.ClientSize.Width / 2, yy + 30, format1);

tlarmsdud111
 
Posts: 3
Joined: Wed Mar 13, 2024 6:52 am

Thu Mar 14, 2024 1:32 am

Hello,

Thanks for your feedback.
Kindly note that the "Time new Roman" font does not support displaying Hangul. Please use the following way to create a font and draw Korean. If you have any further questions, please feel free to write to us.
Code: Select all
PdfCjkStandardFont cjkFont = new PdfCjkStandardFont(PdfCjkFontFamily.HanyangSystemsGothicMedium, 11f);
...
page.Canvas.DrawString("테스트", cjkFont, brush1, page.Canvas.ClientSize.Width / 2, yy + 30, format1);

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Thu Mar 14, 2024 2:26 am

Thank you for your answer. I checked that Hangul is working properly. I'm sorry, but can I ask you one more question?
I use aspose.pdf's datatable to bind data in table format. However, it still breaks letters on the table. Can I use the same font on the table? I couldn't find where to set the font.
Also, the header part of the data table does not apply.
I'll share the file with my code.

dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
dataTable.Columns.Add("Department");
dataTable.Columns.Add("Position");
dataTable.Columns.Add("Level");
dataTable.Columns.Add("test");
dataTable.Columns.Add("t1");
...
dataTable.Rows.Add(new string[] { reportlist.ObsList[i].StationName, reportlist.ObsList[i].PGA_html,
reportlist.ObsList[i].Spectrum_Html, reportlist.ObsList[i].Ukest.ToString(), reportlist.ObsList[i].LCQStatus,
reportlist.ObsList[i].VEPStatus, reportlist.ObsList[i].VKIStatus });
...
PdfTable table = new PdfTable();
table.Style.CellPadding = 2;
table.Style.HeaderSource = PdfHeaderSource.Rows;
table.Style.HeaderRowCount = 1;
table.Style.ShowHeader = true;
table.DataSource = dataTable;

//Show header(the header is hidden by default)
table.Style.ShowHeader = true;

//Set font color and backgroud color of header row
table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Gray;
table.Style.HeaderStyle.TextBrush = PdfBrushes.White;

//Set text alignment in header row
table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

//Set text alignment in other cells
for (int i = 0; i < table.Columns.Count; i++)
{

table.Columns[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

}
//Register with BeginRowLayout event
//table.BeginRowLayout += Table_BeginRowLayout;

//Draw table on the page
table.Draw(page, new PointF(0, 60));

//Save the document to a PDF file
doc.SaveToFile("PdfTable.pdf");

tlarmsdud111
 
Posts: 3
Joined: Wed Mar 13, 2024 6:52 am

Thu Mar 14, 2024 3:24 am

Hello,

Thanks for your feedback.
Do want to set the font for the header and other cells? If so, please refer to the code snippet below. If there are any misunderstandings, please reply to us with more details about your issue. Thank you in advance.
Code: Select all
PdfTable table = new PdfTable();
PdfCjkStandardFont cjkFont = new PdfCjkStandardFont(PdfCjkFontFamily.HanyangSystemsGothicMedium, 11f);
table.Style.DefaultStyle.Font = cjkFont;
table.Style.HeaderStyle.Font = cjkFont;
...

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF