Find in this group all groups
Unknown more information…

i : 18 May 2006 • 3:13PM -0400

Re: [iText-questions] How to draw a horizontal line in PDF
by bruno


Darryl Miles wrote:

> Singhal, Ramneek (Exchange) wrote:
>> A newbie question. How to draw a horizontal line (same as <HR> in html)
>> in PDF using iText.
>     Document document = new Document(PageSize.A4, 36, 36, 36, 36);
>     PdfWriter writer = PdfWriter.getInstance(document, out);
>     PdfContentByte cb = writer.getDirectContent();
>     cb.setLineWidth(2.0f);     // Make a bit thicker than 1.0 default
>     cb.setGrayStroke(0.95f); // 1 = black, 0 = white
>     float x = 72f;
>     float 7 = 72f;
>     cb.moveTo(x,         y);
>     cb.lineTo(x + 72f*6, y);
>     cb.stroke();

That's a good example.
A follow-up question could be: how do I know the value of y?
There are different possibilities.
PdfWriter has a method getVerticalPosition,
but I like to use page events to draw lines,
for instance using onParagraph or onGenericTag.

> On a related note if you know how to do a relative lineTo in iText I
> would like to know, maybe PDF doesn't allow it ?

See table 4.9 on page 196-197 of the PDF Reference manual
for a list with the 'path construction operators'.
There is no relative lineTo...

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
iText-questions mailing list

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.