2

I am trying to generate tables using pdfbox library using below code.

//Draw lines 
for (int i = 0; i <= cols; i++) {
            contentStream.drawLine(nextx,y,nextx,y-tableHeight);
            nextx += colWidth;
        }

 //fill with data
  float textx = margin+cellMargin;
    float texty = y-15;
    for(int i = 0; i < content.length; i++){
        for(int j = 0 ; j < content[i].length; j++){
            String text = content[i][j];
            contentStream.beginText();
            contentStream.moveTextPositionByAmount(textx,texty);
            contentStream.drawString(text);
            contentStream.endText();
            textx += colWidth;
        }
        texty-=rowHeight;
        textx = margin+cellMargin;
    }

While doing so data in created cell doesn't get wrappedenter image description here . I couldn't find a way to do so in pdfbox library. Please suggest solution.

sandy
  • 1,153
  • 7
  • 21
  • 39
  • 1
    If you need to program that yourself (e.g. because you are not allowed to use additional third-party classes like PdfLayoutManager in cello's answer), the information from [this answer](http://stackoverflow.com/a/19683618/1729265) on breaking text lines may help. – mkl Nov 18 '14 at 08:48

1 Answers1

3

PdfBox is rather a low-level API for PDF files and, as such, does not offer help with designing tables out of the box. If you don't want to re-invent the wheel yourself and come up with such functionality, you might want to have a look at the PdfLayoutManager here: https://github.com/GlenKPeterson/PdfLayoutManager

It provides a higher level API for PdfBox and offers text boxes with automatic line breaks, and also tables with line breaks.

cello
  • 5,356
  • 3
  • 23
  • 28