Create mutli-page document dynamically using PDFBox

前端 未结 2 1412
暗喜
暗喜 2021-02-19 05:33

I am attempting to create a PDF report from a Java ResultSet. If the report was only one page, I would have no problem here. The issue comes from the fact that the report coul

2条回答
  •  天涯浪人
    2021-02-19 06:11

    As I expected, the answer was staring me right in the face, I just needed someone to point it out for me.

    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDPage.PAGE_SIZE_LETTER);
    document.addPage(page);
    PDPageContentStream content = new PDPageContentStream(document,page);
    
    //generate data for first page
    
    content.close();
    
    //if number of results exceeds what can fit on the first page
    page = new PDPage(PDPage.PAGE_SIZE_LETTER);
    document.addPage(page);
    content = new PDPageContentStream(document,page);
    
    //generate data for second page
    
    content.close();
    

    Thanks to @mkl for the answer.

提交回复
热议问题