Home Java Itext Rendering Example

Related Tutorials


 
 

Share on Google+Share on Google+

Rendering Example

Advertisement
In this section, you will learn how to make a program by which you can make a render page. iText api provides a method setTextRenderMode(int mode,float strokeWidth,Color strokeColor).We can gives various color and int mode.

Rendering Example

     

In this section, you will learn how to make a program by which you can make a render page. iText api provides a method setTextRenderMode(int mode,float strokeWidth,Color strokeColor).We can gives various color and int mode.   

Code Description:
 
In this example we are using setTextRenderMode(int mode,float strokeWidth,Color strokeColor) method for define the strokeWidth , stokeColor and the mode. We are giving more details about this method following:
setTextRenderMode(int mode,Color strokeColor):

 
With the setTextRenderMode(int mode,float strokeWidth,Color strokeColor) we can change the outline of the text.We are passing here three parameters. First is  int  mode it can  be one of the following values:

  1. PdfContentByte.TEXT_RENDER_MODE_FILL:The mode is used for  glyphs fontcolor, the strokeWidth and strokeColor don't play a role here.
  2. PdfContentByte.TEXT_RENDER_MODE_STROKE: We will only see the outline of the glyphs, with the given strokeWidth and strokeColor.
  3. PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE: The glyphs will be filled with the fontcolor and will have an outline with the given strokeWidth and strokeColor.
  4. PdfContentByte.TEXT_RENDER_MODE_INVISIBLE: The glyphs will be invisible.

The second  one is stroke Color to set the  color of the text.

setTextRenderMode(int mode,float strokeWidth,Color strokeColor):
 
With the setTextRenderMode(int mode,float strokeWidth,Color strokeColor) we can change the outline of the text.We are passing here three parameters. First is  int  mode it can  be one of the following values:

  1. PdfContentByte.TEXT_RENDER_MODE_FILL:The mode is used for  glyphs fontcolor, the strokeWidth and strokeColor don't play a role here.
  2. PdfContentByte.TEXT_RENDER_MODE_STROKE: We will only see the outline of the glyphs, with the given strokeWidth and strokeColor.
  3. PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE: The glyphs will be filled with the fontcolor and will have an outline with the given strokeWidth and strokeColor.
  4. PdfContentByte.TEXT_RENDER_MODE_INVISIBLE: The glyphs will be invisible.

The second  strokeWidth and the thread one is stroke Color to set the width of and color of the text.

The code of the program is given below:

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class exampleOFRendering 
  {
  public static void main(String[] args)throws Exception
  {
  System.out.println("Example of Rendering");  
  Document document = new Document();
  PdfWriter.getInstance(document,
new FileOutputStream
("Rendering.pdf"));
  document.open();
  Paragraph p = new Paragraph("Rose Text Rendering:");
  document.add(p);
  Chunk chunk = new Chunk("Rendering Test");
  chunk.setTextRenderMode(PdfContentByte.
TEXT_RENDER_MODE_FILL, 
100fnew Color(0xc00x000x0f));
  document.add(chunk);
  document.add(Chunk.NEWLINE);
  chunk.setTextRenderMode(PdfContentByte.
TEXT_RENDER_MODE_FILL_STROKE, 
0.3fnew Color(0xFc0x000x00));
  document.add(chunk);
  document.add(Chunk.NEWLINE);
  chunk.setTextRenderMode(PdfContentByte.
TEXT_RENDER_MODE_INVISIBLE, 
100fnew Color(0x0c0xF00x00));
  document.add(chunk);
  document.add(Chunk.NEWLINE);
  chunk.setTextRenderMode(PdfContentByte.
TEXT_RENDER_MODE_FILL_STROKE, 
0.3fnew Color(0x0c0x000xF0));
  document.add(chunk);
  document.add(Chunk.NEWLINE);
  Chunk bold = new Chunk("This looks like STROKE for Bold look");
  bold.setTextRenderMode(PdfContentByte.
TEXT_RENDER_MODE_FILL_STROKE, 
0.5fnew Color(0x0c0x000x00));
  document.add(bold);
  document.close();
  }
}

The output of the program is given below:

Download this example.

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 23, 2008

Related Tutorials

Discuss: Rendering Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com