Hi,
I followed example Chapter7/ColumnControl.java to create a fax cover sheet
for my project. I am trying to generate text which will be displayed on the
new page without changing the font size.
http://www.nabble.com/file/p16995100/CompleteCoverPage.pdf
CompleteCoverPage.pdf .
In the uploaded pdf, the text is to be displayed under the Comments section.
But no text is displayed. Can anyone please help?
My source code
public class CoverPage {
/** Arial Bold Font of Size 18. */
private static Font ARIAL_BOLD_FONT =
FontFactory.getFont("Arial", 18, Font.BOLD);
/** Arial Normal Font of size 10. */
private static Font ARIAL_NORMAL_FONT =
FontFactory.getFont("Arial", 10, Font.NORMAL);
private static final String COVER_PAGE_TEMPLATE = "CompleteCoverPage.pdf";
private static final Logger logger= Logger.getLogger(CoverPage.class);
private static String destination = "1234567890";
private static String from = "Kartik Krishnan";
private static String regarding =
"This is a very very long string to test if the line can be" +
" broken into a separate lines and rolled over onto the next
line." +
" We hope that this works. Good Luck !!!!";
public static void main(String[] args) throws IOException,
DocumentException {
createCoverPage();
}
@SuppressWarnings("unused")
private static void createCoverPage()
throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(COVER_PAGE_TEMPLATE));
document.open();
PdfContentByte cb = writer.getDirectContent();
if (logger.isDebugEnabled()) {
logger.debug("Adding the FAX COVER SHEET as text.");
}
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(document.left(), 0, document.right(),
document.top());
ct.setAlignment(Element.ALIGN_LEFT);
if (logger.isDebugEnabled()) {
logger.debug("Add the text <em>FAX COVER SHEET</em>.");
}
ct.setSimpleColumn(document.left() + 20, 685, document.right() - 20,
document.bottom() - 20);
ct.addText(new Phrase(new Chunk("FAX COVER SHEET", ARIAL_BOLD_FONT)));
ct.go();
if (logger.isDebugEnabled()) {
logger.debug("Underline <em>FAX COVER SHEET</em>.");
}
cb.moveTo(document.left() + 20, 665);
cb.lineTo(document.right() - 20, 665);
cb.stroke();
if (logger.isDebugEnabled()) {
logger.debug("Adding the fields (To, From, Date, Re on the left
column.");
}
String[] titles = {"To", "From", "Date", "Re"};
int titlesLength = titles.length;
for (int index = 0; index < titlesLength; index ++) {
ct.setSimpleColumn(document.left() + 20, 665 - index * 20,
document.right()/2 + 15, document.bottom() - 20);
ct.addText(new Phrase(new Chunk(titles[index], ARIAL_NORMAL_FONT)));
ct.go();
}
if (logger.isDebugEnabled()) {
logger.debug("Adding the COMMENTS text.");
}
ct.setSimpleColumn(document.left() + 20, 555, document.right() - 20,
document.bottom() - 20);
ct.addText(new Phrase(new Chunk("COMMENTS", ARIAL_BOLD_FONT)));
ct.go();
if (logger.isDebugEnabled()) {
logger.debug("Underline <em>Comments</em>.");
}
cb.moveTo(document.left() + 20, 535);
cb.lineTo(document.right() - 20, 535);
cb.stroke();
// Populate the data.
if (logger.isDebugEnabled()) {
logger.debug(
"Adding destination, from, date, regarding, and comments.");
}
ct.setSimpleColumn(document.right()/5 + 30, 665 ,
document.right() - 20, document.bottom() - 20);
ct.addText(new Chunk(destination, ARIAL_NORMAL_FONT));
ct.go();
ct.setSimpleColumn(document.right()/5 + 30, 645 ,
document.right() - 20, document.bottom() - 20);
ct.addText(new Chunk(from, ARIAL_NORMAL_FONT));
ct.go();
ct.setSimpleColumn(document.right()/5 + 30, 625 ,
document.right() - 20, document.bottom() - 20);
ct.addText(new Chunk(getCurrentDate(), ARIAL_NORMAL_FONT));
ct.go();
ct.setSimpleColumn(document.right()/5 + 30, 605 ,
document.right() - 20, document.bottom() - 20);
ct.addText(new Chunk(regarding, ARIAL_NORMAL_FONT));
ct.go();
// Add the comments. If the content is longer than the page,
ct.setSimpleColumn(document.left() + 20, 535, document.right() - 20,
document.bottom() - 20, 18, Element.ALIGN_LEFT);
Phrase p = new Phrase(listToString(createComments()));
ct.addText(p);
int status = ct.go(true);
if (!ColumnText.hasMoreText(status)) {
ct.addText(p);
status = ct.go(false);
document.newPage();
} else {
document.newPage();
ct.setText(p);
ct.go();
}
document.close();
}
/**
* Create a [EMAIL PROTECTED] List} of very long strings to test if the lines
can be
* rolled over onto the next line when creating a cover page.
*/
private static List<String> createComments() {
List<String> comments = new ArrayList<String>();
comments.add("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+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aaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
return comments;
}
/** Returns the String representation of the current date. */
private static String getCurrentDate() {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd yyyy, HH:mm z");
return sdf.format(now);
}
/**
* Return the String representation of [EMAIL PROTECTED] List} contents. Each
element
in
* the [EMAIL PROTECTED] List} is separated by the carriage return.
*/
private static String listToString(List<String> comments) {
StringBuilder sb = new StringBuilder();
for (String comment : comments) {
sb.append(comment).append("\n");
}
return sb.toString().trim();
}
}
--
View this message in context:
http://www.nabble.com/New-Page-is-not-added-for-the-end-of-the-page-for-a-very%2C-very-long-text-tp16995100p16995100.html
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar