Java
  Home arrow Java arrow Page 3 - Adding Images With iTextSharp
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Adding Images With iTextSharp
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2008-07-01


    Table of Contents:
  • Adding Images With iTextSharp
  • Adding padding and a border
  • Manipulating an Image
  • An example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Adding Images With iTextSharp - Manipulating an Image
    ( Page 3 of 4 )

    Images don't have to be added to the document as-is. Sometimes they will need to be altered or transformed in some way. The library provides a few ways to transform images. We'll take a look at two of them here.

    One of the most basic ways to manipulate an image is to rotate it. Rotation is possible with iTextSharp using two properties: Rotation and RotationDegrees. The first property can be used to rotate the image by an angle in radians. For example, an image could be rotated a quarter-turn counterclockwise like this:

    logo.Rotation = (float)Math.PI / 2;

    Of course, most people will be more comfortable using degrees. The RotationDegrees property can be used to rotate an image by an angle in degrees. The same quarter-turn could be done using RotationDegrees like this:

    logo.RotationDegrees = 90;

    Images can also be resized, or scaled, using iTextSharp. There are three ways that an image can be scaled. The first is to scale an image to a certain height, width, or both. The ScaleAbsolute method can be used to give the image both a new height and a new width. To make an image 72 points tall and 36 points wide, we'd do this:

    logo.ScaleAbsolute(36, 72);

    The height or width of an image can be modified using the ScaleAbsoluteHeight and ScaleAbsoluteWidth methods:

    logo.ScaleAbsoluteHeight(72);

    logo.ScaleAbsoluteWidth(72);

    If you're not careful, though, scaling an image to a specific height or width can distort the image. The ScalePercent method can remedy this. We can pass it a percentage, which will be used to scale the image. To make the image half of its original size, we'd do this:

    logo.ScalePercent(50);

    Alternatively, the height and the width can be scaled separately. To make the image half as wide, but just as tall, we'd do this:

    logo.ScalePercent(50, 100);

    As you can see, the first parameter is the percentage to scale the width by, and the second is the percentage to scale the height.

    The third way to scale an image is to scale it to fit within a given rectangle using the ScaleToFit method. This accepts a width and a height, just like ScaleAbsolute, but it will not distort the image. The image will be scaled to fit within the rectangle but won't necessarily fill up the rectangle. So, if the original image is a square, and we use ScaleToFit with 72 as the width and 100 as the height, it will end up with both a width and a height of 72:


    logo.ScaleToFit(72, 100);

    The new dimensions can be checked with the ScaledWidth and ScaledHeight properties.



     
     
    >>> More Java Articles          >>> More By Peyton McCullough
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT