4
现在我使用iText自动生成pdf。 而我的问题是,当内容真的非常大时,我需要计算内容的高度和宽度,然后添加新页面... 这真的很不合情理。如何将内容写入pdf使用iText?
所以我不知道是否有这样的方法: Document.add(“非常非常大的文章”); 之后,它会自动生成一个pdf文件?
在此先感谢!
现在我使用iText自动生成pdf。 而我的问题是,当内容真的非常大时,我需要计算内容的高度和宽度,然后添加新页面... 这真的很不合情理。如何将内容写入pdf使用iText?
所以我不知道是否有这样的方法: Document.add(“非常非常大的文章”); 之后,它会自动生成一个pdf文件?
在此先感谢!
下面创建一个9页的pdf,而不必计算高度和宽度。
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class HelloWorld {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document,
new FileOutputStream("HelloWorld.pdf"));
document.open();
String text = "";
for (int i = 0; i < 10000; i++) {
text += "test";
}
document.add(new Paragraph(text));
} catch (DocumentException e) {
System.err.println(e.getMessage());
} catch (IOException ex) {
System.err.println(ex.getMessage());
}
document.close();
}
}
当当前页面的内容已满时,将自动生成一个新页面。
问自己同样的问题。 – 2009-08-14 14:38:34