Hi,
I have a string of text which need to be filled in a TextParagraph element with a particular size (Rectangle). However, it can occur, that the text delivered is too long and the piece of text which is too long should be added in a new TextParagraph right of the first paragraph (see Image).
Code for creating the too long element
//Define the page
Document doc = new Document();
Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
TextBuilder builder = new TextBuilder(page);
float
x1 = 40,
x1End = 40 + 253,
x2 = (float)page.PageInfo.Width - (40 + 40 + 253),
x2End = x2 + 253,
y = 500,
height1 = 45f * 72f / 25.4f;
TextParagraph paragraph = new TextParagraph
{
Rectangle = new Aspose.Pdf.Rectangle(x1, y, x1End, y - height1)
};
// Specify word wraping mode
paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
paragraph.FormattingOptions.LineSpacing = TextFormattingOptions.LineSpacingMode.FontSize;
paragraph.VerticalAlignment = VerticalAlignment.Top;
paragraph.HorizontalAlignment = HorizontalAlignment.Justify;
paragraph.Margin = new MarginInfo(2, 0, 2, 3);
string
FundDescription = @"Reichmuth Voralpin ist ein aktiv verwalteter defensiver Anlagestrategiefonds mit Referenzwährung CHF, der in traditionelle und nicht-traditionelle Anlagen wie Anleihen, Aktien, Immobilien, Alternativanlagen oder Edelmetall-Anlagen investiert. Ziel ist ein robuster Portfolioaufbau mit ausgewogenenRisikobeiträgen und einer langfristigen Zielrendite von LIBOR + 2% pro Jahr.Der Investment Manager setzt auf einen szenariobasierten, benchmarkunabhängigen Investmentansatz. Gestützt auf eigenes Research und Investment Know-how investiert Reichmuth Voralpin primär in Direktanlagen, opportunistisch ergänzt mit ETFs und Fonds sowie Derivaten zu Absicherungszwecken. Eine dynamische Portfolioallokation und ein überwiegend qualitätsorientierter Selektionsansatz zeichnen Reichmuth Voralpin aus.";
// Create text fragment
TextFragment tf = new TextFragment(FundDescription);
tf.TextState.Font = FontRepository.FindFont("Arial"); ;
tf.TextState.FontSize = 9;
tf.TextState.LineSpacing = 2f;
// Add fragment to paragraph
paragraph.AppendLine(tf);
// Add paragraph
builder.AppendParagraph(paragraph);
doc.Save(dataDir + "TextParagraph.pdf");
Is there a way how I can get the information, that the right margin at the bottom of the rectangle (in this case it’s the word “opportunistisch”) is reached in order to add the remaining text to another paragraph?
Many thanks for you help.
TextParagraph.pdf (44.7 KB)
ThisIsHowTheTextShouldLookLike.PNG (79.3 KB)