gpt4 book ai didi

itext - 在 columntext 走后获取 y 位置

转载 作者:行者123 更新时间:2023-12-04 17:01:11 24 4
gpt4 key购买 nike

在 contentByte 中有一个 columnText 对象 (5.4.1)

如果我这样做

go = ct.go(true)
yy = ct.getYLine()

我可以将最后写入的 y 位置的值放入变量 yy 中,但文本列中的段落未写入(显然)

如果我这样做

go = ct.go()
yy = ct.getYLine()

然后没有任何东西返回给 yy。我如何写入 ct 并返回 YLine 值???

最佳答案

我无法重现这个问题。这是我的代码:

import java.io.FileOutputStream;
import java.io.IOException;

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


public class ColumnTest {

public static void main(String[] args) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("columntest.pdf"));
document.open();
ColumnText ct = new ColumnText(writer.getDirectContent());
ct.setSimpleColumn(PageSize.A4);
ct.addElement(new Paragraph("Hello World"));
ct.addElement(new Paragraph("Hello Sun"));
ct.addElement(new Paragraph("Hello Moon"));
ct.go();
System.out.println(ct.getYLine());
document.close();
}
}

这是写入 System.out 的内容:

788.0

这与我将 ct.go(); 替换为 ct.go(true); 时的结果相同(但是当我在模拟模式下工作时,我得到一个异常(exception),说“文档没有页面”,原因很明显)。

关于itext - 在 columntext 走后获取 y 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17070196/

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