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 30, 2022 6:12 am

Hi.

We are generating documents from Microsoft CRM, and when we print text with Bulgarian it is converted into ????? in the PDF document.

Example characters here: Laboratory of Microliology (Лаборатория по Микробиология),
How can we avoid this, it's the same with other special characters.

Regards Steen Maigaard

steenmaigaardDTU
 
Posts: 7
Joined: Fri Oct 08, 2021 7:59 am

Wed Mar 30, 2022 7:27 am

Hello,

Thank you for your inquiry.
To help us investigate your issue quickly and efficiently, please provide the following information. You could attach them here or send them to us via email ([email protected]). Thanks in advance. Thanks in advance.
1) Your input file.
2) Your complete test code.
3) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
4) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Mar 30, 2022 10:02 am

Hi again.

There is no file to read from, I read directly from CRM webservice

Environment Windows 10, Danish region settings
Console app dotnet 4.6



foreach (eqasia_labtest Labtest in Labtests.Entities.Skip(1))
{

PdfDocument doc = new PdfDocument();
PdfSection section1 = doc.Sections.Add();
section1.PageSettings.Orientation = PdfPageOrientation.Landscape;
section1.PageSettings.Size = PdfPageSize.A4;
PdfPageBase page = section1.Pages.Add();
PdfMargins pdfMargin = new PdfMargins();
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
pdfMargin.Left = unitCvtr.ConvertUnits(80f, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
pdfMargin.Right = unitCvtr.ConvertUnits(30f, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
pdfMargin.Top = unitCvtr.ConvertUnits(80f, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
pdfMargin.Bottom = unitCvtr.ConvertUnits(100f, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);

int LabNameLength = ResultingName.Length;
// Load image to foreground
CreateImage(page);
if (Laboratory.Name != null)
{
WriteLaboratoryFirstName(Laboratory.Name, page, LabNameLength);
}
if (Laboratory.eqasia_Nameofinstiute != null)
{
WriteLaboratoryInstituteNameAndCountry(Laboratory.eqasia_Nameofinstiute + ", " + Laboratory.Address1_Country, page, LabNameLength);
}
PdfDocument destDoc = new PdfDocument();

float top = -40;
float bottom = -58;
float left = -60;
float right = -70;

foreach (PdfPageBase PDFpage in doc.Pages)
{
PdfPageBase newPage = destDoc.Pages.Add(PDFpage.Size, new PdfMargins(0));
newPage.Canvas.ScaleTransform((PDFpage.ActualSize.Width - left - right) / PDFpage.ActualSize.Width,
(PDFpage.ActualSize.Height - top - bottom) / PDFpage.ActualSize.Height);
newPage.Canvas.DrawTemplate(PDFpage.CreateTemplate(), new PointF(left, top));
}

destDoc.DocumentInformation.Author = "DTU";
destDoc.DocumentInformation.Title = "EARS-Net 2021 certificate of participation ";
destDoc.DocumentInformation.Producer = "DTU";

destDoc.SaveToFile(PathToSaveCertificate + "\\" + Laboratory.Address1_Country + "\\" + Laboratory.eqasia_Labnumber + ".pdf");
destDoc.Close();

} }
}
}
}

private static void WriteLaboratoryInstituteNameAndCountry(string ResultingName, PdfPageBase page, int labNameLength)
{
if (ResultingName.Length > 100)
{
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 10f, FontStyle.Bold));
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
page.Canvas.DrawString(ResultingName, font, brush, page.Canvas.ClientSize.Width / 2, 220, centerAlignment);
}
else
{
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 14f, FontStyle.Bold));
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
page.Canvas.DrawString(ResultingName, font, brush, page.Canvas.ClientSize.Width / 2, 220, centerAlignment);
}
}

private static void WriteLaboratoryFirstName(string ResultingName, PdfPageBase page, int NameLength)
{
if (ResultingName.Length > 100)
{
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 10f, FontStyle.Bold));
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
page.Canvas.DrawString(ResultingName, font, brush, page.Canvas.ClientSize.Width / 2, 200, centerAlignment);
}
else
{
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 14f, FontStyle.Bold));
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
page.Canvas.DrawString(ResultingName, font, brush, page.Canvas.ClientSize.Width / 2, 200, centerAlignment);
}


}

private static void CreateImage(PdfPageBase page)
{
PdfImage image = PdfImage.FromFile(@"c:\data\Certificate 2021.png");
float width = image.Width * 0.43f;
float height = image.Height * 0.43f;
page.Canvas.DrawImage(image, 20, 0, width, height);
}
}

steenmaigaardDTU
 
Posts: 7
Joined: Fri Oct 08, 2021 7:59 am

Thu Mar 31, 2022 1:51 am

Hello,

Thanks for your feedback.
I tested your code and did reproduce your issue. After investigation, I found that it is a font setting problem, please fix the code for setting the font as follows:
Code: Select all
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 10f, FontStyle.Bold),true);

If there is any question, just feel free to contact us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Apr 07, 2022 12:33 pm

Hi Annika.

It works perfectly now

steenmaigaardDTU
 
Posts: 7
Joined: Fri Oct 08, 2021 7:59 am

Fri Apr 08, 2022 1:12 am

Hello,

Glad to hear that.

If you encounter other issues related to our products in the future, please feel free to contact us.

Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF

cron