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.