Escape sequences in TextFragment are not being validated

string s = “This is \t a \n plain text”;
TextFragment textFragment = new TextFragment(s);
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont(“Arial”);
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);

// The output must be -
//This is a
//plain text.

But I get
//This is a plain text.

Is there any way to make this work ? I have seen a few post saying where TextFragment doesn’t support ‘\n’ and I want to clarify if it’s the same for all the escape sequences.

@crajagopalan

Would you kindly try ‘\r\n’ characters for a line break as we have tested it in our environment and we got correct output. For your kind reference, a sample output PDF is also attached. In case you need further assistance, please feel free to let us know.
19.9.pdf (28.5 KB)

“\r\n” is working fine.
Is there no support for other escape sequences like “\t” ?

@crajagopalan

We have logged an issue as PDFNET-46998 in our issue tracking system about \t not being honored by the API. We will further look into details of the logged issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Thanks for the looking into this. Can you please look into all the escape sequences as well if possible because it might be easy to copy the the text rather than replacing them with Environment.Newline and other characters. Aspose.Cell supports all the escape sequence it would be nice if Aspose.PDF supports it too.
All the escape sequences :

  • \' – single quote, needed for character literals
  • \" – double quote, needed for string literals
  • \\ – backslash
  • \0 – Unicode character 0
  • \a – Alert (character 7)
  • \b – Backspace (character 8)
  • \f – Form feed (character 12)
  • \n – New line (character 10)
  • \r – Carriage return (character 13)
  • \t – Horizontal tab (character 9)
  • \v – Vertical quote (character 11)
  • \uxxxx – Unicode escape sequence for character with hex value xxxx
  • \xn[n][n][n] – Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
  • \Uxxxxxxxx – Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

@crajagopalan

Sure, we will surely check feasibility for all these escape characters and let you know as soon as we have some additional updates.

1 Like