Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
94 views
in Technique[技术] by (71.8m points)

c# - How to write a text across multiple columns in itextSharp?

I'm relatively new to iText 5 .NET (formerly known as iTextSharp). Is there a way to write a text across multiple columns? I can't use colspan as each column has a different color.

var cell = new PdfPCell() { Padding = 0, BorderWidth = 0, FixedHeight = _slotParam.SlotHeight };
var tgrid = new PdfPTable(3);
tgrid.AddCell(new PdfPCell() { Padding = 0, BackgroundColor = Color.ORANGE, BorderWidth = 0, FixedHeight = _slotParam.SlotHeight });
tgrid.AddCell(new PdfPCell() { Padding = 0, BackgroundColor = Color.WHITE, BorderWidth = 0, FixedHeight = _slotParam.SlotHeight });
tgrid.AddCell(new PdfPCell() { Padding = 0, BackgroundColor = Color.GREEN, BorderWidth = 0, FixedHeight = _slotParam.SlotHeight });

cell.AddElement(tgrid);
Paragraph paragraph = new Paragraph(phrase);
paragraph.Leading = 11f;
cell.AddElement(phrase);
mainGrid.AddCell(cell);

This is the output that I have, I want to write a text across that 3 colors.

enter image description here

question from:https://stackoverflow.com/questions/65882936/how-to-write-a-text-across-multiple-columns-in-itextsharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Actually, the solution is simple. By giving NoWrap = true for the first cell will make the text to over lap other cells. tgrid.AddCell(new PdfPCell(phrase) { Padding = 0, BackgroundColor = Color.ORANGE, BorderWidth = 0, FixedHeight = _slotParam.SlotHeight, NoWrap = true }); [Output] 1 Thank you all for helping. Cheers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...