gpt4 book ai didi

grails - 使用导出插件或iText在垂直方向上将一个PDF页面分成两个相等的部分:Grails

转载 作者:行者123 更新时间:2023-12-02 14:42:08 25 4
gpt4 key购买 nike

我当前正在使用Export 1.6插件将SQL查询的数据导出到Grails中的PDF中。

我已分层,但无法找到确切的解决方案-

I want to generate dynamically multi page PDF, but the page should be equally partitioned into two equal section vertically.I used document.newPage() but this is dividing a page into two pages.



代码段
protected void exportData(OutputStream outputStream, List data, List fields) throws ExportingException{
Rectangle left;
Rectangle right;
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
// step 3
document.open();
// step 4
PdfContentByte canvas = writer.getDirectContent();
ColumnText ct = new ColumnText(canvas);
int side_of_the_page = 0;

ct.setSimpleColumn(36, 36, 290, 806);
int paragraphs = 0;
while (paragraphs < 30) {
ct.addElement(new Paragraph(String.format("Paragraph %s: %s", ++paragraphs, TEXT)));
while (ColumnText.hasMoreText(ct.go())) {
if (side_of_the_page == 0) {
side_of_the_page = 1;
canvas.moveTo(297.5f, 36);
canvas.lineTo(297.5f, 806);
//canvas.colorStroke
canvas.stroke();
}
else {
side_of_the_page = 0;

PdfPTable talble = new PdfPTable()
while(data.size())
PdfPCell cell1 = new PdfPCell()


ct.addElement(data);
document.newPage();
}

ct.setSimpleColumn(305, 36, 559, 806);
}
}
// step 5
document.close();
}



}

最佳答案

您可以尝试使用 itextpdf-5.x.x.jar 代替默认的Grails导出插件。

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;

关于grails - 使用导出插件或iText在垂直方向上将一个PDF页面分成两个相等的部分:Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29372099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com