I'm having a bit of a problem with generating a pdf.

The create method seems to create a blank page, but nothing else - no text, no lines, 
nothing...

If I get a PdfWriter with a FileOutputStream, then everything is what I am expecting 
it to be. However, if I pass in a ByteArrayOutputStream, all I get is blank pages. Any 
idea on what I'm doing wrong?

The code goes something like this:


public class MainClass
{
        public void someMethod()
        {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                GenPdf.create(baos);
        }
}


public class GenPdf
{
        public static void create(OutputStream os)
        {
                try
                {
                        Document document = new Document(PageSize.LETTER, 25, 25, 25, 
25);
                        PdfWriter writer = PdfWriter.getInstance(document, os);
                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        document.newPage();

                        BaseFont bf = BaseFont.createFont(BaseFont.COURIER, 
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                        cb.setFontAndSize(bf, 11);
                        cb.beginText();
                        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "***********", 
123, 123, 0);
                        cb.endText();
                        
                        cb.setLineWidth(0.5f);
                        cb.moveTo(306f, 714f);
                        cb.lineTo(306f, 399f);
                        cb.stroke();

                        document.close();
                }
                catch (DocumentException de)
                {
                        de.printStackTrace();
                }
                catch (IOException ioe)
                {
                        ioe.printStackTrace();
                }
        }
}

Thanks,
AB
-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to