Hey, 
New to posting stuff wasn't sure how to reply and need to attached this
image for you to use.  Just place it in the C drive or you can change the
path to wherever you put it.  Not sure if this works I'm not familiar with
creating the pdf files outside of my system.  It compiled and executed just
didn't know where the pdf file is created.  This code inside my system
produced the same errors.  Here is the code as self-contained as I could get
it.  If you need something else or more info let me know.  

Thanks,
Jed Hanes


import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Image;

/**
 * Adding text at an absolute position.
 */
public class Text {
    /**
     * Adding text at absolute positions.
     * @param args no arguments needed
     */
    public static void main(String[] args) {
        
        System.out.println("trying to get this to work");
        
        // step 1: creation of a document-object
        Document document = new Document();
        
        boolean topRecord = true;
        
        try 
        {
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("text.pdf"));
            
            // step 3: we open the document
            document.open();
            
            String url = "C:\\dodseal.jpg";
            Image sealDod = Image.getInstance(url);
            
            // step 4: we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();

            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            
            for (int i=0; i < 9; i++)
            {
                String fname = "First Name " +i;
                String lname = "Last Name " +i;
                String service = "USAF " +i;
                String borderTop =
"______________________________________________________";
                String borderBottom = "YOYO D. SMITH COLLEGE FOR
PROFESSIONAL DEVELOPMENT";
                
                cb.beginText();
                
                if(topRecord == true)
                    {
                        sealDod.setAbsolutePosition(25, 350);
                        sealDod.scaleAbsolute(200, 200);
                        writer.add(sealDod);
                        cb.setFontAndSize(bf, 24);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
fname, 500, 425, 0);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
lname, 500, 375, 0);
                        cb.showTextAligned(PdfContentByte.ALIGN_LEFT,
service, 25, 350, 0);
                        cb.setFontAndSize(bf, 18);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
borderTop, 475, 350, 0);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
borderBottom, 475, 325, 0);
                        topRecord = false;
                    }
                else
                    {
                        sealDod.setAbsolutePosition(25, 50);
                        sealDod.scaleAbsolute(200, 200);
                        writer.add(sealDod);
                        cb.setFontAndSize(bf, 24);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
fname, 500, 125, 0);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
lname, 500, 75, 0);
                        cb.showTextAligned(PdfContentByte.ALIGN_LEFT,
service, 25, 50, 0);
                        cb.setFontAndSize(bf, 18);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
borderTop, 475, 50, 0);
                        cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
borderBottom, 475, 25, 0);
                        topRecord = true;
                    }
                cb.endText();
                
                //Every 2 records create a new page
                if(i % 2 == 1)
                {
                    //Then create new page with a newPage method in our util
file
                    document.newPage();

                }
            }
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        
        // step 5: we close the document
        document.close();
    }
}




-----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 27, 2005 4:44 PM
To: Hanes Jedidiah A1C AU/SCIE; itext-questions@lists.sourceforge.net
Subject: Re: [iText-questions] Help with PdfContentByte

I don't see anything wrong. Post self contained code that reproduces the
error.

----- Original Message ----- 
From: "Hanes Jedidiah A1C AU/SCIE" <[EMAIL PROTECTED]>
To: <itext-questions@lists.sourceforge.net>
Sent: Monday, June 27, 2005 9:16 PM
Subject: [iText-questions] Help with PdfContentByte


> Please help.
>
> I'm using PdfContentByte to position text (which are variables filled from
a
> list) on my screen.  They are basically name plates with two per page.
> Problem is only the last page is showing up ... its like the contentbyte
is
> overwritten...  how do i stop this from happening.  If I take away the new
> page command the loop works fine, just writes on top of itself on one
page.
> When I have the new page in there it does crazy stuff... like blank pages
> and even one page that is set at zoom 4444% or something.


<<attachment: dodseal.jpg>>

Reply via email to