Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Measure Of Width    

                         

In this section, you will learn how we can measure the width of the page.  iText api provides a getWidthPoint() to know the width of the page. The width will be in centimeters or inches.

Code Description:
getWidthPoint():
If we have a Chunk and we want to know it's width on a page then we can use the method getWidthPoint(). It gives us the width in points and we will have to do maths to know the width in inches or centimeters.
setHorizontalScaling(float scale):
With the method setHorizontalScaling(float scale), we can shrink (scale < 1.0f) or expand (scale > 1.0f) the Chunk. In the example we first print the Chunk in its actual size, then we print it twice at half its size (scale = 0.5f).

The code of the program is given below:

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.PdfWriter;
public class MeasureOfWidth {  
  public static void main(String[] args)throws Exception {
    System.out.println("Example of measure Width of the chunk");
    Document document = new Document();
      PdfWriter.getInstance(document,new 
FileOutputStream
("Width.pdf"));
      document.open();
      Chunk c = new Chunk("Rose India");
      float w = c.getWidthPoint();
      Paragraph p = new Paragraph("The width of the chunk: '");
      p.add(c);
      p.add("' is ");
      p.add(String.valueOf(w));
      p.add(" points or ");
      p.add(String.valueOf(w / 72f));
      p.add(" inches.");
      document.add(p);
      document.add(c);
      document.add(Chunk.NEWLINE);
      c.setHorizontalScaling(0.5f);
      document.add(c);
      document.add(c);    
      document.close();
  }
}

The output of the program is given below:

Download this example.

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

sir,

All the example that you have given we fine. now i want to know; how to find the position of the text in a pdf file.

Reply me as soon as possible.

yours truly,

prabu

Posted by prabu on Monday, 04.30.07 @ 15:08pm | #15092

Latest Searches:
client/server computin
checkbox button enable
java drivers use to co
dojo.query
array in javascript
char at
validate using picture
jQuery To Slide Effect
calculate time
Linux Caixa MÐ????Ð???
runnable
calculator square root
decimal to aski
how to check the char
css
String to array in jav
dropdown list in jsp
array element in php
Use of <fn:substringBe
global variable in j
calling one jsp p
pagination using javas
data grid
draw Flag
types of webserver
Photoshop Textures and
java 4 features
JSON AJAX
array element
Creating Midlet Applic
convert java.sql.Time
meterbar bean
xls
php oops
json lib/componen...]=
Photoshop Web Layouts
paging and sorting wit
combo box my sql
stored procedure debug
connection pooling usi
logout code in jsp
JSF tree collapse
log4j
clear grid dojo
scroll bar
java merging images
tree
jersey
example of JFileChoos
retreive numerical val
Selection Sort In Java
jtabbedpanel enabled
Image with mouse drag
Photoshop Text Effects
VB Project
message box display in
Binome
Authentication Filters
how to iterate a linke
compare two arraylist
jsf tree node set hr
get url
ajax auto complete
jar entry
diff. shape of linear
advantages of jsp over
jsp method
Struts Projects
tax calculator
Passing Parameters in
FlowLayout
JDBC-ODBC
<form: checkbox path=
Treemap using gwt tree
draw Polyline
comparable
jsp with strutsframewo
selecting option value
struts-servlets.xml
generate report in exc
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.