By Date: <-- -->
By Thread: <-- -->

How to draw a horizontal line in PDF



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();


Maybe you want to replace "72f*6" with "PageSize.A4.getWidth() - 72.0" as the above example only gives you a 1 inch horizontal line, set one inch up from origin (south-west corner).



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 ? But in the direct PostScript I am porting from it would go like this:


/hrline {
	gsave

	translate

	2 setlinewidth
	0.95 setgray

	0 0 moveto
	72 6 mul 0 rlineto  %% rlineto here in iText ?
	stroke

	grestore
} def

72 72 hrline



HTH

Darryl


------------------------------------------------------- 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 http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions (at) lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions