小编Ant*_*sky的帖子

无法正确计算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
查看次数

postgresql to_json()函数转义所有双引号字符

我已经编写了一个plpgsql脚本,该脚本会在字符串中生成json对象的数组,但是在我使用to_json()方法将带有该字符串的变量传递给它之后,它返回的结果将被双引号引起,并且每个双引号字符都将转义。但是我需要原样的字符串。

jsonResult变量的初始内容为:

[{“ key”:{04949429911,“ Code”:“ 400”},“ value”:“ 20000.00”},{“ key”:{“ InsuranceNumber”:“ 04949429911”,“ Code”:“ 403”}, “ value”:“ 10000.00”},...]

但是在to_json()之后,它看起来像这样:

“ [{\” key \“:{04949429911,\” Code \“:\” 400 \“},\” value \“:\” 20000.00 \“},{\” key \“:{\” InsuranceNumber \ “:\” 04949429911 \“,\”代码\“:\” 403 \“},\”值\“:\” 10000.00 \“} ...]”

这是jsonResult中存储的所有内容中断的地方:

UPDATE factor_value SET params = to_json(jsonResult) WHERE id = _id;  
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

sql json postgresql-9.3

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

标签 统计

height ×1

itext ×1

java ×1

json ×1

pdfptable ×1

postgresql-9.3 ×1

sql ×1