Hi,
We have a requirement where in we would have a image as a background. the
text would need to start at a particular position in the page and it needs
to do a textwrap automatically. And there may/may not be a image too and all
these will have a image in the background. I'm able to complete all of them
except that textwrap is not working. Can someone help me in accomplishing
the same. I tried using Cellcolumns but it does not work with a image
background.
I tried using CoulmnText functionality too. When I open the pdf, it gives
some warnings like 'Illegal operation 'm' inside a text oject' and I'm not
sure what it is.. this is how I used ColumnText method(in the class given
below)
ColumnText ct = new ColumnText(cb);
Font font24B = new Font(Font.TIMES_ROMAN, 24, Font.BOLD);
for (int j = 0; j < stringList.size(); j++) {
Phrase ph = new Phrase(stringList.get(j).toString());
System.out.println(ph);
cb.moveTo(300 + j, 600 - (20 * j));
ct.setYLine(600 - (20 * j));
ct.addText(new Chunk(stringList.get(j).toString(),font24B));
ct.go();
}
I'm attaching my code for reference.. Pls help me in fixing the problem.
Appreciate your help!!.
package com.hallmark.hbe.harness;
import com.hallmark.common.util.JDBCConnectionFactory;
import com.lowagie.text.*;
import com.lowagie.text.pdf.* ;
import java.awt.Color;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager ;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException ;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class ItextTest {
public final static String FONT_PATH = "c:\\windows\\fonts\\";
public final static String EMBEDDED_FONT_PATH = "fonts/";
public final static String OUTPUT_FILE_PATH = "files/";
public static void main(String[] args) {
// Creation of the document with a certain size and certain margins
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
Connection connection = null;
PreparedStatement p = null;
ResultSet rs = null;
try {
// creation of the different writers
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(OUTPUT_FILE_PATH+" pdfalign3.pdf
"));
document.open ();
BaseFont ef = BaseFont.createFont(EMBEDDED_FONT_PATH+"
ShelleyScript.ttf "
, "Cp1252", BaseFont.EMBEDDED);
PdfContentByte cb = writer.getDirectContent();
cb.setLineWidth(0f);
cb.beginText();
cb.setFontAndSize(ef, 12);
cb.setRGBColorFill(0, 0, 255);
connection = getDirectConnection();
String s = null;
s = "happy b'day happy b'day happy b'day happy b'day happy
b'day happy b'day\n\r happy b'day happy b'day"
System.out.println(",,,,,,," + s);
ArrayList stringList = new ArrayList();
for (StringTokenizer tok = new StringTokenizer(s, "\n\r");
tok.hasMoreTokens();) {
stringList.add(tok.nextToken());
}
for (int j = 0; j < stringList.size(); j++) {
System.out.println(stringList.get (j));
}
for (int j = 0; j < stringList.size(); j++) {
Paragraph para = new Paragraph(" ");
para.add(stringList.get(j));
System.out.println("Para is " + para.toString());
cb.showTextAligned (PdfContentByte.ALIGN_RIGHT, "" + para,
300 + j,
600 - (20 * j), 0);
}
cb.setTextMatrix(100, 400);
cb.setFontAndSize(ef, 14);
cb.endText();
Image image = Image.getInstance("1HBE1036-3-375.jpg");
image.setAlignment(Image.UNDERLYING);
document.add(image);
image = Image.getInstance ("infoicon.jpg");
image.setAbsolutePosition(180,450);
document.setMargins(50, 20,30,40);
document.add (image);
document.close();
System.out.println("FINISHED.");
} catch (Exception de) {
System.err.println(de.getMessage());
}
}
}
--
Regards,
Magesh
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/