I am generating a pdf form a jsp page. If I use the same code in a
standard java class it works. If I run it from a jsp page but write it
to a file it works. However, if I attempt to return it to the browser
directly its blank, though it has the same file size, same title,
subject, author, and pages as it should. When I save this PDF and
compare it to the one that works, I see that the faulty one has a bunch
of question marks where the correct one shows black graphic blocks.

Anyone have any suggestions? Below is my JSP code.

<%@ page language="java"  contentType="application/pdf" %><%@ page
import="com.lowagie.text.*,
com.lowagie.text.pdf.PdfWriter,java.io.*,java.net.*"%><%@ page
import="com.lowagie.text.pdf.BaseFont,
com.lowagie.text.pdf.PdfContentByte, com.lowagie.text.pdf.PdfTemplate,
com.lowagie.text.pdf.PdfWriter"%><%
        Document document = new Document();
        ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
        PdfWriter docWriter = PdfWriter.getInstance(document, baosPDF);
        try {
                        document.open();
                            // step 4:
            PdfContentByte cb = docWriter.getDirectContent();
            
            // we create a PdfTemplate
            PdfTemplate template = cb.createTemplate(25, 25);
            
            // we add some crosses to visualize the coordinates
            template.moveTo(13, 0);
            template.lineTo(13, 25);
            template.moveTo(0, 13);
            template.lineTo(50, 13);
            template.stroke();
            
            // we add the template on different positions
            cb.addTemplate(template, 216 - 13, 720 - 13);
            cb.addTemplate(template, 360 - 13, 360 - 13);
            cb.addTemplate(template, 360 - 13, 504 - 13);
            cb.addTemplate(template, 72 - 13, 144 - 13);
            cb.addTemplate(template, 144 - 13, 288 - 13);

            cb.moveTo(216, 720);
            cb.lineTo(360, 360);
            cb.lineTo(360, 504);
            cb.lineTo(72, 144);
            cb.lineTo(144, 288);
            cb.stroke();
        } catch (Exception e) {
                System.err.println(e.getMessage());
        }

        // step 5: we close the document
        document.close();
        baosPDF.flush();
        byte[] bytes = baosPDF.toByteArray();
        int contentLength =bytes.length;
        response.setContentLength(contentLength);
        //System.out.println("Size is " + bytes.length);
        for(int i = 0; i < contentLength-2; i++)
        {
           out.write(bytes[i]);
        }
%>

Brian



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to