标签: pdfptable

iTextSharp并将一些数据移动到下一页

我正在使用iTextSharp创建发票.这显示很好,但有时,当发票项目的数量较大时,汇总部分(显示小计,税,​​折扣,总计等)将被拆分.一些显示在当前页面中,一些显示在下一页.我想将整个摘要部分移到下一页,如果剩下的当前高度还不够.

但是,要做到这一点,我需要知道剩余多少页面高度(在我当前的页面内容渲染之后).我想知道是否有人知道如何计算页面的当前左高度?或者,如果pdfPTable中有一个属性,可能会强制表格作为一个整体打印出来,不要让它分割成多个页面!我想如果第二个选项可用,那将很容易.

总之,我需要知道是否可以计算剩余页面高度,以及是否可以强制表格不分割在多个页面上.

谢谢.Sameers

itextsharp pdfptable

3
推荐指数
1
解决办法
1万
查看次数

无法正确计算itext PdfPTable/PdfPCell高度

我在尝试生成PdfPTable并在将其添加到文档之前计算其高度时遇到问题.calculateHeightsPdfPTable 的方法返回的高度比页面的高度大很多(当表格大约是页面高度的1/4时),所以我写了一个计算高度的方法:

protected Float getVerticalSize() throws DocumentException, ParseException, IOException {
    float overallHeight=0.0f;
    for(PdfPRow curRow : this.getPdfObject().getRows()) {
        float maxHeight = 0.0f;
        for(PdfPCell curCell : curRow.getCells()) {
            if(curCell.getHeight()>maxHeight) maxHeight=curCell.getHeight();
        }
        overallHeight+=maxHeight;
    }
    return overallHeight;
}
Run Code Online (Sandbox Code Playgroud)

其中getPdfObjectmethod返回PdfPTable对象.
使用调试器我发现单元格矩形的lly和ury坐标差异(以及因此高度)比将表格添加到文档后看起来要大得多(例如,一个单元格为20,另一个单元格为38高度在页面上看起来一样).除了带有块的段落外,单元格中没有任何内容:

Font f = getFont();
        if (f != null) {
            int[] color = getTextColor();
            if(color != null) f.setColor(color[0],color[1],color[2]);
            ch = new Chunk(celltext, f);
            par = new Paragraph(ch);
        }
cell = new PdfPCell(par);
cell.setHorizontalAlignment(getHorizontalTextAlignment());
cell.setVerticalAlignment(getVerticalTextAlignment());
Run Code Online (Sandbox Code Playgroud)

然后一个表添加了一个单元格,并将setWidthPercentage属性设置为某个浮点数.我究竟做错了什么?为什么单元格的比例与生成PDF后看到的不同?也许我正在计算身高错误?是不是PDF页面上单元格的高度应严格地说是lly和ury坐标之间的区别
对不起我没有显示确切的代码,因为PDF是使用大量的中间步骤和对象生成的XML是不是很"有用",我猜...
提前谢谢!

java height itext pdfptable

3
推荐指数
1
解决办法
4008
查看次数

如何减少具有多个单元格的 PdfPTable 的内存消耗

我正在使用由单个 PdfTable 组成的 ITextSharp 创建 PDF。不幸的是,对于特定数据集,由于创建了大量 PdfPCell,我遇到了内存不足异常(我已经分析了内存使用情况 - 我有近 1/2 百万个单元格!)

在这种情况下,有没有办法减少内存使用?我试过在不同点(每行之后)冲洗和完全压缩

PdfWriter 基于 FileStream

代码看起来很像这样:

Document document = Document();
FileStream stream = new FileStream(fileName,FileMode.Create);                                   
pdfWriter = PdfWriter.GetInstance(document, stream);
document.Open();
PdfPTable table = new PdfPTable(nbColumnToDisplay);
foreach (GridViewRow row in gridView.Rows)
{
    j = 0;
    for (int i = 0; i < gridView.HeaderRow.Cells.Count; i++)
    {
        PdfPCell cell = new PdfPCell( new Phrase( text) );
        table.AddCell(cell);
    }   
}
document.Add(table);
document.Close();
Run Code Online (Sandbox Code Playgroud)

c# itextsharp pdfptable pdf-writer

2
推荐指数
1
解决办法
2851
查看次数

iTextSharp PdfPCell与块对齐

我正在使用iTextSharp以编程方式创建PDF并生成PdfPTable.

在一些细胞中,我需要有一个超链接.

没有超链接我可以水平和垂直对齐单元格中的文本,但是当我添加包含我的超链接的块时,单元格将失去其对齐属性.

这是我的代码......

var webAddress = new Chunk(row["product_code"].ToString(), linkFont);
webAddress.SetAnchor(row["url"].ToString());

PdfPCell ProductCodeCell = new PdfPCell();
ProductCodeCell.AddElement(webAddress);
ProductCodeCell.VerticalAlignment = Element.ALIGN_MIDDLE;
ProductCodeCell.HorizontalAlignment = Element.ALIGN_CENTER;
ProductCodeCell.Padding = 3f;
table.AddCell(ProductCodeCell);
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我重新调整链接吗?

非常感谢.

c# itextsharp pdfptable

2
推荐指数
1
解决办法
7068
查看次数

如何改变细胞的宽度?

我需要你帮助设置单元格底部边框的长度.目前,它显示单元格的底部边界太长,我需要缩短它.我试图改变表的宽度,但它没有正确.

以下是代码:

Paragraph tableParagraph = new Paragraph();
tableParagraph.setAlignment(Element.ALIGN_LEFT);

PdfPTable table55 = new PdfPTable(2);
table55 = new PdfPTable(new float[] { 6, 6 });
table55.setWidthPercentage(90f);
table55.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

PdfPCell cel2a = new PdfPCell(new Paragraph("Total of Net Profit ", font));

PdfPCell cel2b = new PdfPCell(new Paragraph("100.000" + " USD  ", font));

cel2a.setBorder(Rectangle.NO_BORDER);
cel2b.setBorder(Rectangle.BOTTOM);
cel2a.setLeading(1f, 1.5f);
cel2b.setLeading(1f, 1.5f);

table55.addCell(cel2a);
table55.addCell(cel2b);
Run Code Online (Sandbox Code Playgroud)

java pdf-generation itext pdfptable

2
推荐指数
1
解决办法
1万
查看次数

如何设置PdfPTable的宽度并在页面中对齐表格中心

我是iTextSharp的首发,我将此代码编写为创建RoundRectangle到PdfPTable并在页面中心对齐表

 string pdfpath = Server.MapPath("PDFs");
        RoundRectangle rr = new RoundRectangle();

        using (Document document = new Document())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics6.pdf", FileMode.CreateNew));
            document.Open();
            PdfPTable table = new PdfPTable(1);
                           float[] f=new float[]{0.5f};

            table.SetWidths(f);
            PdfPCell cell = new PdfPCell()
            {
                CellEvent = rr,
                Border = PdfPCell.NO_BORDER,

                Phrase = new Phrase("test")
            };
            table.AddCell(cell);
            document.Add(table);
Run Code Online (Sandbox Code Playgroud)

我想改变表格宽度我改变代码

 string pdfpath = Server.MapPath("PDFs");
        RoundRectangle rr = new RoundRectangle();

        using (Document document = new Document())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics6.pdf", …
Run Code Online (Sandbox Code Playgroud)

c# itextsharp pdfptable

1
推荐指数
1
解决办法
2万
查看次数

PdfPTable.DefaultCell.Padding 似乎不起作用

我正在尝试定义一系列列的填充,这些列将被推入我的 PdfPTable 中...

这是我的代码:

PdfPTable table = new PdfPTable(6);
table.WidthPercentage = 100;
table.SetWidths(new float[]{25, 25, 16, 11, 11, 11});
table.DefaultCell.Padding = 3;
Run Code Online (Sandbox Code Playgroud)

有问题,因为当生成表时,它在任何地方都没有填充。

先感谢您。

c# itext pdfptable

0
推荐指数
1
解决办法
5155
查看次数

标签 统计

pdfptable ×7

c# ×4

itextsharp ×4

itext ×3

java ×2

height ×1

pdf-generation ×1

pdf-writer ×1