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.

Mon Jul 15, 2019 8:45 am

Hello, I am creating a new pdf and when I print special characters they are not painted or strange characters appear. The data to be painted comes from a json, I leave below the code of my application and the json:

json:

{
"Messages": {
"SendDate": "Fecha del envío: ",
"10": "Dirección de correo validada"
}
}

code c#:
Spire.License.LicenseProvider.SetLicenseFileName("license");
PdfDocument document = new PdfDocument();
PdfPageBase newPage = document.Pages.Add(PdfPageSize.A4, new PdfMargins(0));
PdfGraphicsState state = newPage.Canvas.Save();
PdfImage header = PdfImage.FromFile("xxx.png");
PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
leftAlignment.LineSpacing = 20f;
PdfStringLayouter stringLayout = new PdfStringLayouter();
var headerfont = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Bold), true);
PdfSolidBrush headerbrush = new PdfSolidBrush(Color.White);
var textfond = new PdfTrueTypeFont(new Font("Calibri", 10f, FontStyle.Regular), true);
PdfSolidBrush textbrush = new PdfSolidBrush(Color.Black);
PdfSolidBrush tittlebrush = new PdfSolidBrush(Color.FromArgb(255, 64, 72));
newPage.Canvas.DrawString(ConfigurationManager.AppSetting["Messages:SendDate"] + doc.DCreationDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"), textfond, textbrush, 60, 160,
leftAlignment);
newPage.Canvas.DrawString(ConfigurationManager.AppSetting["Messages:10"], headerfont, tittlebrush, imageInfo[0].Bounds.Width - 40, yStart, leftAlignment);
using (MemoryStream ms2 = new MemoryStream())
{
document.SaveToStream(ms2, FileFormat.PDF);
//save to byte array
byte[] toArray = ms2.ToArray();
documentBytes = new byte[toArray.Length];
documentBytes = toArray;
document.Close();
}
System.IO.File.WriteAllBytes(newpath, documentBytes);

thanks.

shane_dany
 
Posts: 2
Joined: Mon Feb 18, 2019 5:30 pm

Mon Jul 15, 2019 9:59 am

Hello,

Thanks for your post.
I tested your case with our latest Spire.PDF Pack Version:5.7 and found that the created PDF file is correct. There is no strange characters. You can refer to the attachment. As for your situation, please firstly make sure the "Calibri" font has been installed in your computer, and then I suggest you try again with the latest version. If your issue still exists after trying, please share us with the following more information to help further look into it.
1. Your created PDF file.
2. Your system information (E.g. Windows 7, 64 bit) and region setting (E.g. China, Chinese).

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Tue Jul 16, 2019 2:27 pm

Hello, i jus found the problem, The json from which I read, is in a different encoding to utf-8. I converted the json to utf-8 and the problem was solved.

thanks.

shane_dany
 
Posts: 2
Joined: Mon Feb 18, 2019 5:30 pm

Wed Jul 17, 2019 1:32 am

Hello,

I’m so delighted to hear that your issue has been resolved. Just feel free to contact us if you need other helps.
Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF