I am currently working with Itextsharp and I have some trouble with PDfPtables.
Sometimes they get too big for a page and, when added to a document, are broken up on multiple pages.
Sadly ths rational behviour is not acceptable for some of my superiors – they keep insisting that the table shall be “shrunk” to a page. Is there a way to achieve this? There are some tantalizing hints that i could be possible – but hints are all that i have.
What is the alternative? Perhaps I could delete the fat table from the document and build the table again with smaller Fonts and Cells, but that would be very cumberosme – I would prefer to “zoom out”, in lack of a better word.
My current code:
Dim test As PdfContentByte = mywriter.DirectContent
Dim templ = test.CreateTemplate(mywriter.PageSize.Width, mywriter.PageSize.Height)
Table.WriteSelectedRows(0, Table.Rows.Count - 1, 0.0F, mywriter.PageSize.Height, templ)
Dim myimage = Image.GetInstance(templ)
' myimage.ScaleAbsolute(mywriter.PageSize.Width, mywriter.PageSize.Height)
would scaleabsolute be necessary?
myimage.SetAbsolutePosition(0, 0)
test.AddImage(myimage)
This code puts something one the page, but it has the height of the page and the width is about a quarter of the page – wi will try to find the bug…
Create the table and define a ‘total width’. As soon as iText knows the width of the table, you can calculate the height of all the rows. Once you know the height, you can check:
WriteSelectedRowsif you don’t want to take any page margins into account.PdfTemplate(there’s more than one way to do this), wrap thePdfTemplateinside anImage. Scale the image, and add it to the document.