【问题标题】:Using itext for printing at absolute positions使用 itext 在绝对位置打印
【发布时间】:2011-10-31 11:34:51
【问题描述】:

使用绝对定位将文本文档打印为 pdf 的推荐方法是什么? 我有一张必须打印的桌子。我也有数据类型长度和列的起始位置。 由于现有的表格是基于字符的,因此它的定位没有问题。但即使在使用单型字体(Courier,10)后,我也无法正确定位数据,并且每行的最后一列错误地跳到下一行。

为了使我的数据尽可能接近字符一,我将页面分为不同的列(根据其页面大小),然后将内容添加到所需的位置。我正在将数据块添加到段落中。

paragraph.add(new Chunk(new VerticalPositionMark(), columnNo*ptUnit, false));

我尝试调整页面大小、字体大小和边距长度,但数据显示不正确。你有遇到过这样的问题吗?请分享你的想法。

【问题讨论】:

    标签: java reporting itext


    【解决方案1】:

    你试过ColumnText

    当我想写一个段落并且我知道行数时......我会循环递增(即使它说递增并且是负数是因为 pdf 是从“南”到“北”(0 - height) y 与字体大小的比例,像这样

    //_valueArray is my string[]
    //fontSize is the value of the Size of the font...
    //1.5 it's just a magic number :) that give me the space line that i need
    //cbLocal is the PdfContentByte of the pdf
    for (i = 0; i < _valueArray.Length; i++)
    {
        var p = new Phrase(_valueArray[i], font);
        ColumnText.ShowTextAligned(cbLocal, align, p, x, y, 0);
        if (i + 1 != _valueArray.Length)
        {
            y = y - (fontSize*1.5f);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      相关资源
      最近更新 更多