Home arrow Java & J2EE arrow Page 2 - Adding Images With iTextSharp

Adding padding and a border - Java

Often, text alone can communicate a message, but sometimes graphics are needed. Even when they aren't, text alone can be a bit dull to read. In this article, we'll take a look at incorporating graphics into a PDF document with iTextSharp.

TABLE OF CONTENTS:
  1. Adding Images With iTextSharp
  2. Adding padding and a border
  3. Manipulating an Image
  4. An example
By: Peyton McCullough
Rating: starstarstarstarstar / 13
July 01, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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;



 
 
>>> More Java & J2EE Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: