Migration from Aspose.Pdf.Generator: String to double conversion in table cells

Hello Aspose,

I’m currently trying to migrate to Aspose.Pdf. I’m using v11.4.0.0.
I’m suffering from this problem:

Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at Aspose.Pdf.Table.??(String )
at Aspose.Pdf.Table.▬?:spades::heart:(String , Double , Boolean )
at Aspose.Pdf.Table.:slight_smile:??(Double , Page )
at Aspose.Pdf.Table.Process(Double& , Double& , Boolean , Double , Double , Page , Boolean , List`1 )
at ?:diamonds:♫.:heart::diamonds:♫.Process()
at Aspose.Pdf.Page.()
at Aspose.Pdf.Document.ProcessParagraphs()
at Aspose.Pdf.Document.Save(Stream output)

The related doubles are converted before writing to cells to target language which does not match the local language setting.
It seems so that the numbers are converted back using the local settings.

How can I switch off this behavior or how can I configure it working correctly.
Or is there a way to directly write the double in the cells.

Regards
Gerd

Hi Gerd,

Thanks for contacting support.

I have tested the scenario using following code snippet and I am unable to notice any issue. Can you please share your code snippet and some details regarding your working environment i.e. Operating System, .NET Framework version, Regional Language settings etc, so that we can again try replicating it in our environment. We are sorry for this inconvenience.

[C#]

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
doc.Pages.Add();

Aspose.Pdf.Table table = new Table();

table.ColumnWidths = "100 100";

Aspose.Pdf.Row row = table.Rows.Add();

Aspose.Pdf.Cell cell1 = row.Cells.Add("First Cell");

Aspose.Pdf.Cell cell2 = row.Cells.Add(""+ String.Format("{0:0.00}", 123.4567));

doc.Pages[1].Paragraphs.Add(table);

doc.Save("c:/pdftest/Table_in_pdf.pdf");

Hello,

I tried to reproduce within a snippet which is very close to my usage.
But I failed too. I’m dealing with different fonts and unicode
characters. My snippet is a simplification so far.

My environment is Win7, .Net 4.6, Local setting are fully German, rendering settings are different languages. In my test case en-EN. For string conversion I use “#,0.0”.

The same problem arises in header and footer tables where I definitively have no numeric values inside, only serial number, page numbering, pure text. This I can identify if I comment the header and footer tables.

I have some hundred tables inside of the test document, so I’m not able to precise identify which table rises the problem.

Is there a way how I can give you more information?
Is there an intermediate file format which I can store before rendering to PDF so that you can reproduce the problem?
Can I produce some tracing?
Do you have some debugging DLLs?
Or simply can switch off this behavior, because there is no need to convert back to double?

Regards
Gerd


Hi Gerd,


Thanks for sharing the resource file.

I have tried replicating the issue but I am afraid an object RenderingContext is not defined. Can you please share some sample project, so that we can again try replicating the issue in our environment. We are sorry for this inconvenience.

Hello,

RenderingContext.Culture can be replaced with culture from line 46.

But I could not reproduce the problem, but i gives an impression about the context.

I can only share an executable, but not public.
But it would be simpler to give you an intermediate file which you can use to replay.

Regards
Gerd

Hi Gerd,

Thanks for sharing the details.

I have again tested the scenario using following code snippet using Aspose.Pdf for .NET 11.9.0 in Studio 2015 with .NET Framework 4.5 running over Windows 10 where I have used German (Germany) as regional language and I am still unable to notice any problem. As per my observations, the PDF file is properly being generated.

For your reference, I have also attached the output files generated over my end.

[C#]

Document doc = new Document();
doc.Pages.Add();
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
double numeric = 134.4;

for (int i = 1; i <= 1000; i++)
{
    Aspose.Pdf.Row row = table.Rows.Add();
    Aspose.Pdf.Cell cell = row.Cells.Add();
    TextFragment f = new TextFragment();
    TextSegment s = new TextSegment(i.ToString(culture));
    StyleToTextInfo(s.TextState);
    f.Segments.Add(s);
    cell.Paragraphs.Add(f);
    SplitSegmentForSeldomCharacters(s, f);

    cell = row.Cells.Add();
    f = new TextFragment();
    s = new TextSegment("Phase: " + i);
    StyleToTextInfo(s.TextState);
    f.Segments.Add(s);
    cell.Paragraphs.Add(f);
    SplitSegmentForSeldomCharacters(s, f);

    cell = row.Cells.Add();
    f = new TextFragment();
    s = new TextSegment(ValueString(numeric, (i % 2 == 0) ? "V" : "", 1));
    StyleToTextInfo(s.TextState);
    f.Segments.Add(s);
    cell.Paragraphs.Add(f);
    SplitSegmentForSeldomCharacters(s, f);

    cell = row.Cells.Add();
    f = new TextFragment();
    s = new TextSegment(ToleranceString(numeric - 1, numeric + 1, (i % 2 == 0) ? "V" : "", 2));
    StyleToTextInfo(s.TextState);
    f.Segments.Add(s);
    cell.Paragraphs.Add(f);
    SplitSegmentForSeldomCharacters(s, f);

    numeric = Math.Pow(-1.0, (4)) * (Math.Abs(numeric) + 63.1);
}

doc.Pages[1].Paragraphs.Add(table);
doc.Save(testPDF);

private static void SplitSegmentForSeldomCharacters(TextSegment segment, TextFragment numeric)
{
    if (!string.IsNullOrEmpty(segment.Text) && segment.Text.Contains(NonBreakableWhiteSpaceSign))
    {
        var split = segment.Text.Split(new char[] { NonBreakableWhiteSpaceSign });
        segment.Text = split[0];
        for (int index = 1; index < split.Length; index++)
        {
            var x = split[index];
            TextSegment s = new TextSegment(NonBreakableWhiteSpace);
            StyleToTextInfo(s.TextState);
            numeric.Segments.Add(s);
            s = new TextSegment(x);
            StyleToTextInfo(s.TextState);
            numeric.Segments.Add(s);
        }
    }
}

internal static void StyleToTextInfo(TextState textInfo)
{
    textInfo.Font = FontRepository.FindFont("Arial");
    textInfo.ForegroundColor = Aspose.Pdf.Color.FromRgb(0.2, 0.2, 0.2);
    textInfo.FontSize = 7;
    textInfo.Font.IsEmbedded = true;
    textInfo.FontStyle = FontStyles.Bold;
    textInfo.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
}

private static string GetFormatString(string starter, int significantFigures)
{
    string valueFormat = "#,0";
    if (significantFigures > 0)
    {
        valueFormat += ".";
        for (int i = 0; i < significantFigures; i++)
        {
            valueFormat += "0";
        }
    }
    return starter + valueFormat;
}

private static string ValueString(double value, string unit, int significantFigures)
{
    string unitString = (string.IsNullOrWhiteSpace(unit)) ? "" : "\u202F" + unit;
    string formatString = GetFormatString("", significantFigures);
    string result = value.ToString(formatString, culture) + unitString;
    return result;
}

private static string ToleranceString(double minimum, double maximum, string unit, int significantFigures)
{
    string unitString = (string.IsNullOrWhiteSpace(unit)) ? "" : "\u202F" + unit;
    string s = string.Empty;
    if (!Double.IsNaN(minimum) && !Double.IsNaN(maximum))
    {
        s = MinMaxString(minimum, maximum, unit, significantFigures);
    }
    else if (!Double.IsNaN(minimum))
    {
        string format = GetFormatString(MinString, significantFigures);
        s = minimum.ToString(format, culture) + unitString;
    }
    else if (!Double.IsNaN(maximum))
    {
        string format = GetFormatString(MaxString, significantFigures);
        s = maximum.ToString(format, culture) + unitString;
    }
    return s;
}

private static string MinMaxString(double minimum, double maximum, string unit, int significantFigures)
{
    string unitString = (string.IsNullOrWhiteSpace(unit)) ? "" : "\u202F" + unit;
    string format = GetFormatString("", significantFigures);
    return minimum.ToString(format, culture) + FromToString + maximum.ToString(format, culture) + unitString;
}

Hello,

this is what I wrote above.
How can I share DLLs none-public?

Regards
Gerd

Gerd:
Hello,

this is what I wrote above.
How can I share DLLs none-public?
Hi Gerd,

You can share the resource files privately by following instructions specified over How to send a license?