For the first part in red, it's kept together in one line.
But for the second part in red, it's splitted to multiple lines, which is not pure text but composed by Text & Link.
Here is the code:
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc, PageSize.A4, false);
doc.SetMargins(55f, 55f, 45f, 55f);
var pageWidth = doc.GetPageEffectiveArea(PageSize.A4).GetWidth();
var pageHeight = doc.GetPageEffectiveArea(PageSize.A4).GetHeight();
var text1 = "Our PDF toolkit offers you one of the best-documented and most versatile PDF engines in the world (written in Java and .NET), which allows you to not only integrate PDF functionalities into your workflow, but also in your applications, processes products";
var text2 = "We have an active community of partners, customers, and contributors, that help us every day to improve our products, documentation and support. We see them as part of our iText family, and hope you will join our family too.";
var riseText = "[12,13,14,15]";
var link1 = new Link("12", PdfAction.CreateURI("http://123.com"));
link1.SetTextRise(3).SetFontColor(ColorConstants.ORANGE);
link1.GetLinkAnnotation().SetBorder(new PdfAnnotationBorder(0, 0, 0));
var link2 = new Link("13", PdfAction.CreateURI("http://123.com"));
link2.GetLinkAnnotation().SetBorder(new PdfAnnotationBorder(0, 0, 0));
link2.SetTextRise(3).SetFontColor(ColorConstants.ORANGE);
var link3 = new Link("14", PdfAction.CreateURI("http://123.com"));
link3.GetLinkAnnotation().SetBorder(new PdfAnnotationBorder(0, 0, 0));
link3.SetTextRise(3).SetFontColor(ColorConstants.ORANGE);
var link4 = new Link("15", PdfAction.CreateURI("http://123.com"));
link4.GetLinkAnnotation().SetBorder(new PdfAnnotationBorder(0, 0, 0));
link4.SetTextRise(3).SetFontColor(ColorConstants.ORANGE);
var p1 = new Paragraph();
p1.SetWidth(200f).SetMarginBottom(20).SetTextAlignment(TextAlignment.JUSTIFIED);
p1.Add(text1);
p1.Add(new Text(riseText).SetTextRise(3).SetFontSize(9));
p1.Add(text2);
var p2 = new Paragraph();
p2.SetWidth(200f).SetTextAlignment(TextAlignment.JUSTIFIED);
p2.Add(text1);
p2.Add(new Text("[").SetTextRise(3).SetFontSize(9))
.Add(link1.SetFontSize(9))
.Add(new Text(",").SetTextRise(3).SetFontSize(9))
.Add(link2.SetFontSize(9))
.Add(new Text(",").SetTextRise(3).SetFontSize(9))
.Add(link3.SetFontSize(9))
.Add(new Text(",").SetTextRise(3).SetFontSize(9))
.Add(link4.SetFontSize(9))
.Add(new Text("]").SetTextRise(3).SetFontSize(9));
p2.Add(text2);
doc.Add(p1);
doc.Add(p2);
doc.Close();
So my question is how to strictly keep text block (Text + Link) together in one line of Paragraph? (For iText5, I think it can be achieved by utilizing Phrase.)
You can do a trick here and add an inner block element to a paragraph. That will make the inner block element behave like inline-block element in HTML/CSS and avoid word wrapping. Here is the code:
var p2 = new Paragraph();
p2.SetWidth(200f).SetTextAlignment(TextAlignment.JUSTIFIED);
p2.Add(text1);
var inlineBlock = new Paragraph();
inlineBlock.Add(new Text("[").SetTextRise(3).SetFontSize(9))
.Add(link1.SetFontSize(9))
.Add(new Text(",").SetTextRise(3).SetFontSize(9))
.Add(link2.SetFontSize(9))
.Add(new Text(",").SetTextRise(3).SetFontSize(9))
.Add(link3.SetFontSize(9))
.Add(new Text(",").SetTextRise(3).SetFontSize(9))
.Add(link4.SetFontSize(9))
.Add(new Text("]").SetTextRise(3).SetFontSize(9));
p2.Add(inlineBlock);
p2.Add(text2);