text direction

text direction

Forum member · Jan 8, 2007
What is the best way to change any texts directions?: I usually use ceTe.DynamicPDF.PageElements.Label to put text. But in some cases I need to put text with other orientation (usually I need to rotate 90º top) Any suggestion? Thanks ims

Re: text direction

Support · Jan 8, 2007
Hello, In order to change the angle for the text, you can use the Angle property of the Label page element and set it to the desired angle. Thanks, ceTe Software Support Team

Re: text direction

Forum member · Mar 26, 2007
is there a non-trigonometric way to rotate a label around its center, instead of its upper left corner?

Re: text direction

Support · Mar 26, 2007
Hello, You can rotate the label around its center using the sample code below. You will have to use the X and Y coordinates of the label as the point from where you want to rotate the label (i.e. the center). So if the label is starting at point 100,100 and its height and width is 100; then pass in 150,150 as the X and Y in your label constructor. string text = "Hello World"; Label label = new Label( text, 150, 150, 100, 21, Font.Helvetica, 18, TextAlign.Center ); label.Angle = 45; double dblAngleInRadians = -label.Angle * ( Math.PI / 180 ); float xX = (float)Math.Cos( dblAngleInRadians ); float xY = (float)Math.Sin( dblAngleInRadians ); float yX = -(float)Math.Sin( dblAngleInRadians ); float yY = (float)Math.Cos( dblAngleInRadians ); label.X -= (xX * label.Width/2) + (xY * label.Height/2); label.Y -= (yX * label.Width/2) + (yY * label.Height/2); // Add label to page page.Elements.Add( label ); Thanks, ceTe Software Support Team

Re: text direction

Forum member · Mar 26, 2007
i had trouble with this until i subtracted the last (Y) terms. could that be correct? label.X -= (xX * label.Width / 2) - (xY * label.Height / 2); label.Y -= (yX * label.Width / 2) - (yY * label.Height / 2);

Re: text direction

Support · Mar 26, 2007
Hello, I am getting the correct result when using the below lines of code: label.X -= (xX * label.Width / 2) + (xY * label.Height / 2); label.Y -= (yX * label.Width / 2) + (yY * label.Height / 2); Also make sure that you are you setting the X and Y coordinates of your label to be the center point from where you wish to pivot the label. Can you please post the code you are using so that we can take a look at it? Thanks, ceTe Software Support Team

Re: text direction

Forum member · Mar 26, 2007
thanks for reviewing this. watermark is meant to sit in the middle of a table, rather than the middle of the page, so everything's relative to tableLeft and tableTop. // set upper left of watermarkLabel to middle of table watermarkLabel.X = tableLeft + (tableWidth / 2); watermarkLabel.Y = tableTop + (tableHeight / 2); watermarkLabel.Width = tableWidth; watermarkLabel.Height = tableHeight; //this next bit to angle watermark according to table dimensions float watermarkAngleInRadians = -((float)(Math.Atan2((double)tableHeight,(double)tableWidth))); float watermarkAngle = watermarkAngleInRadians * (180 / (float)Math.PI); watermarkLabel.Angle = watermarkAngle; float xX = (float)Math.Cos(watermarkAngleInRadians); float xY = (float)Math.Sin(watermarkAngleInRadians); float yX = -(float)Math.Sin(watermarkAngleInRadians); float yY = (float)Math.Cos(watermarkAngleInRadians); watermarkLabel.X -= (xX * watermarkLabel.Width / 2) - (xY * watermarkLabel.Height / 2); watermarkLabel.Y -= (yX * watermarkLabel.Width / 2) - (yY * watermarkLabel.Height / 2);

Re: text direction

Support · Mar 27, 2007
Hello, Are you trying to add the Label to the cell of the table or just on top of the table but in the center? Thanks, ceTe Software Support Team

Re: text direction

Forum member · Mar 27, 2007
just on top. the table's not centered in the page, but the watermark has to be centered in the table. i *am* adding watermarkLabel to a TransparencyGroup, though i doubt that has to do with our conversation.

Re: text direction

Support · Mar 27, 2007
Hello, Following is a sample code that shows how to add the label to the center of the table. Table table = new Table( 100, 100, 300, 300 ); table.Columns.Add( 300 ); for ( int i = 1; i <= 15; i++ ) { Row row = table.Rows.Add( 20 ); row.Cells.Add( "" ); } string text = "Hello World"; Label label = new Label( text, (table.X + table.Width/2), (table.Y + table.Height/2), table.Width, 21, Font.Helvetica, 18, TextAlign.Center ); label.Angle = 45; double dblAngleInRadians = -label.Angle * ( Math.PI / 180 ); float xX = (float)Math.Cos( dblAngleInRadians ); float xY = (float)Math.Sin( dblAngleInRadians ); float yX = -(float)Math.Sin( dblAngleInRadians ); float yY = (float)Math.Cos( dblAngleInRadians ); label.X -= (xX * label.Width/2) + (xY * label.Height/2); label.Y -= (yX * label.Width/2) + (yY * label.Height/2); page.Elements.Add( table ); page.Elements.Add( label ); Thanks, ceTe Software Support Team