You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Rick R <ri...@gmail.com> on 2013/11/13 16:11:44 UTC

Iis pdfbox the correct choice for this scenario?

I need to create my pdf dynamically, iterating over different  types of
java objects etc.. and all I'll be putting data into two columns ..
basically a label column and then a value column. I need the value column
to wrap though.

I don't see any sort of table like functionality built in?

(The docs really do not have much information so I'm starting to ask here.)

-- 
Rick R

Re: Iis pdfbox the correct choice for this scenario?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi Rick,

there are several attempts to provide a higher level API to generate PDF from content. At that point in time you  could give Apache fop a try for such a task.

Maruan Sahyoun

> Am 13.11.2013 um 16:11 schrieb Rick R <ri...@gmail.com>:
> 
> I need to create my pdf dynamically, iterating over different  types of
> java objects etc.. and all I'll be putting data into two columns ..
> basically a label column and then a value column. I need the value column
> to wrap though.
> 
> I don't see any sort of table like functionality built in?
> 
> (The docs really do not have much information so I'm starting to ask here.)
> 
> -- 
> Rick R

Re: Iis pdfbox the correct choice for this scenario?

Posted by Eliot Kimber <ek...@rsicms.com>.
There’s no general table-construction code in PDFBox. You need to
implement your own business logic for working out the geometry of where
your text and stuff will go. So you need to know the bounds of your area,
how much vertical space each cell requires, etc.

Unfortunately the code I wrote to do this was for a client so I can’t
share it, but basically I set up an object to hold the geometric aspects
and a helper class to maintain the current position on the page with some
helper methods to update the position as needed, e.g., to move down one
row or move to the second column, as well as logic to determine when the
page was full.

Here’s my method for actually writing text:

 public static void placeText(PDPageContentStream contentStream,
			float yPos, 
			float xPos, 
			String text) throws IOException {
		contentStream.beginText();
		contentStream.moveTextPositionByAmount( xPos, yPos );	
		contentStream.drawString(text);			
		contentStream.endText();
	}



And here’s a typical use:

   yPosition -= lineHeight;
			PDFHelper.placeText(
					contentStream,
					yPosition, 
					leftMargin, 
textValue);

			contentStream.setFont( fontHelvNormal, HEADER_TEXT_FONT_SIZE );
			yPosition -= (lineHeight * 2);
			PDFHelper.placeText(
					contentStream,
					yPosition, 
					leftMargin, 
textValue);

Cheers,


Eliot

-- 
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 512.554.9368
www.reallysi.com
www.rsuitecms.com




On 11/13/13, 9:11 AM, "Rick R" <ri...@gmail.com> wrote:

>I need to create my pdf dynamically, iterating over different  types of
>java objects etc.. and all I'll be putting data into two columns ..
>basically a label column and then a value column. I need the value column
>to wrap though.
>
>I don't see any sort of table like functionality built in?
>
>(The docs really do not have much information so I'm starting to ask
>here.)
>
>-- 
>Rick R