Free Support Forum - aspose.com

Subscript 2 and document encoding

I’m currently trying to get the 2 in CO2 subscripted and used the suggested solution from the documentation and the answers Aspose have given others with the same problem. That solution is to set the IsBaseline-property of the segment containing the “2” to true and the FontSize to 5. This, however, was not to my clients liking. They really want the 2 subscripted just below CO.


Displaying a subscripted “2” in CO2 in a win forms application messagebox is done like below using Unicode:

MessageBox.Show(“CO” + “\u2082”);

This renders the correct subscript 2 after CO. Is there any way of achieving the same when saving the Aspose pdf-document to disc? I’ve tried just appending the “\u2082” when instantiating the Textinstance containing the CO2-text like below:

Text subScriptCo2 = new text(“CO” + “\2082”);

but it only renders the CO, and not the 2. Is this feasible? Is it possible to change the encoding of the Textinstance or the pdf-document itself to make this work as it would greatly simplify things for me as well as make my client happy. :slight_smile:



Hello Henric,

Thanks for using our products.

I have tested the scenario using following code snippet and as per my observations, the letter 2 is properly being subscripted below CO. The resultant PDF that I have generated with the following code is also in attachment, please take a look.

[C#]

//Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf object
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

//Create a new text paragraph with an initial text segment "Aspose"
Text text1 = new Text(sec1,"CO");
//Add the text paragraph to the section
sec1.Paragraphs.Add(text1);
//Create a new text segment into the text paragraph
Segment seg2 = text1.Segments.Add("2");

//Set the vertical alignment of text segment "seg2" to Topline by setting
//IsBaseline property ot seg2.TextInfo to true
seg2.TextInfo.IsBaseline=true;
// set the font size information for the segment
seg2.TextInfo.FontSize = 5;

//Save the Pdf
pdf1.Save(@"d:/pdftest/SubScriptTest.pdf");

I have tested the scenario using Aspose.Pdf for .NET 4.5.0. In case it does not resolve your problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Thanks for the quick response codewarior!


The solution you suggest is the one I used when my client said they wanted a properly subscripted 2 in the text. Essentially, that solution renders the two in a smaller font and aligns the bottom of the 2 with the bottom of CO which prompted me to ask if there is some way of rendering a proper subscript 2 using unicode (\u2082), much in the same manner you would do in a windows app for example.

Hello Henric,

Thanks for sharing the information.

I have tried displaying the output in windows messagebox and as per my observations, the output in PDF (based over code snippet shared in my earlier post) is same as the windows message box or I think I am missing something. Can you please share some image file that can help us in understanding the scenario ?

We apologize for your inconvenience.

I have attached two images for you. In the image named Aspose.png you can see the result I get in the PDF I have generated with your suggestion. As you can see, the 2 is in line with the text CO, and the subscript effect is just a result of the 2 having a smaller font size than the text “CO”.


In the image msbx.png you can see the result of directly writing this code in a win forms:

MessageBox.Show(“CO” + “\u2082”);

The above renders the 2 properly subscripted below the “CO” text.

It does, however, seem like my client is accepting the solution you have provided. I fear they might change their minds in the future, so I better keep on my toes and prepare. :slight_smile:

Thanks codewarior!

Hello Henric,

Thanks for the detailed information and image files.

As per your requirements, Aspose.Pdf for .NET supports the feature of displaying Unicode in PDF document. For that reason you can use #$UNICODE(UnicodeValue) tag, where the number in the macro will be translated into Unicode character. I am afraid currently I am not sure about the unicode for 2 in subscript. If you are not interested in using earlier specified approach, you may try using this one. For more related information, please visit Replaceable Symbols

In case of any further query, please feel free to contact. We apologize for your inconvenience.