Hey,
We are currently using Aspose.PDF version 25.1.0 and have encountered an issue with rendering multiline text when the horizontal alignment is set to Right
. Specifically, when the text wraps into multiple lines, the first letter or the first word in the first line is partially cut off or not fully visible.
This issue seems related to the word-wrapping algorithm and how right-aligned text is handled. The problem occurs with both TextParagraph
and Aspose.Pdf.Table
(when configured with a single cell to act as a paragraph).
We are working with the Hebrew language (RTL text), which seems to exacerbate this issue.
Could you please provide guidance on how to properly right-align RTL text in these scenarios without having parts of words cut off?
@CreativITy
Could you provide document and code you are using so we can recreate issue in our environment?
Sure,
this is when we use a table with a single-cell
Aspose.Pdf.Table pdfTable = new Aspose.Pdf.Table
{
ColumnWidths = textAreaData.SIZE.WIDTH.ToString(),
Left = textAreaData.POSITION.X,
Top = textAreaData.POSITION.Y
};
Aspose.Pdf.Row tableRow = pdfTable.Rows.Add();
tableRow.FixedRowHeight = textAreaData.SIZE.HIGHT;
Aspose.Pdf.Cell pdfCell = tableRow.Cells.Add(textAreaData.VALUE);
pdfCell.DefaultCellTextState = new TextState
{
Font = FontRepository.FindFont(textAreaData.STYLES.FONTFAMILY),
FontSize = textAreaData.STYLES.FONTSIZE,
ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.ColorTranslator.FromHtml(textAreaData.STYLES.COLOR)),
FontStyle = textAreaData.STYLES.BOLD ? FontStyles.Bold : FontStyles.Regular,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right
};
pdfCell.VerticalAlignment = VerticalAlignment.Top;
page.Paragraphs.Add(pdfTable);
And this is when we try to use TextParagraph
var paragraph = new Aspose.Pdf.Text.TextParagraph();
// Set subsequent lines indent
// Specify the location to add TextParagraph
paragraph.Position = new Position(textAreaData.POSITION.X, textAreaData.POSITION.Y);
paragraph.Rectangle = new Aspose.Pdf.Rectangle(0, 0, textAreaData.SIZE.WIDTH, textAreaData.SIZE.HIGHT);
paragraph.HorizontalAlignment = HorizontalAlignment.Right;
paragraph.Margin = new MarginInfo(0, 0, 0, 0);
// Specify word wraping mode
paragraph.FormattingOptions.WrapMode = Aspose.Pdf.Text.TextFormattingOptions.WordWrapMode.ByWords;
// Create text fragment
var fragment = new Aspose.Pdf.Text.TextFragment(textAreaData.VALUE);
fragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont(textAreaData.STYLES.FONTFAMILY);
fragment.TextState.FontSize = 12;
// Add fragment to paragraph
paragraph.AppendLine(fragment);
// Add paragraph
textBuilder.AppendParagraph(paragraph);
this is the result:
image.png (20.6 KB)
@CreativITy
Thank you, I’ll investigate this issue and write you back as soon as possible
@CreativITy
I investigated a bit, but currently couldn’t reproduce the issue, probably due to specifics of positions & font
Code I used was the following
var output = OutputFolder + "output_table_issues.pdf";
string value = "אפשר לתת לו את איפיוני העיצוב הדרושים לסק";
Aspose.Pdf.Text.Font font = FontRepository.FindFont("DejaVu Sans");
var valueLength = font.MeasureString(value, 14);
valueLength = Math.Round(valueLength);
var doc = new Document();
var page = doc.Pages.Add();
Aspose.Pdf.Table pdfTable = new Aspose.Pdf.Table
{
ColumnWidths = valueLength.ToString(),
//Left = 400,
//Top = 400
//ColumnWidths = textAreaData.SIZE.WIDTH.ToString(),
//Left = textAreaData.POSITION.X,
//Top = textAreaData.POSITION.Y
};
pdfTable.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black));
Aspose.Pdf.Row tableRow = pdfTable.Rows.Add();
tableRow.FixedRowHeight = 14;// textAreaData.SIZE.HIGHT;
Aspose.Pdf.Cell pdfCell = tableRow.Cells.Add(value);
pdfCell.DefaultCellTextState = new TextState
{
Font = font,
FontSize = 14,
ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black),
FontStyle = FontStyles.Regular,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right
};
pdfCell.VerticalAlignment = VerticalAlignment.Top;
doc.Pages[1].Paragraphs.Add(pdfTable);
page = doc.Pages.Add();
TextBuilder textBuilder = new TextBuilder(doc.Pages[2]);
var paragraph = new Aspose.Pdf.Text.TextParagraph();
// Set subsequent lines indent
// Specify the location to add TextParagraph
paragraph.Rectangle = new Aspose.Pdf.Rectangle(0, page.PageInfo.Height - 14, valueLength, page.PageInfo.Height);
paragraph.HorizontalAlignment = HorizontalAlignment.Right;
paragraph.Margin = new MarginInfo(0, 0, 0, 0);
// Specify word wraping mode
paragraph.FormattingOptions.WrapMode = Aspose.Pdf.Text.TextFormattingOptions.WordWrapMode.ByWords;
// Create text fragment
var fragment = new Aspose.Pdf.Text.TextFragment(value);
fragment.TextState.Font = font;
fragment.TextState.FontSize = 12;
// Add fragment to paragraph
paragraph.AppendLine(fragment);
// Add paragraph
textBuilder.AppendParagraph(paragraph);
doc.Save(output);
and the output result looks like this
output_table_issues.pdf (82.4 KB)
Could you check if issue is reproduced with these inputs and provide information what values are required to recreate it?
@ilyazhuykov
Thank you for your response. The problem we face is when the text spans multiple lines.
To illustrate this, I Repeat the text value four times and Multiply the row height by 4 to accommodate the increased text content.
var output = OutputFolder + "output_table_issues.pdf";
string value = "אפשר לתת לו את איפיוני העיצוב הדרושים לסק";
value = $"{value} {value} {value} {value}";
Aspose.Pdf.Text.Font font = FontRepository.FindFont("DejaVu Sans");
var valueLength = font.MeasureString(value, 14);
valueLength = Math.Round(valueLength);
var doc = new Document();
var page = doc.Pages.Add();
Aspose.Pdf.Table pdfTable = new Aspose.Pdf.Table
{
ColumnWidths = valueLength.ToString(),
//Left = 400,
//Top = 400
//ColumnWidths = textAreaData.SIZE.WIDTH.ToString(),
//Left = textAreaData.POSITION.X,
//Top = textAreaData.POSITION.Y
};
pdfTable.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black));
Aspose.Pdf.Row tableRow = pdfTable.Rows.Add();
tableRow.FixedRowHeight = 14 * 4;// textAreaData.SIZE.HIGHT;
Aspose.Pdf.Cell pdfCell = tableRow.Cells.Add(value);
pdfCell.DefaultCellTextState = new TextState
{
Font = font,
FontSize = 14,
ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black),
FontStyle = FontStyles.Regular,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right
};
pdfCell.VerticalAlignment = VerticalAlignment.Top;
doc.Pages[1].Paragraphs.Add(pdfTable);
page = doc.Pages.Add();
TextBuilder textBuilder = new TextBuilder(doc.Pages[2]);
var paragraph = new Aspose.Pdf.Text.TextParagraph();
// Set subsequent lines indent
// Specify the location to add TextParagraph
paragraph.Rectangle = new Aspose.Pdf.Rectangle(0, page.PageInfo.Height - 14, valueLength, page.PageInfo.Height);
paragraph.HorizontalAlignment = HorizontalAlignment.Right;
paragraph.Margin = new MarginInfo(0, 0, 0, 0);
// Specify word wraping mode
paragraph.FormattingOptions.WrapMode = Aspose.Pdf.Text.TextFormattingOptions.WordWrapMode.ByWords;
// Create text fragment
var fragment = new Aspose.Pdf.Text.TextFragment(value);
fragment.TextState.Font = font;
fragment.TextState.FontSize = 12;
// Add fragment to paragraph
paragraph.AppendLine(fragment);
// Add paragraph
textBuilder.AppendParagraph(paragraph);
doc.Save(output);
When the text value is long enough to span multiple lines, parts of the text get cut off from the right side of the textbox/row cell
image.png (17.6 KB)
test.pdf (106.7 KB)
@CreativITy
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-59130
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thank you for clarifying, I’ll check if there any workarounds for this issue
but in any case this behavior doesn’t seem to be right as default so I added task for development team
@ilyazhuykov
Thank you for investigating this issue and escalating it to the development team.
In the meantime, we have been able to implement a workaround by utilizing the HtmlFragment
and generating the table within the HTML code.
If possible, we would appreciate it if you could update us on any progress regarding this issue.
1 Like
@CreativITy , I currently found no direct workaround, there’s just no similar functionality to TextParagraph.FormattingOptions.WrapMode in Aspose.Pdf.Table, so I added this to description as desired outcome.
Currently issue is open and isn’t assigned to anyone, but in any case if task will be resolved you’ll get automatic notification about fixing the problem. If there will be any additional details about fix, I’ll add them as separate explanation
@ilyazhuykov
Thanks for the update and for clarifying the status. We’ll continue using our workaround for now and look forward to any updates. Appreciate your help!
1 Like