Thanks very much Bruno. I'm gonna pull it apart today and figure you what
you are doing. Cya,
Kenny
----- Original Message -----
From: "Bruno" <[EMAIL PROTECTED]>
To: "Kenny G. Dubuisson, Jr." <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 13, 2003 3:02 AM
Subject: Re: [iText-questions] Can you have a second, HTML, stream going to
one browser
> Quoting "Kenny G. Dubuisson, Jr." <[EMAIL PROTECTED]>:
>
> > Sounds great but way over my head :P...would you mind sharing your code
for
> > me to look at. Thanks so much Bruno.
>
> OK, as promised.
> I made a reduced (UNTESTED) version of what I do normally in the
> case I have to let the user wait for a document.
>
> It might not work directly, you may have to change some things.
> It would be nice if you could turn it into an example I can put
> on my site:
>
> CLASS MyPdfGenerator
>
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
>
> import com.lowagie.text.Document;
> import com.lowagie.text.DocumentException;
> import com.lowagie.text.Paragraph;
> import com.lowagie.text.pdf.PdfWriter;
>
> public class MyPdfGenerator implements Runnable {
>
> public static final int NOT_STARTED = 0;
> public static final int BUSY = 1;
> public static final int FINISHED = 2;
> public static final int ABORTED = 3;
>
> private int status = NOT_STARTED;
> private int counter = 0;
> private static final int TOTAL = 1000;
> private ByteArrayOutputStream ba = new ByteArrayOutputStream();
>
> /**
> * @see java.lang.Runnable#run()
> */
> public void run() {
> try {
> status = BUSY;
> Document document = new Document();
> PdfWriter.getInstance(document, ba);
> document.open();
> while (counter < TOTAL) {
> document.add(new Paragraph(String.valueOf(counter)));
> counter++;
> }
> document.close();
> status = FINISHED;
> }
> catch(DocumentException de) {
> status = ABORTED;
> }
> }
>
> public int getPercentage() {
> return counter / TOTAL;
> }
>
> public boolean isBusy() {
> return status == BUSY;
> }
>
> public boolean isFinished() {
> return status == FINISHED;
> }
>
> public boolean isAborted() {
> return status == ABORTED;
> }
>
> public int getStatus() {
> return status;
> }
>
> public int size() {
> return ba.size();
> }
>
> public void writePdf(OutputStream out) throws IOException {
> ba.writeTo(out);
> }
> }
>
>
> CLASS PleaseWaitServlet
>
> import java.io.IOException;
> import java.io.PrintWriter;
>
> import javax.servlet.ServletException;
> import javax.servlet.ServletOutputStream;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.http.HttpSession;
>
> public class PleaseWaitServlet extends HttpServlet {
>
> /**
> * @see javax.servlet.http.HttpServlet#service(HttpServletRequest,
> HttpServletResponse)
> */
> protected void service(HttpServletRequest request, HttpServletResponse
response)
> throws ServletException, IOException {
> HttpSession session = request.getSession(true);
> MyPdfGenerator generator = (MyPdfGenerator) session.getAttribute("PDF");
> if (generator == null) {
> response.setHeader("Refresh", "3");
> generator = new MyPdfGenerator();
> Thread t = new Thread(generator);
> t.start();
> session.setAttribute("PDF", generator);
> doHtmlOutput(response, "document generation was initialized; please
wait");
> return;
> }
> if (generator.isBusy()) {
> response.setHeader("Refresh", "3");
> doHtmlOutput(response, "document generation is busy (" +
generator.getPercentage()
> + "% done); please wait");
> return;
> }
> if (generator.isFinished()) {
> doPdfOutput(response, generator);
> session.removeAttribute("PDF");
> return;
> }
> if (generator.isAborted()) {
> doHtmlOutput(response, "document generation was aborted, please contact
your system
> administrator.");
> session.removeAttribute("PDF");
> return;
> }
> }
>
> protected void doHtmlOutput(HttpServletResponse response, String message)
throws
> IOException {
> response.setContentType("Text/html");
> PrintWriter out = response.getWriter();
> out.println("<html><body>");
> out.println(message);
> out.println("</body></html>");
> out.flush();
> out.close();
> }
>
> protected void doPdfOutput(HttpServletResponse response, MyPdfGenerator
> generator) throws IOException {
> response.setContentType("application/pdf");
> response.setContentLength(generator.size());
> ServletOutputStream out = response.getOutputStream();
> generator.writePdf(out);
> }
>
> }
>
-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open!
Get cracking and register here for some mind boggling fun and
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions