Kyle,
Are you setting the content type on the response? Are you setting the
content length on the response? Given that you only posted a snippet of
your code, are you writing the contents of your ByteArrayOutputStream to
the response?
response.setContentType("application/pdf");
response.setContentLength(baosPDF.toByteArray().length);
response.getOutputStream().write(baosPDF.toByteArray());
_______________________
Jeremy Nix
Senior Application Developer
Southwest Financial Services, LTD.
(513) 621-6699 x1158
www.sfsltd.com
-----Original Message-----
From: Kyle [mailto:[EMAIL PROTECTED]
Sent: Friday, July 29, 2005 12:54 PM
To: [email protected]
Subject: [iText-questions] Help with outputting bytestream to PDF
Hi,
I have a page that calls a servlet, that calls another class that gets a
resultset. I want that class to take the resultset, iterate through it,
and
call another class's method to display the output stream in a new pdf in
IE
(without creating a pdf file). The problem is that it loads through the
files, but it only displays a blank white screen...obviously I'm missing
something with the outputstream part. I've included some snippets of
the code
below, so only the itext related parts will be shown. Any help will be
GREATLY APPRECIATED!! :)
Here is the servlet being called, all it does is call the next class:
---------------------------------------
package com.scires.ntiraweb.beans;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.scires.ntiraweb.beans.ExportInstallPlanData_PDFShapes;
import com.lowagie.text.pdf.PdfContentByte;
public class PDFServletReport1 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
private static final Logger log =
Logger.getLogger(SchedulerServlet.class);
try
{
ExportInstallPlanData_PDFShapes pdf = new
ExportInstallPlanData_PDFShapes();
pdf.getPDFResult(request, response);
}
catch (Exception se) {
log.info(se);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
doGet(request,response);
}
}
----------------------------------------------------------
//And this is a snippet of the file that I want to call the class for
the
// output stream
---------------------------------------------------------
package com.scires.ntiraweb.beans;
import com.lowagie.text.pdf.PdfContentByte;
import com.scires.ntira.common.db.RSBean;
import com.scires.ntira.common.constants.DatabaseConstants;
import com.scires.ntiraweb.reports.itext.PDFShapes;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class ExportInstallPlanData_PDFShapes extends RSBean {
public void getPDFResult(HttpServletRequest request, HttpServletResponse
response)
throws javax.servlet.ServletException, java.io.IOException {
Document doc = new Document(PageSize.A4.rotate(),10,10,10,10);
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
PdfWriter docWriter = null;
try {
PDFShapes pdfShape = new PDFShapes();
docWriter = PdfWriter.getInstance(doc, baosPDF);
doc.setPageSize(PageSize.A1);
doc.open();
PdfContentByte cb = docWriter.getDirectContent();
// pdfShape.rectangle calls a method in the next class that will output
// the result
pdfShape.rectangle(5,6,10,8,cb);
}
-------------------------------------------------------
And this is the method in PDFShapes that pdfShape.rectangle calls
------------------------------------------------------
public class PDFShapes {
public void rectangle(int xCoord, int yCoord, int rectWidth, int
rectHeight,
PdfContentByte cbr ) { // x, y, width, height
cbr.setLineWidth(10f);
// draw a rectangle
cbr.rectangle(xCoord, yCoord, rectWidth,
rectHeight);
cbr.stroke();
// Model Rectangle (Adjust for scaling)
/* cb.setLineWidth(10f);
// draw a rectangle
cb.rectangle(100, 700, 10, 10);
cb.stroke(); */
}
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
iText-questions mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions