GlenKPeterson / PdfLayoutManager

Adds line-breaking, page-breaking, tables, and styles to PDFBox
45 stars 20 forks source link

Line feed is not respected in cells #16

Open rmattler opened 7 years ago

rmattler commented 7 years ago

Text with line breaks is not show in the cell.

Code: String s = "Policies \n and \n Proc, ";

y = lp.putRow(pMargin, y, Cell.of(headingCell20, colWidths[0], heading20, s));

I'm expecting:

Policies and Procs

Instead I get:

Policies and Proc

Is this intentional or a bug?

GlenKPeterson commented 7 years ago

You can split your input string on the \n so that "Policies\n and\n Procs" becomes ["Policies", "and", "Procs"] and pass that array to cb.add(). Or perhaps something like:

StringTokenizer sT = new StringTokenizer("Policies\n and\n Procs");
CellBuilder cb = n.cellBuilder().align(TOP_LEFT);
while (sT.hasMoreTokens()) { 
    cb.add(sT.nextToken());
}
cb.buildCell()

I think that recognizing \n internally would be a great new feature.

rmattler commented 7 years ago

I appreciate the fast response. Your suggestion solved my problem. But recognizing the \n internally would be better because the work around leaves spaces between the lines because of the line padding. Which isn't a problem in my case.

Thanks again for you help and PdfLayoutManager.

bob

On Thu, Apr 20, 2017 at 3:21 PM, Glen K. Peterson notifications@github.com wrote:

You can split your input string on the \n so that "Policies\n and\n Procs" becomes ["Policies", "and", "Procs"] and pass that array to cb.add(). Or perhaps something like:

StringTokenizer sT = new StringTokenizer("Policies\n and\n Procs");CellBuilder cb = n.cellBuilder().align(TOP_LEFT);while (sT.hasMoreTokens()) { cb.add(sT.nextToken()); } cb.buildCell()

I think that recognizing \n internally would be a great new feature.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GlenKPeterson/PdfLayoutManager/issues/16#issuecomment-295867663, or mute the thread https://github.com/notifications/unsubscribe-auth/AE5nhOHn5PxAaT-HK9deoxln1-6wF5zbks5rx7AfgaJpZM4NDYun .