PDF에 컨텐츠를 작성하는 방법 ITEXT를 사용합니까?
-
22-07-2019 - |
문제
지금 당장 ITEXT를 사용하여 PDF를 자동으로 생성합니다. 내 문제는 콘텐츠가 실제로 매우 크면 내용의 높이와 너비를 계산 한 다음 새 페이지를 추가해야한다는 것입니다.
따라서 다음과 같은 방법이 있는지 궁금합니다. 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();
}
}
다른 팁
현재 페이지의 내용이 가득 차면 새 페이지가 자동으로 생성됩니다.
제휴하지 않습니다 StackOverflow