Search code examples
c#pdf

PDF: How to Draw a formatted Content using PDFFormattedContent inside a table Cell


I'm building a PDF document using the PDF4Net library, my document should render different text content side by side, I'm using PDFFLowDocument class to build and design the page and I'm using PDFFlowTable to organize my content. I have my content built in two separate PDFFormattedContent. I introduce a table to separate the content into columns and I get something like,

PDFFormattedContent content1 = new PDFFormattedContent()
PDFFormattedContent content2 = new PDFFormattedContent()

PDFFLowTable MyTable = new PDFFlowTable();
Mytable.Rows.AddRowWithCells(content1, content2)

This is good but the problem I'm facing is that there's a limited type cells I can use to manipulate the way my FormattedContent I rendered on the screen. so far all I'm finding is PDFLowTableStringCell which does not reproduce the formatting of my PDFFormattedContent all I get is the text, no font, color, line spacing etc. I would ideally want to be able to call DrawFormattedContent inside of a table cell so that all my design gets rendered properly. Is there a way to do that ??


Solution

  • Wrap your PDFFormattedContent object in a PDFFlowTextContent object (see @SimonDK answer). Then create a PDFFlowTableCompositeCell and add the PDFFlowTextContent object to it.

    Note: I work for the company that develops the PDF4NET library.