I’ve just downloaded v4.4 of .NET for PDF to resolve the “Index was outside the bounds of the array.” error we were occasionally getting when calling getBuffer. It is indeed fixed in v4.4
However, we make extensive use of getStringWidth, and this seems to be returning different result in v4.4 than it did in v4.1.2
TextInfo ti = new TextInfo();
ti.FontName = “Times”;
ti.FontSize = 10;
return pdf1.GetStringWidth(“hello world”, ti);
The above code returns 45.842 in v4.1.2 but only 45.83 in v4.4
Obviously with much larger strings there is a much bigger difference.
Please tell me there’s something I/you can do to get this to return the same result it used to??
I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNET-17603. We will investigate this issue in details and will keep you updated on the status of a correction.
So to clarify, are you saying this was a deliberate change and it will be staying as it is? That’s fine if that is the case, we’ll just adjust our code.
Are there likely to be any changes again to the way this is calculated? Is there any easy calculation I can apply to convert width values pre v4.1.2 to get the values now? ie, will they always be 3% less or similar?
What I don’t understand though is this. GetStringWidth returns X. Therefore we set the width of a cell in a table to X and the text fits in the cell without any wrapping.
With the new calculations this doesn’t work as if we use the value from GetStringWidth to set the cell width then the cell isn’t wide enough and the text is wrapped.
Could you publish a sample code for the text wrapping issue for our investigation?
There is no exact calculation for old and new version, and unfortunately we can’t guarantee the Pdf.GetStringWidth algorithm will be unchanged in the nearest release, but I think the correction value isn’t greater than 0.001 point on each char for Times, 10 or ~0.0001*P, where P is size font in points.
The GetMaxColWidth returns correct cell width value depend on text, cell padding, border width.
Here is a sample:
string[] str = {“Lorem ipsum”, “Lorem ipsum dolor set amet”, “123”}; Pdf pdf = new Pdf(); Section section = pdf.Sections.Add(); TextInfo ti = new TextInfo(); ti.FontName = “Courier New”; ti.FontSize = 10;
Table table = new Table(); table.DefaultCellBorder = new BorderInfo((int)BorderSide.All, new Color(“Blue”)); MarginInfo defPadding = new MarginInfo(); defPadding.Left = 20; defPadding.Right = 20; table.DefaultCellPadding = defPadding; table.DefaultCellTextInfo = ti; Row row = table.Rows.Add();
//fill table
for(int i = 0; i < 3; i++) { Cell cell = row.Cells.Add(); cell.Paragraphs.Add(new Text(str[i])); }
//it’s to adjust column width
for (int i = 0; i < 3; i++ ) { table.SetColumnWidth(i, table.GetMaxColumnWidth(pdf, i)); }
Re-writing this is going to cost us a lot of time and hassle. And if it's possible that we'll need to re-write again in the future then it's not something I'd want to commit the time to getting done.
Is there any possibility of you adding a flag/setting so we can force the dll to use the same calculations from v4.1.2?
If you change fundamental stuff like this without giving users the ability to stick with the old way of doing it then it's not possible to build an application using your software.
We have reverted back the mechanism to return values for GetStringWidth as presented in 4.1.2. It will be included in the latest version of Aspose.Pdf for .NET which will be published sometimes soon. Please be patient and spare us little time. Once the version becomes available, we would be pleased to update you with the status of correction.
Thanks for your cooperation and understanding. We are sorry for the delay and inconvenience.
I have tested the scenario using following code snippet with Aspose.Pdf for .NET 5.0.1 over WindowsXP SP3 and as per my observations, the method pdf.GetStringWidth is returning 45.842. Can you please share the code snippet that you are using so that we can test the scenario at our end. We apologize for your inconvenience.
[C#]
Pdf pdf = new Pdf(); Aspose.Pdf.Section section = pdf.Sections.Add(); Aspose.Pdf.TextInfo ti = new Aspose.Pdf.TextInfo(); ti.FontName = "Times"; ti.FontSize = 10; MessageBox.Show("" + pdf.GetStringWidth("hello world", ti));
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.