Java
  Home arrow Java arrow Page 2 - Creating Simple PDF Files 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? 
Google.com  
JAVA

Creating Simple PDF Files With iTextSharp
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2008-06-17


    Table of Contents:
  • Creating Simple PDF Files With iTextSharp
  • Working with fonts and text
  • Working with paragraphs
  • A short 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


    Creating Simple PDF Files With iTextSharp - Working with fonts and text
    ( Page 2 of 4 )

    Adding text to the document is quite easy. The most basic unit of text is the Chunk, which is simply a “chunk” of text that must have a consistent appearance. Here, we create a simple Chunk:


    Chunk boo = new Chunk("Boo!");


    Content must be manually added to the page:


    doc.Add(boo);


    We can stylize the text if we need to. Below, we make the text bold and big:


    boo.Font.SetStyle(Font.BOLD);

    boo.Font.Size = 72;


    As you can see, the Font property, which is of the Font type, represents the text's font. Above, we make it bold and give it a size of 72 points. To set the style, we can either pass an appropriate integer value (these values can be found in Font, like Font.Bold), or we can pass a string to achieve the same effect:


    boo.Font.SetStyle("bold");


    Fonts can also be created and passed into the constructor when creating a Chunk:


    Font small = new Font(Font.TIMES_ROMAN, 5);

    Chunk smallText = new Chunk("This is small.", small);


    Above, we create a font by specifying the font family (Times Roman) and a size (five points). However, we can specify several more properties in the constructor, such as the font style and the color. Below, we create a red, italicized font:


    Font redItalic = new Font(Font.HELVETICA, Font.DEFAULTSIZE,

     Font.ITALIC, Color.RED);


    Fonts can also be quickly and easily created using the GetFont method of the FontFactory class:


    Chunk hey = new Chunk("Hey.", FontFactory.GetFont("Courier", 12, Font.ITALIC));


    There's also a Phrase class, which is a bit higher level than the Chunk class, but is created similarly:


    Phrase p = new Phrase("This is a phrase.");




     
     
    >>> 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek