是否有可能“收缩”?一个PdfPtable? [英] Is it possible to "shrink" a PdfPtable?
问题描述
我目前正在使用Itextsharp,我在使用PDfPtables时遇到了一些麻烦。
有时它们对于页面来说太大了,当添加到文档中时,会在多个页面上分解。
遗憾的是,对于我的一些上级来说,理性行为是不可接受的 - 他们坚持要求桌子缩小到一页。有没有办法实现这个目标?有一些诱人的提示,我可能 - 但提示是我所拥有的。
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.
我当前的代码:
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)
是否有必要进行扩展?
myimage.SetAbsolutePosition(0,0)
test.AddImage(myimage)
would scaleabsolute be necessary? myimage.SetAbsolutePosition(0, 0) test.AddImage(myimage)
此代码将页面放入页面,但它具有高度页面和宽度约为页面的四分之一 - wi将尝试查找错误...
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...
推荐答案
创建表格并定义'总宽度'。只要iText知道表格的宽度,您就可以计算出所有行的高度。一旦知道了高度,就可以查看:
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:
- 表格是否适合页面?只需按原样添加即可。如果您不想考虑任何页边距,可以使用
WriteSelectedRows
。 - 页面上没有足够的空间?将表添加到
PdfTemplate
(有多种方法可以执行此操作),在<$中包装PdfTemplate
C $ C>图片。缩放图像,并将其添加到文档中。
- Does the table fit the page? Just add it as is. Maybe using
WriteSelectedRows
if you don't want to take any page margins into account. - Isn't there enough space on the page? Add the table to a
PdfTemplate
(there's more than one way to do this), wrap thePdfTemplate
inside anImage
. Scale the image, and add it to the document.
这篇关于是否有可能“收缩”?一个PdfPtable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!