Java & J2EE Page 2 - Adding Images With iTextSharp |
Sometimes, it's necessary to put some space between the image and other content. This is done just as with a Paragraph. Like a Paragraph, an Image has IndentationLeft, IndentationRight, SpacingBefore, and SpacingAfter properties that can be used to pad the image. Here, we create half an inch of padding on all sides: logo.IndentationLeft = 36; logo.IndentationRight = 36; logo.SpacingBefore = 36; logo.SpacingAfter = 36; Note that adding padding will have no effect if there's nothing in the direction of the padding. For example, adding padding to the right of an image that's aligned to the right won't add extra space. Another technique that helps to set an image apart is adding a border to it. There are at least two steps involved in adding a border around an image. The first step is to set the Border property to specify what sides of the image will need a border. The binary OR operator can be used to combine Image.LEFT_BORDER, Image.RIGHT_BORDER, Image.TOP_BORDER, and Image_BOTTOM_BORDER to create the appropriate border. Here, we create a border around all sides of an image: logo.Border = Image.LEFT_BORDER | Image.TOP_BORDER | Image.RIGHT_BORDER | Image.BOTTOM_BORDER; The next step is to set the width of the border in points. Here, we set the border to be one point wide: logo.BorderWidth = 1; This will create a black border around all sides of the image. However, it's possible to specify a width for each side individually: logo.BorderWidthLeft = 1; logo.BorderWidthRight = 1; logo.BorderWidthTop = 1; logo.BorderWidthBottom = 1; These first two steps will create a black border around the image. Of course, black may not work in all situations, so it's possible to specify another color. Below, a border is set to red: logo.BorderColor = Color.RED; This will make the entire border red. As with width, though, each side can be colored differently: logo.BorderColorLeft = Color.LIGHT_GRAY; logo.BorderColorTop = Color.GRAY; logo.BorderColorRight = Color.DARK_GRAY; logo.BorderColorBottom = Color.BLACK;
blog comments powered by Disqus |
|
|
|
|
|
|
|