First, let me say this a great site. This is my first PDF, and you guys sure made it
a lot easier. Here's my question. I have a report that prints landscape on legal size
paper. Due to the amount of information I must display, I would like to rotate the
text in certain cells to show a bottom to top orientation. Is there a way to get this
done using itext, or do I have to go through all the gyrations of full blown Java?
Any help you can give me is greatly appreciated. Below is my code for creating the
PDF.
Thanks, Jeff
package com.bigy.apps.distros.services;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.*;
import com.bigy.apps.distros.events.*;
import com.bigy.apps.distros.eventstatus.*;
import com.bigy.common.services.*;
import com.bigy.common.eventstatus.*;
import com.bigy.apps.distros.services.*;
import com.bigy.apps.distros.busobj.*;
import com.lowagie.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.awt.Point.*;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.pdf.PdfWriter;
//import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class PrintReportService {
public Document printDistros(Vector itemGroup,
//String dept,
String dsDate, Vector storeGroup, OutputStream out) {
Document doc = new Document(PageSize.LEGAL.rotate());
try {
PdfWriter.getInstance(doc, out);
//BaseFont arial = BaseFont.createFont("arial.ttf", BaseFont.WINANSI,
BaseFont.EMBEDDED);
Chunk chnk =
new Chunk(
"Big Y Foods Inc. - Product Distribution",
FontFactory.getFont(FontFactory.COURIER, 18, Font.BOLD,
java.awt.Color.black));
HeaderFooter header = new HeaderFooter(new Phrase(chnk), false);
header.setAlignment(10);
header.setBorder(Rectangle.BOTTOM);
Paragraph pg = new Paragraph();
pg.add(new Phrase("Department - "));
HeaderFooter footer = new HeaderFooter(pg, false);
doc.setFooter(footer);
doc.setHeader(header);
doc.open();
doc.newPage();
BaseFont bf =
BaseFont.createFont(
"c:\\winnt\\fonts\\cour.ttf",
BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
System.out.println("postscriptname: " + bf.getPostscriptFontName());
String[] codePages = bf.getCodePagesSupported();
for (int i = 0; i < codePages.length; i++) {
System.out.println(codePages[i]);
}
String names[][] = bf.getFullFontName();
for (int k = 0; k < names.length; ++k) {
if (names[k][0].equals("3") && names[k][1].equals("1")) //
Microsoft encoding
System.out.println(names[k][3]);
}
Font font = new Font(bf, 8);
Chunk ck1 =
new Chunk(
"",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Chunk ck2 =
new Chunk(
"",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Chunk ck3 =
new Chunk(
"",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Chunk ck4 =
new Chunk(
"",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
int stores = storeGroup.size();
int items = itemGroup.size();
Table table = new Table(stores + 26, items + 3);
table.setAutoFillEmptyCells(true);
table.setWidth(100);
table.setPadding(1);
Cell cell1 = new Cell(ck1);
cell1.setColspan(13);
cell1.setBorder(0);
table.addCell(cell1);
Cell cell2 = new Cell(ck2);
cell2.setColspan(6);
cell2.setBorder(0);
table.addCell(cell2);
Cell cell3 = new Cell(ck3);
cell3.setColspan(4);
cell3.setBorder(0);
table.addCell(cell3);
Cell cell4 = new Cell(ck4);
cell4.setColspan(3);
cell4.setBorder(0);
table.addCell(cell4);
for (int h = 0; h < storeGroup.size(); h++) {
StoreSales ssls = (StoreSales) storeGroup.get(h);
Chunk ck5 =
new Chunk(
ssls.getStorenum(),
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Cell header5 = new Cell(ck5);
header5.setBackgroundColor(java.awt.Color.lightGray);
table.addCell(header5);
header5.setColspan(1);
}
Cell cell6 = new Cell("");
cell6.setColspan(13);
cell6.setBorder(0);
table.addCell(cell6);
Cell cell7 = new Cell("");
cell7.setColspan(6);
cell7.setBorder(0);
table.addCell(cell7);
Cell cell8 = new Cell("");
cell8.setColspan(4);
cell8.setBorder(0);
table.addCell(cell8);
Cell cell9 = new Cell("");
cell9.setColspan(3);
cell9.setBorder(0);
table.addCell(cell9);
for (int h = 0; h < storeGroup.size(); h++) {
StoreSales ssls = (StoreSales) storeGroup.get(h);
Chunk ck10 =
new Chunk(
ssls.getStorename().substring(0, 10),
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Cell header10 = new Cell(ck10);
header10.setBackgroundColor(java.awt.Color.lightGray);
table.addCell(header10);
header10.rotate();
header10.setColspan(1);
}
Chunk ck11 =
new Chunk(
"Description",
FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD,
java.awt.Color.black));
Cell cell11 = new Cell(ck11);
cell11.setColspan(13);
cell11.setVerticalAlignment(Element.ALIGN_BOTTOM);
table.addCell(cell11);
Chunk ck12 =
new Chunk(
"Pack/Size",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Cell cell12 = new Cell(ck12);
cell12.setColspan(6);
cell12.setVerticalAlignment(Element.ALIGN_BOTTOM);
table.addCell(cell12);
Chunk ck13 =
new Chunk(
"Retail",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Cell cell13 = new Cell(ck13);
cell13.setColspan(4);
cell13.setVerticalAlignment(Element.ALIGN_BOTTOM);
table.addCell(cell13);
Chunk ck14 =
new Chunk(
"Code",
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Cell cell14 = new Cell(ck14);
cell14.setColspan(3);
cell14.setVerticalAlignment(Element.ALIGN_BOTTOM);
table.addCell(cell14);
for (int h = 0; h < storeGroup.size(); h++) {
StoreSales ssls = (StoreSales) storeGroup.get(h);
String storenum = ssls.getStorenum();
if (storenum.length() < 2) {
storenum = "80" + storenum + "00";
} else {
storenum = "8" + storenum + "00";
}
Chunk ck15 =
new Chunk(
storenum,
FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD,
java.awt.Color.black));
Cell header15 = new Cell(ck15);
header15.setHorizontalAlignment(Element.ALIGN_RIGHT);
header15.setBackgroundColor(java.awt.Color.lightGray);
table.addCell(header15);
header15.rotate();
header15.setColspan(1);
}
for (int i = 0; i < itemGroup.size(); i++) {
System.out.println("itemgrtoupsize " + itemGroup.size());
WhsDistroItems wdi = (WhsDistroItems) itemGroup.get(i);
System.out.println(wdi.getOrderCode() + " this is the order code");
Chunk ck16 =
new Chunk(
wdi.getDescription(),
FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD,
java.awt.Color.black));
Cell header16 = new Cell(ck16);
header16.setHorizontalAlignment(Element.ALIGN_RIGHT);
header16.setColspan(13);
table.addCell(header16);
Chunk ck17 =
new Chunk(
wdi.getPack() + "/" + wdi.getSizeDescription(),
FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD,
java.awt.Color.black));
Cell header17 = new Cell(ck17);
header17.setHorizontalAlignment(Element.ALIGN_RIGHT);
header17.setColspan(6);
table.addCell(header17);
Cell header18 = new Cell("");
header18.setHorizontalAlignment(Element.ALIGN_RIGHT);
header18.setColspan(4);
table.addCell(header18);
Chunk ck19 =
new Chunk(
wdi.getOrderCode(),
FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD,
java.awt.Color.black));
Cell header19 = new Cell(ck19);
header19.setHorizontalAlignment(Element.ALIGN_RIGHT);
header19.setColspan(3);
table.addCell(header19);
Vector cases = wdi.getCases();
for (int h = 0; h < cases.size(); h++) {
System.out.println("this is size of cases vector
"+cases.size());
String casenum = (String) cases.elementAt(h);
System.out.println("these are the cases "+casenum+" / "+h);
if(casenum.equals("null")){
casenum = "0";
}
Chunk ck20 =
new Chunk(
casenum,
FontFactory.getFont(FontFactory.COURIER, 8,
Font.BOLD, java.awt.Color.black));
Cell header20 = new Cell(ck20);
table.addCell(header20);
header20.rotate();
header20.setColspan(1);
}
}
doc.add(table);
System.out.println("Document117");
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
doc.close();
return doc;
}
public Vector printDistroList(String[] orderCode, String printDate, Vector
distros) {
DistrosBusSrve dbs = new DistrosBusSrve();
Vector listToPrint = new Vector();
Vector distroHistory = dbs.getStores();
String century = printDate.substring(6, 8);
String year = printDate.substring(8, 10);
String month = printDate.substring(0, 2);
String day = printDate.substring(3, 5);
System.out.println("THIS the list of distros to print " + orderCode);
try {
//establish connection
Connection conn = DistrosConnections.getDistroAS400Connection();
//create statement
Statement stmt = conn.createStatement();
for (int i = 0; i < orderCode.length; i++) {
String list = orderCode[i];
WhsDistroItems thisItem =
(WhsDistroItems)distros.get(Integer.parseInt(list));
Vector cases = dbs.getStores();
Vector sCases = new Vector();
String qry =
"select sdstor, sddamt from loglib.sdistrl1 where sdefcc = "
+ century
+ " and sdefyy = "
+ year
+ " and sdefmm = "
+ month
+ " and sdefdd = "
+ day
+ " and sditem = "
+ thisItem.getOrderCode()
+ "";
//create result set
System.out.println(qry);
ResultSet rs = stmt.executeQuery(qry);
//put while in here
while (rs.next()) {
int loc = dbs.findStore(cases, rs.getString(1));
if (loc != -1) {
StoreSales ss = (StoreSales) cases.get(loc);
ss.setCases(rs.getInt(2));
System.out.println("storenum " + rs.getString(1));
System.out.println("cases " + rs.getString(2));
//String tCases = getTotalCases(orderNum, distroDate);
//wmi.setTotalCases(tCases);
cases.set(loc, ss);
//end while
}
}
for( int s = 0;s<cases.size();s++){
StoreSales ss = (StoreSales)cases.get(i);
sCases.add(ss.getCases()+"");
}
thisItem.setCases(sCases);
listToPrint.add(thisItem);
}
stmt.close();
conn.close();
//end try
} catch (Exception e) {
e.printStackTrace();
}
return listToPrint;
}
}
Thanks, Jeff
************************************************************
This email message and any files transmitted with it contain confidential information
intended only for the person(s) to whom this email message is addressed.
If you have received this email message in error, please notify the sender immediately
by telephone or email and destroy the original message without making a copy.
Thank you.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions