If you are writing the PDF to the outputstream your struts action can
(should) return null.
On 12/15/05 11:28 AM, "Diana K. Woodhouse" <[EMAIL PROTECTED]> wrote:
> Nevermind this null pointer exception. I made the Pdf
> class extend Action and added this method.
>
> public ActionForward execute(
> ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response ) throws
> IOException, ServletException {
>
> HttpSession httpsession = request.getSession(true);
> try {
> ...
>
> NEW PROBLEM with this: The action needs to return
> something. How can the action return the Pdf in the
> Outputstream?????
>
>
>
> --- "Diana K. Woodhouse" <[EMAIL PROTECTED]> wrote:
>
>> Thanks everybody for your replies! I've changed the
>> method createPdf() below to stream to an output
>> buffer
>> like in the tutorial example. I'm getting a null
>> pointer exception in the close method.
>>
>> // NEW
>> private ByteArrayOutputStream baos;
>> private ServletOutputStream out;
>> private ServletResponse response;
>>
>> public Pdf(String filename) {
>>
>> try {
>>
>> // we create a reader for a certain document
>> infilename = path + "form.pdf";
>>
>>
>> // we create a reader for a certain document
>> reader = new PdfReader(infilename);
>>
>>
>> // we retrieve the size of the first page
>> pager = reader.getPageSize(1);
>>
>> // step 1: creation of a document-object
>> document = new Document(pager, 50, 50, 50, 50);
>>
>> // NEW
>> baos = new ByteArrayOutputStream();
>>
>> // step 2: we create a writer that listens to
>> // the document
>>
>> // OLD
>> //writer = PdfWriter.getInstance(document,
>> new
>> FileOutputStream(outfilename));
>>
>> // NEW
>> writer = PdfWriter.getInstance(document, baos);
>>
>> // step 3: we open the document
>> document.open();
>>
>> // step 4: we add content
>> cb = writer.getDirectContent();
>> document.newPage();
>> pagew = writer.getImportedPage(reader, 1);
>> cb.addTemplate(pagew, 0, 0);
>> // we tell the ContentByte we're ready to draw text
>> cb.beginText();
>>
>> bf = BaseFont.createFont(BaseFont.HELVETICA,
>> BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
>> cb.setFontAndSize(bf, 10);
>>
>>
>> pdf.setConfnumber(record.getConfnumber());
>> cb.endText();
>> } catch (Exception e) {}
>> }
>>
>> public void close() {
>> // step 5: we close the document
>> document.close();
>>
>> try {
>>
>> // NEW
>>
>> response.setContentType("application/pdf");
>> response.setContentLength(baos.size());
>> out = response.getOutputStream();
>> baos.writeTo(out);
>> out.flush();
>> } catch (Exception e) {
>> log.error("Function pdf.close failed: " +
>> e);
>>
>> }
>> }
>>
>>
>> Error message is:
>>
>> Function pdf.close failed:
>> java.lang.NullPointerException
>>
>>
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam
>> protection around
>> http://mail.yahoo.com
>>
>>
>>
> -------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc. Do
>> you grep through log files
>> for problems? Stop! Download the new AJAX search
>> engine that makes
>> searching your log files as easy as surfing the
>> web. DOWNLOAD SPLUNK!
>>
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
>> _______________________________________________
>> iText-questions mailing list
>> [email protected]
>>
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
--
Michael Griffith
Managing Partner, OpenPrinciple Consulting, LLC.
http://www.openprinciple.com
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions