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

Free Support Forum - aspose.com

Text Background and Alignment

Hi,

I have same the problem in getting the text to change the text alignment to center and I am using Aspose.Pdf version 8.8.0.0.

Here is my code.

using (Aspose.Pdf.Document Doc = new Aspose.Pdf.Document(input))
{
foreach (Aspose.Pdf.Page page in Doc.Pages)
{

Aspose.Pdf.FloatingBox fb = new Aspose.Pdf.FloatingBox();
fb.Top = 520.0f;
//this was the version 1
//fb.Left = 331.0f;

fb.Left = -40.0f;
fb.Width = 510.23f;
fb.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
fb.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
fb.IsNeedRepeating = false;
//fb.IsExtraContentClip = true;
fb.IsKeptWithNext = false;

Aspose.Pdf.Table table = new Aspose.Pdf.Table();
//Set default cell border using BorderInfo object
//table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F, Aspose.Pdf.Color.Red);


//Set with column widths of the table
table.ColumnWidths = "100%";
Aspose.Pdf.Row row = new Row();
row.DefaultCellPadding = new MarginInfo(12,3,12,3);
Aspose.Pdf.Text.TextState textState = new Aspose.Pdf.Text.TextState();
textState.HorizontalAlignment = HorizontalAlignment.Center;
row.DefaultCellTextState = textState;

Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell();
float fontSize = 12.0f;
cell.Alignment = HorizontalAlignment.Center;
HorizontalAlignment alignment = Aspose.Pdf.HorizontalAlignment.Center;
Aspose.Pdf.Text.TextFragment txtFragment = new Aspose.Pdf.Text.TextFragment();
txtFragment.TextState.HorizontalAlignment = alignment;

// Add a text segment to text together
Aspose.Pdf.Text.TextSegment segmentText = new Aspose.Pdf.Text.TextSegment();
Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");
font.IsEmbedded = true;
segmentText.TextState.Font = font;
segmentText.TextState.FontSize = fontSize;
segmentText.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Regular;
segmentText.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
segmentText.TextState.HorizontalAlignment = alignment;
segmentText.Text = "The Govt estimates that the Federal carbon tax and green energy schemes add about $100 a year to a typical 6.5MWh household bill.";

txtFragment.Segments.Add(segmentText);
cell.Paragraphs.Add(txtFragment);

row.Cells.Add(cell);
table.Rows.Add(row);

fb.Paragraphs.Add(table);
page.Paragraphs.Add(fb);
}

Doc.Save(stream);v

Hi Danny,


Thanks for your query. I am afraid I am unable to understand the issue, as I have tried your sample code and text of floating box is being centered aligned properly. Can you please share some more details about the issue and your sample input/output documents? So we will test the scenario and will provide you more information.

We are sorry for the inconvenience caused.

Best Regards,

Hi Tilal,

The text is not center aligned, please refer attached document, The output of the text.doc

Regards,

Danny

Hi Danny,

Thanks for sharing additional information. While testing the scenario with the latest version of Aspose.Pdf for NET 8.8.0, We have managed to notice that second line of text is not being aligned as expected and logged it in our bug tracking system as PDFNEWNET-36249 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

We are trying to implement your pdf generator but still waiting for you to fix text alignment. We already bought the Aspose Total for .NET. We need this fix.

Thanks,

Danny

Hi Danny,


Thanks for your inquiry. I am afraid your reported issue is pending for investigation in the queue with other priority tasks. However we have requested our development team to complete the investigation and share an ETA at their earliest. As soon as we get a feedback, we will update you via this forum thread.

Thanks for your patience and cooperation.

Best Regards,

Hi Danny,

i have had the same problem, you can use the x and y coordinates to calculate the center pos by yourself.

i.e. like this:

var fragment = new Aspose.Pdf.Text.TextFragment(“blablabla”);
trackingCodeXPos = theWholeWidth / 2;
trackingCodeXPos -= (float)fragment.Rectangle.Width / 2;
_trackingCodeTextHeight = fragment.Rectangle.Height; // Aspose Bug

fragment.Position = new Aspose.Pdf.Text.Position(trackingCodeXPos, trackingCodeYPos - _trackingCodeTextHeight);
trackingCodeTextBuilder.AppendText(fragment);

Greetz
Sebbe

Hi Sebbe,

Thanks, it mine case, I have split my string into append each text into the floating box.

I have got it working.

Regards,

Danny

Hi Danny,


I am glad to hear that you have found a workaround for your problem. However we will definitely consider resolving the issue reported earlier in this thread. As soon as we have some further updates, we would be more than happy to update you with the status of correction.

Hi Danny,


Thanks for your inquiry. We have a good news for you, your above reported issue,PDFNEWNET-36249, has been resolved and its fix will be included in upcoming release of Aspose.Pdf for .NET i.e. 9.2.0. Hopefully it will be published in first week of May, 2014. However, we will notify you via this forum thread as soon as it is published and gets available for download.

Thanks for your patience and cooperation.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36249) have been fixed in Aspose.Pdf for .NET 9.2.0.

The blog post for this release is created over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.