c# - iTextSharp ShowTextAligned Anchor Point -
i'm adding text pdf using itextsharp's showtextaligned method. method looks (c#):
public void showtextaligned( int alignment, string text, float x, float y, float rotation ) however, unclear anchor point text we're making. provide x , y, these correspond upper left corner of text rectangle, lower left corner, or else? impacted line spacing?
i looked @ documentation @ website, isn't explanatory. see pdfcontentbyte class / pdfcontentbyte methods / showtextaligned method.
obviously anchor point depends on kind of alignment. not make sense right-align if anchor point @ left side of text.
furthermore, text operations align relative baseline.
thus:
- for left aligned text anchor point left-most point of text baseline.
- for center aligned text anchor point middle point of text baseline.
- for right aligned text anchor point right-most point of text baseline.
more visually:
this has been generated using:
[test] public void showanchorpoints() { directory.createdirectory(@"c:\temp\test-results\content\"); string dest = @"c:\temp\test-results\content\showanchorpoints.pdf"; using (document document = new document()) { pdfwriter writer = pdfwriter.getinstance(document, new filestream(dest, filemode.create, fileaccess.write)); document.open(); pdfcontentbyte canvas = writer.directcontent; canvas.moveto(300, 100); canvas.lineto(300, 700); canvas.moveto(100, 300); canvas.lineto(500, 300); canvas.moveto(100, 400); canvas.lineto(500, 400); canvas.moveto(100, 500); canvas.lineto(500, 500); canvas.stroke(); columntext.showtextaligned(canvas, element.align_left, new phrase("left aligned"), 300, 500, 0); columntext.showtextaligned(canvas, element.align_center, new phrase("center aligned"), 300, 400, 0); columntext.showtextaligned(canvas, element.align_right, new phrase("right aligned"), 300, 300, 0); } } 
Comments
Post a Comment