We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

$D replacement

I am using Aspose pdf for .net
When I add a cell to a table that includes the text ‘$D’, it is replaced with the date.
I do not want to have the text replaced with the date.
Is there a way I can turn off replacement, and is there a way to turn it off in a table.

newCell = newRow.Cells.Add($"{partNumber} $D");

I saw this old forum thread: Escaping the dollar sign in Visual C#
The links in it do not work and the thread is very old - I’m not sure the info is still up-to-date.
For instance, I cannot find a IsSystemReplaceable flag in the documentation.

Thanks for any help!

@bhoenes1,

Can you please share complete working sample code along with source file so that we may further investigate to help you out.

The problem is having the $D in the cell.
We have part numbers that actually contain “$D”.
But here you go.

    public Document CreatePdfReport(GacDto gacDto)
    {
        Document newDocument = CreateDocument();

        CreateTestPage(newDocument);

        newDocument.Save("C:\\temp\\PdfTesting\\" + "TestReport.pdf");
}


    private void CreateTestPage(Document document)
    {
        Page newPage = CreatePage(document);

        var newTable = AddTestTable();
        newPage.Paragraphs.Add(newTable);
    }

    private Table AddTesttTable()
    {
        var newTable = CreateTable();
        newTable.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;

        AddTestColumnTitles(newTable);
        AddTestRows(newTable);

        return newTable;
    }

     private void AddAssayLayoutColumnTitles(Table table)
     {
        Row newRow;
        Cell newCell;

        newRow = table.Rows.Add();
        newRow.Border = new BorderInfo(BorderSide.Bottom | BorderSide.Left | BorderSide.Right, 0.1f);
        newRow.BackgroundColor = Color.DarkGray;
        newCell = newRow.Cells.Add("Part Number");
        newCell.Alignment = HorizontalAlignment.Center;
  }

    private void AddTestRows(Table table)
    {
        Row newRow = table.Rows.Add();
        newRow.BackgroundColor = rowCount++ % 2 > 0 ? Color.White : Color.LightYellow;
        newRow.Border = new BorderInfo(BorderSide.All, 0.1f);
        Cell newCell = newRow.Cells.Add("I123$D");
        newCell.Alignment = HorizontalAlignment.Center;
     }

A part number that should be this “I2GZ$D8Z”
Is showing up like this in the cell “I2GZ11/03/20208Z” because of the date replacement caused by $D.

@bhoenes1,

I have observed your comments and like to inform that if you want to avoid this than please use following method and share feedback with us if there is still an issue.

$ D

@Adnan.Ahmad

Thank you for this potential solution.
However, inserting a space to prevent replacement is not really a solution for me.
Now the part number shows up in the cell as “I2GZ$ D8Z” when it should be “I2GZ$D8Z”.
The characters in our part numbers have meaning and are important.

Is there a way to turn off the replacement so it does not happen?
Or to somehow quote my string so it doesn’t happen?

Hi Ahmad
I thought I would check and find out if you have been able to find any further information about how to disable replacement of $D (and other similar strings).

@bhoenes1,

Thanks for sharing further details.

We have logged an investigation ticket as PDFNET-47848 in our issue tracking system. We will further look into details of it and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

@Adnan.Ahmad
Hi Ahmad
I thought I would check in again and find out if you have been able to find any further information about how to disable replacement of $D (and other similar strings).

@bhoenes1,

I regret to inform that issue is still unresolved. We will share good news with you soon. I request for your patience.

I thought I would check in again and find out if there is any further information about how to disable replacement of $D (and other similar strings).

@bhoenes1

Regretfully, the ticket is not yet resolved. However, you could please use HtmlFragment as a workaround to escape $ sign like following:

row.Cells.Add().Paragraphs.Add(new HtmlFragment("<p>$D</p>"));

@asad.ali Thank you. I have verified that this does allow a $D (and a $P) to be placed in a string.
However, I set the font information of the table I create to:
newTable.DefaultCellTextState.Font = FontRepository.FindFont(“Calibri”);
newTable.DefaultCellTextState.FontSize = 8f;
newTable.DefaultCellTextState.FontStyle = FontStyles.Regular;
The HTML fragment does not seem to obey these settings.
I am not familiar with using HTML fragments - Is there a way to make the HTML fragment also use these setting (or style it with these settings).

html fragment: image.png (6.0 KB)

normal cell: image.png (3.9 KB)

@asad.ali Also, I notice that when I use the HTML fragment, that this statement:
document.ProcessParagraphs();
causes a bunch of these errors (only shown a small number of them):
Exception thrown: ‘System.ArgumentException’ in System.Drawing.Common.dll
Exception thrown: ‘System.ArgumentException’ in System.Drawing.Common.dll
Exception thrown: ‘System.ArgumentException’ in System.Drawing.Common.dll
Exception thrown: ‘System.ArgumentException’ in System.Drawing.Common.dll

And if I don’t use HTML fragment, I don’t get these errors.

@bhoenes1

HtmlFragment also offers TextState Property to set the font and different styles.

HtmlFragment html = new HtmlFragment("<p>$D</p>");
html.TextState.Font = FontRepository.FindFont("Calibri");
row.Cells.Add().Paragraphs.Add(html);

Would you kindly share a minimum sample code snippet that is able to reproduce the issue that you are facing. We will surely test the scenario in our environment and address it accordingly.

Any update on this?
I am running into the issue where I need to display text that includes “$D” and “$P” and it’s being replaced. I tried using Htmlfragments but the performance impact was too high to be a viable solution. Is there no way to just escape the $ character?

@SamuelMcd1 - After having Aspose not give me any help with this for a very long time, then finally give me some help that led to more errors (using HTML fragments). And then Aspose asked me to again to post simplified code that reproduced the errors described, so I looked for an alternate solution.

I parsed each output item looking for the $D/$P/$p and inserted a non-printable character between the $ and the D/P/p.
The character I inserted is the char 2 (which is the STX character). It seems to work OK.
My code is like this:

            char c = (char)2;
            if (outerPartNumber.Contains("$D"))
            {
                outerPartNumber = outerPartNumber.Replace("$D", "$" + c + "D");
            }
            else if (outerPartNumber.Contains("$P"))
            {
                outerPartNumber = outerPartNumber.Replace("$P", "$" + c + "P");
            }
            else if (oligoRow.OuterPartNumber.Contains("$p"))
            {
                outerPartNumber = outerPartNumber.Replace("$p", "$" + c + "p");
            }

And then it no longer tries to process into a date or page.
It’s kind of a hack, but Aspose really wasn’t being very helpful or responsive with this.
Good luck!

@bhoenes1
That is a genius workaround. I’ll give it a shot. Thank you!

@bhoenes1

We really apologize for the inconvenience faced due to this behavior of the API. Please note that in order to address an issue appropriately, we need to get complete details of the scenario. That is why we asked for a runnable complete sample code snippet. There is quite a chance that just due to little modifications in the code snippet, the issue would not occur.

Nevertheless, it is nice to hear that you were able to resolve your issue. You shared workaround would also help others who are facing similar issue. As far as the logged ticket is concerned, we will update this forum thread once it is fixed.

@asad.ali I appreciate the attention you gave to this issue, thank you.

1 Like