Free Support Forum - aspose.com

AlignmentType attribute not having an effect

Hi there

I am currently testing a demo version of the pdf component.

the AlignmentType.Right doest not seem to have an effect whenever i apply it to a TextInfo.Alignment Property. The reason why I want the text aligned to the right is because the document is been generated in arabic. I have however tried aligning it to the center or right with just normal english characters, but it does not seen to have an effect. Please see code below

Pdf ReportPDF = new Pdf();

ReportPDF.PageSetup.PageHeight = PageSize.A4Height;

ReportPDF.PageSetup.PageWidth = PageSize.A4Width;

ReportPDF.TextInfo.Alignment = AlignmentType.Right;

//Add report section

Section ReportPageSection = ReportPDF.Sections.Add();

Text TxtReportTitle = new Text("this is a test of allignment");

//Enable text alignment from right to left

TxtReportTitle.Segments[0].TextInfo.IsRightToLeft = false; //I have set to true and false for this, not effect

//Enable unicode character set for the text segment

TxtReportTitle.Segments[0].TextInfo.IsUnicode = false; //I have alss set to true and false, no effect

//Set Font Name

TxtReportTitle.Segments[0].TextInfo.FontName = "Times New Roman";

//Set font size

TxtReportTitle.Segments[0].TextInfo.FontSize = 10;

//Align text to right hand side using AlignmentType enumeration

TxtReportTitle.Segments[0].TextInfo.Alignment = AlignmentType.Right; //Center does not have an effect either

ReportPageSection.TextInfo.Alignment = AlignmentType.Right; //I added this line, still no effect

ReportPageSection.Paragraphs.Add(TxtReportTitle);

ReportPDF.Save(Server.MapPath("simple33.pdf"));

Can you please advise as we need to buy this component if it works as soon as possible.

Hi,

The following code will solve your problem. You only need to set the Alignment property of the TextInfo object of Text class.

Pdf ReportPDF = new Pdf();

ReportPDF.PageSetup.PageHeight = Aspose.Pdf.PageSize.A4Height;

ReportPDF.PageSetup.PageWidth = Aspose.Pdf.PageSize.A4Width;

//Add report section

Aspose.Pdf.Section ReportPageSection = ReportPDF.Sections.Add();

Text TxtReportTitle = new Text("this is a test of allignment");

//Enable text alignment from right to left

TxtReportTitle.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Right;

//Set Font Name

TxtReportTitle.Segments[0].TextInfo.FontName = "Times New Roman";

//Set font size

TxtReportTitle.Segments[0].TextInfo.FontSize = 10;

ReportPageSection.Paragraphs.Add(TxtReportTitle);

ReportPDF.Save("simple33.pdf");

Thanks.

Thanks Adeel, it works now.