Sorry, I hit reply and didn't notice that it wasn't being posted to
the list...
Here's the forward.
--
Please avoid sending me Word, PowerPoint or Excel attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
--- Begin Message ---
Paulo Soares wrote:
>
> Nothing can be said without looking at the code.
>
> Best Regards,
> Paulo Soares
>
I was looking at some of the possibilities of decoding the resultant
PDF, but if you don't mind, the code for the servlet in question is
attached.
Thanks for looking it over...
Barry
--
Please avoid sending me Word, PowerPoint or Excel attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
package com.blkline.bcw;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.util.*;
import java.math.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.util.MessageResources;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public final class ShowWrestlerBoutsActionPDF extends Action {
private static final int[] headerwidths = {48,3,9,9,9,9,9,3}; // AS PERCENTAGES
private static final String[] headings = {"Opponent/School", "D/T", "Date",
"Actual",
"Weight", "Level", "Score", "W/L"};
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Validate the request parameters specified by the user
ActionErrors errors = new ActionErrors();
// Put the TeamStats and stats list into the request
//HttpSession mySession = request.getSession();
// Get the current roster
Roster r = new Roster();
Document document = new Document(PageSize.LETTER, 36, 36, 36, 36);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Font headingFont = new Font(Font.HELVETICA, 8, Font.BOLD);
Font dataFont = new Font(Font.HELVETICA, 8);
try {
// creation of the different writers
PdfWriter.getInstance(document, baos);
//PdfWriter.getInstance(document, new
FileOutputStream("/tmp/team.pdf"));
// we add some meta information to the document
document.addAuthor("Barry L. Kline");
document.addSubject("Actual Weights.");
// we define a header and a footer
HeaderFooter header = new HeaderFooter(new Phrase("Interscholastic Athletic
Association"), false);
header.setAlignment(Element.ALIGN_CENTER);
document.setHeader(header);
// we open the document for writing
document.open();
// Loop through the roster.
for (int j=0; j < r.size(); j++) {
// Add the wrestler's name.
RosterBean rb = (RosterBean)(r.elementAt(j));
// Heading information
PdfPTable headingTable = new PdfPTable(2);
headingTable.getDefaultCell().setBorderWidth(0);
headingTable.setWidthPercentage(100);
headingTable.addCell(new Phrase(rb.getWrestler()));
headingTable.addCell(new Phrase("Huntingdon Area"));
headingTable.addCell(new Phrase("Jan 14 Certified
Weight: "+rb.getWeight()));
headingTable.addCell(new Phrase(" "));
document.add(headingTable);
document.add(new Paragraph(" ")); // Spacing.
// Put in the headings
PdfPTable datatable = new
PdfPTable(headerwidths.length);
datatable.setWidths(headerwidths);
datatable.setWidthPercentage(100);
datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
for ( int i=0; i < headings.length; i++ ) {
PdfPCell pcell = new PdfPCell(new
Phrase(headings[i],headingFont));
pcell.setHorizontalAlignment( i==0 ?
Element.ALIGN_LEFT : Element.ALIGN_CENTER );
datatable.addCell(pcell);
}
datatable.setHeaderRows(1);
// Add the wrestler's bouts
PdfPCell pcell = new PdfPCell(new Phrase("Last, First
(Bellefonte)",dataFont));
pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
datatable.addCell(pcell);
datatable.addCell(new Phrase("T",dataFont));
datatable.addCell(new Phrase("12-31-02",dataFont));
datatable.addCell(new Phrase("100.1",dataFont));
datatable.addCell(new Phrase("103",dataFont));
datatable.addCell(new Phrase("V",dataFont));
datatable.addCell(new Phrase("4-0",dataFont));
datatable.addCell(new Phrase("W",dataFont));
// Put the table into the document.
document.add(datatable);
document.add(new Paragraph("End of this wrestler..."));
// close this page
document.newPage();
datatable = null;
}
} catch(Exception e) {
e.printStackTrace();
}
document.close();
// Put it out
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
// Report any errors we have discovered back to the original form
if (!errors.empty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope()))
request.removeAttribute(mapping.getAttribute());
}
// Forward control to the specified success URI
return (mapping.findForward("success"));
}
}
--- End Message ---