Gerar arquivo PDF "gigante"

Tenho um sistema que gera relatórios em PDF
em um determinado caso preciso gerar um pdf com uma quantidade grande de detalhes…
onde o pdf vai ter por volta de 1gb e pouco.
Estou usando o iReport e ja tentei usando diversas formas de gerar tais pdfs.
Alguem conhece alguma forma de gerar relatórios grandes assim ??

http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=44280

[color=darkblue] Uma vez fiz alguns testes para gerar PDF e uma das maneiras que encontrei também foi essa via Servlet, mas acabei usando Jasper :[/color]

Howto Servlet JavaStudioCreator2_1 and iText for PDF Creation ?

[color=darkblue] Para facilitar também o código :[/color]



import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

/** 
 * 
 * 
 */
public class PDFServlet extends HttpServlet
{
	/** 
	* 
	* 
	*/
	public PDFServlet()
	{
		super();
	}

	/**
	 *  
	 * 
	 * 
	 */
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws javax.servlet.ServletException, java.io.IOException
	{
		DocumentException ex = null;
		
		ByteArrayOutputStream baosPDF = null;
		
		try
		{
			baosPDF = generatePDFDocumentBytes(req, this.getServletContext());
			
			StringBuffer sbFilename = new StringBuffer();
			sbFilename.append("filename_");
			sbFilename.append(System.currentTimeMillis());
			sbFilename.append(".pdf");

			////////////////////////////////////////////////////////
			// Note: 
			//
			// It is important to set the HTTP response headers 
			// before writing data to the servlet's OutputStream 
			//
			////////////////////////////////////////////////////////
			//
			//
			// Read the HTTP 1.1 specification for full details
			// about the Cache-Control header
			//
			resp.setHeader("Cache-Control", "max-age=30");
			
			resp.setContentType("application/pdf");
			
			//
			//
			// The Content-disposition header is explained
			// in RFC 2183
			//
			//    http://www.ietf.org/rfc/rfc2183.txt
			//
			// The Content-disposition value will be in one of 
			// two forms:
			//
			//   1)  inline; filename=foobar.pdf
			//   2)  attachment; filename=foobar.pdf
			//
			// In this servlet, we use "inline"
			//
			StringBuffer sbContentDispValue = new StringBuffer();
			sbContentDispValue.append("inline");
			sbContentDispValue.append("; filename=");
			sbContentDispValue.append(sbFilename);
							
			resp.setHeader(
				"Content-disposition",
				sbContentDispValue.toString());

			resp.setContentLength(baosPDF.size());

			ServletOutputStream sos;

			sos = resp.getOutputStream();
			
			baosPDF.writeTo(sos);
			
			sos.flush();
		}
		catch (DocumentException dex)
		{
			resp.setContentType("text/html");
			PrintWriter writer = resp.getWriter();
			writer.println(
					this.getClass().getName() 
					+ " caught an exception: " 
					+ dex.getClass().getName()
					+ "<br>");
			writer.println("&lt;pre&gt;");
			dex.printStackTrace(writer);
			writer.println("&lt;/pre&gt;&quot;);
		}
		finally
		{
			if (baosPDF != null)
			{
				baosPDF.reset();
			}
		}
		 
	}

	/**
	 *  
	 * @param req must be non-null
	 * 
	 * @return a non-null output stream. The output stream contains
	 *         the bytes for the PDF document
	 * 
	 * @throws DocumentException
	 * 
	 */
	protected ByteArrayOutputStream generatePDFDocumentBytes(
		final HttpServletRequest req,
		final ServletContext ctx)
		throws DocumentException
		
	{	
		Document doc = new Document();
		
		ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
		PdfWriter docWriter = null;

		try
		{
			docWriter = PdfWriter.getInstance(doc, baosPDF);
			
			doc.addAuthor(this.getClass().getName());
			doc.addCreationDate();
			doc.addProducer();
			doc.addCreator(this.getClass().getName());
			doc.addTitle(&quot;This is a title.&quot;);
			doc.addKeywords(&quot;pdf, itext, Java, open source, http&quot;);
			
			doc.setPageSize(PageSize.LETTER);
			
			HeaderFooter footer = new HeaderFooter(
							new Phrase(&quot;This is a footer.&quot;),
							false);

			doc.setFooter(footer);
		
			doc.open();
			
			doc.add(new Paragraph(
						&quot;This document was created by a class named: &quot;
						+ this.getClass().getName()));
						
			doc.add(new Paragraph(
						&quot;This document was created on &quot;
						+ new java.util.Date()));

			String strServerInfo = ctx.getServerInfo();
			
			if (strServerInfo != null)
			{
				doc.add(new Paragraph(
						&quot;Servlet engine: &quot; + strServerInfo));
			}
			
			doc.add(new Paragraph(
						&quot;This is a multi-page document.&quot;));
			
			doc.add( makeGeneralRequestDetailsElement(req) );
			
			doc.newPage();
			
			doc.add( makeHTTPHeaderInfoElement(req) );
			
			doc.newPage();
			
			doc.add( makeHTTPParameterInfoElement(req) );
			
		}
		catch (DocumentException dex)
		{
			baosPDF.reset();
			throw dex; 
		}
		finally
		{
			if (doc != null)
			{
				doc.close();
			}
			if (docWriter != null)
			{
				docWriter.close();
			}
		}

		if (baosPDF.size() &lt; 1)
		{
			throw new DocumentException(
				&quot;document has &quot;
				+ baosPDF.size()
				+ &quot; bytes&quot;);		
		}
		return baosPDF;
	}
	
	/**
	 * 
	 * @param req HTTP request object
	 * @return an iText Element object
	 * 
	 */
	protected Element makeHTTPHeaderInfoElement(final HttpServletRequest req)
	{
		Map mapHeaders = new java.util.TreeMap();
		
		Enumeration enumHeaderNames = req.getHeaderNames();
		while (enumHeaderNames.hasMoreElements())
		{
			String strHeaderName = (String) enumHeaderNames.nextElement();
			String strHeaderValue = req.getHeader(strHeaderName);
			
			if (strHeaderValue == null)
			{
				strHeaderValue = &quot;&quot;;
			}
			mapHeaders.put(strHeaderName, strHeaderValue);
		}

		Table tab = makeTableFromMap(
				&quot;HTTP header name&quot;,
				&quot;HTTP header value&quot;,
				mapHeaders);
		
		return (Element) tab;
	}

	/**
	 *  
	 * @param req HTTP request object 
	 * @return an iText Element object
	 * 
	 */
	protected Element makeGeneralRequestDetailsElement(
						final HttpServletRequest req)
	{
		Map mapRequestDetails = new TreeMap();
		 
		mapRequestDetails.put(&quot;Scheme&quot;, req.getScheme());
				
		mapRequestDetails.put(&quot;HTTP method&quot;, req.getMethod());
				
		mapRequestDetails.put(&quot;AuthType&quot;, req.getAuthType());
				
		mapRequestDetails.put(&quot;QueryString&quot;, req.getQueryString());
				
		mapRequestDetails.put(&quot;ContextPath&quot;, req.getContextPath());
				
		mapRequestDetails.put(&quot;Request URI&quot;, req.getRequestURI());
				
		mapRequestDetails.put(&quot;Protocol&quot;, req.getProtocol());
				
		mapRequestDetails.put(&quot;Remote address&quot;, req.getRemoteAddr());
				
		mapRequestDetails.put(&quot;Remote host&quot;, req.getRemoteHost());
				
		mapRequestDetails.put(&quot;Server name&quot;, req.getServerName());
				
		mapRequestDetails.put(&quot;Server port&quot;, &quot;&quot; + req.getServerPort());
				
		mapRequestDetails.put(&quot;Preferred locale&quot;, req.getLocale().toString());
				
		Table tab = null;
		
		tab = makeTableFromMap(
						&quot;Request info&quot;, 
						&quot;Value&quot;,
						mapRequestDetails);
		
		return (Element) tab;
	}

	/**
	 * 
	 * 
	 * @param req HTTP request object
	 * @return an iText Element object
	 * 
	 */
	protected Element makeHTTPParameterInfoElement(
					final HttpServletRequest req)
	{
		Map mapParameters = null;
		
		mapParameters = new java.util.TreeMap(req.getParameterMap());

		Table tab = null;

		tab = makeTableFromMap(
				&quot;HTTP parameter name&quot;,
				&quot;HTTP parameter value&quot;,
				mapParameters);
		
		return (Element) tab;
	}
	
	/**
	 *
	 * @param firstColumnTitle
	 * @param secondColumnTitle
	 * @param m map containing the data for column 1 and column 2
	 * 
	 * @return an iText Table
	 * 
	 */
	private static Table makeTableFromMap(
			final String firstColumnTitle,
			final String secondColumnTitle,
			final java.util.Map m)
	{
		Table tab = null;

		try
		{
			tab = new Table(2 /* columns */);
		}
		catch (BadElementException ex)
		{
			throw new RuntimeException(ex);
		}
		
		tab.setBorderWidth(1.0f);
		tab.setPadding(5);
		tab.setSpacing(5);

		tab.addCell(new Cell(firstColumnTitle));
		tab.addCell(new Cell(secondColumnTitle));
		
		tab.endHeaders();

		if (m.keySet().size() == 0)
		{
			Cell c = new Cell(&quot;none&quot;);
//			c.setColspan(tab.columns());
			tab.addCell(c);
		}
		else
		{
			Iterator iter = m.keySet().iterator();
			while (iter.hasNext())
			{
				String strName = (String) iter.next();
				Object value = m.get(strName);
				String strValue = null;
				if (value == null)
				{
					strValue = &quot;&quot;;
				}
				else if (value instanceof String[])
				{
					String[] aValues = (String[]) value;   
					strValue = aValues[0];
				}
				else
				{
					strValue = value.toString();
				}
				
				tab.addCell(new Cell(strName));
				tab.addCell(new Cell(strValue));
			}
		}
		
		return tab;
	}
	 
}

Ñ entendi thingol
ele não resolveu o problema…

[quote=Metaleiro][color=darkblue] Uma vez fiz alguns testes para gerar PDF e uma das maneiras que encontrei também foi essa via Servlet, mas acabei usando Jasper :[/color]

Howto Servlet JavaStudioCreator2_1 and iText for PDF Creation ?

[color=darkblue] Para facilitar também o código :[/color]

[/quote]

Não tenho certesa mais creio que dará problema por causa do tamanho do PDF
mais irei testar

É claro que ele não resolveu o problema. O que estou dizendo é que você pode ter problemas se tiver de criar um relatório tão grande com o iReport; talvez tenha de usar alguma solução comercial - se bobear, nem uma solução Java exista. Deixo para você a pesquisa, ou então quebre o relatório em PDFs de várias partes (por exemplo, em vez de gerar um relatório anual, gere 12 relatórios mensais e mais um relatório do resumo anual. Nem sei se o Adobe Reader consegue carregar um arquivo tão grande assim.)