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 May 31, 2023 2:46 pm

Hi, I'm using freespire.PDF to create a pdf.

When using the right alignment options on grid cells or drawstring adding a £ symbol anywhere on the line it appears to add an extra space to the end of the line, so it is no longer right aligned. If I use a $ symbol is works fine, so it appears to be just the £ symbol with the issue.

Sample code to reproduce.

Code: Select all
PdfDocument document = new PdfDocument();
document.Pages.Add();
PdfPageBase page = document.Pages[0];
RectangleF rctg1 = new RectangleF(x, y, 280, 712);
RectangleF rctg2 = new RectangleF(x, y+80, 280, 712);
//works as expected
page.Canvas.DrawString( "Hello \nWorld", arialNormal, mainBrush, rctg1,new PdfStringFormat() { Alignment = PdfTextAlignment.Right});
//alignment not correct
page.Canvas.DrawString("Hello \n£World", arialNormal, mainBrush, rctg2, new PdfStringFormat() { Alignment = PdfTextAlignment.Right });




Can you suggest a workaround or fix?

Thanks
Andy

andyjmills
 
Posts: 2
Joined: Tue Nov 05, 2019 2:46 pm

Thu Jun 01, 2023 6:01 am

Hello,

Thanks for your inquiry.
I tested your sample code and did reproduce the issue you mentioned. After investigation, I found that the issue was caused by incorrect settings of "arialNormal". Please refer to the modified code below and test it.
Code: Select all
 PdfDocument document = new PdfDocument();
            document.Pages.Add();
            PdfPageBase page = document.Pages[0];
            int x = 0;
            int y = 0;
            RectangleF rctg1 = new RectangleF(x, y, 280, 712);
            RectangleF rctg2 = new RectangleF(x, y + 80, 280, 712);


            //Using PdfFont may lead to encoding issues with special characters.
            //PdfFont arialNormal = new PdfFont(arialFamily, 12, PdfFontStyle.Regular);

            //When using PdfTrueTypeFont, setting the "true" parameter indicates the use of Unicode encoding,
            //and special characters typically do not pose formatting issues.
            PdfTrueTypeFont arialNormal = new PdfTrueTypeFont(new Font("Arial", 12), true);

            //Create a black color brush object.
            PdfBrush mainBrush = new PdfSolidBrush(new PdfRGBColor(0, 0, 0));

            page.Canvas.DrawString("Hello \nWorld", arialNormal, mainBrush, rctg1, new PdfStringFormat() { Alignment = PdfTextAlignment.Right });
            //alignment not correct(alignment is correct now)
            page.Canvas.DrawString("Hello \n£World", arialNormal, mainBrush, rctg2, new PdfStringFormat() { Alignment = PdfTextAlignment.Right });

            document.SaveToFile("result-2.pdf", FileFormat.PDF);

Looking forward to your test feedback.

Sincerely
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Thu Jun 01, 2023 9:42 am

Perfect. Thank you. It works fine now.

Thanks for the quick reply.

Andy

andyjmills
 
Posts: 2
Joined: Tue Nov 05, 2019 2:46 pm

Thu Jun 01, 2023 9:55 am

Hello,

You're welcome.
If you encounter other issues related to our products in the future, please feel free to contact us.
Have a nice day!

Sincerely,
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Thu Jun 08, 2023 1:30 pm

Just for your information,
The same problem occurs when the text contains accented characters (as is often the case in French).
The proposed solution applies perfectly in this case!
Thanks for the solution!

alytech91
 
Posts: 1
Joined: Thu Jun 08, 2023 1:27 pm

Fri Jun 09, 2023 1:57 am

alytech91 wrote:Just for your information,
The same problem occurs when the text contains accented characters (as is often the case in French).
The proposed solution applies perfectly in this case!
Thanks for the solution!

Hello,

Glad to hear that the solution provided by our team was able to help you.
If you have any further questions, please feel free to contact us at any time.
Have a nice day!

Sincerely,
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Return to Spire.PDF

cron