As far as I understand you work with iText5 and there might be troubles with recognising white-space: nowrap
anyway and therefore it's possible to set your table preferences going through all the cells in your code after obtaining the table from the page elements:
// Setting a css file
ICSSResolver cssResolver = new StyleAttrCSSResolver();
ICssFile cssFile = XMLWorkerHelper.GetCSS(cssStream);
cssResolver.AddCss(cssFile);
// HTML
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
// Pipelines
ElementList elements = new ElementList();
ElementHandlerPipeline pdf = new ElementHandlerPipeline(elements, null);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
// XML Worker
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
// Transmitting the html file with the table
p.Parse(htmlStream);
// Obtaining the table
var table = elements[0];
var pdfTable = table as PdfPTable;
foreach (var c in pdfTable.Rows.SelectMany(r => r.GetCells()))
{
c.NoWrap = true;
}
Here is the link to the official documentation (though there are only examples written in JAVA) which I applied to my example.
The problem with the approach is that you're likely to be responsible for dealing with your cell widths like this (How to define the width of a cell?
):
pdfTable.SetTotalWidth(new float[] { 500, 500, 500, 500, 500 });
pdfTable.LockedWidth = true;
Otherwise the cells might overlap with one another.
To define your page size in accordance to the table width and height you can do it the next way (How to define the page size based on the content?):
var pdfDoc = new Document(new Rectangle(pdfTable.TotalWidth, pdfTable.TotalHeight), 10f, 10f, 10f, 0f);