1

I need to write JSON data line by line to PDF. How do I determine if last line has reached and accordingly add a new page?

I have searched the internet but I am unable to get code that prints huge chunk of data in loop with wrap text and page numbers.

Can someone help me with the same? This is the 1st time I am working with PDFBox though I have used iText very flexibly.

NorthCat
  • 9,643
  • 16
  • 47
  • 50
  • 1
    Unlike iText, PDFBox is very "low level". There is no concept of "number of lines per page" in PDF. You must know the text positions you use yourself (it is dependent of font size, or it will look bad), know your paper size, and add pages accordingly. I recommend that you download the source code, it has many examples, and one of them writes a text line on a page, you could start from there. – Tilman Hausherr Apr 07 '15 at 07:16
  • 1
    These links can help you to print lines in one page: http://stackoverflow.com/questions/19635275/how-to-generate-multiple-lines-in-pdf-using-apache-pdfbox http://stackoverflow.com/questions/16541660/creating-a-new-pdf-document-using-pdfbox-api http://www.coderanch.com/how-to/java/PDFBoxExample Doing it for several pages is just closing the old content stream, create a new page and reset the start position. – Tilman Hausherr Apr 07 '15 at 10:00
  • Were you able to solve your problem? If yes, please answer the question yourself or delete the question. If no, please edit your question to include the code you already wrote and mention what roadblock you hit. – Tilman Hausherr Apr 09 '15 at 06:52

1 Answers1

-1

I can`t comment yet so I answer.

PdfBox doesn´t have the tools to handle layout. You must count the number of results you´re printing in order to know when a new page is required.

I had been in the same situation and used Boxable for PdfBox (https://github.com/dhorions/boxable) to print a table (without lines if desired) whitout worrying about page creation (Boxable does that work for yourself)

javi_swift
  • 377
  • 6
  • 16