Java
  Home arrow Java arrow Page 2 - Creating Simple PDF Files With iTextSh...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Creating Simple PDF Files With iTextSharp
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · Hello, all,I'm not entirely sure why this wasn't placed in ASPFree. Sorry about...
       · I have search over the net looking for examples on how to connect to sql database...
       · Generating a PDF document from a database would simply involved combining PDF...
     

       

    JAVA ARTICLES

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT