Let me paste the method I am using to create the pdf.  I obtain the
signatureString from the database and it contains the text of the
letter.  There's no special formatting, just straight text.  Here's the
method:

  public void doPrint(OutputStream bos) {
    String printString = signatureText;
    Font font = FontFactory.getFont(FontFactory.HELVETICA, 10);

    Document document = new Document(PageSize.LETTER, 60, 80, 157,
90);

    try {
      PdfWriter.getInstance(document, bos);

      document.open();

      int i;
      int lineLen;

      String line;
      Phrase ph = new Phrase();

      ph.setLeading(12f);

      BufferedReader in = new BufferedReader(new
StringReader(printString));

      while ((line = in.readLine()) != null) {
        line = line.trim();
        lineLen = line.length();
        i = 0;

        StringBuffer parsedBuf = new StringBuffer();

        while (i < lineLen) {
          // Make sure there is enough room for the
DELIMITER+SKIPMARKER+(DELIMITER or New Line)
          if ((i < lineLen - 2) &&
              (line.charAt(i) == Parser.DELIMITER &&
              line.charAt(i + 1) == Parser.SKIP_MARKER)) {
            i += 2;

            // Advance past the DELIMITER and SKIPMARKER

            StringBuffer attribute = new StringBuffer();

            while (i < lineLen) {
              // Break at next DELIMITER or New Line
              if ((line.charAt(i) == Parser.DELIMITER) ||
                  (line.charAt(i) == '\n')) {
                System.out.println("Found Attribute: " +
attribute.toString());
                break;
              }
              attribute.append(line.charAt(i));
              i++;
            }
            // Try to take action on the attribute
            if (attribute.toString().compareTo("SignatureImage") == 0)
{
              try {
                Image img = (Image)
signatureImages.get(signatureId.trim());

                if (img == null) {
                  URL imageUrl = new URL("http", host, port,
sigImageDir + signatureId.trim() + sigImageSuffix);

                  img = Image.getInstance(imageUrl);
                  img.scalePercent(10);
                  signatureImages.put(signatureId.trim(), img);
                }
                ph = new Phrase(new Chunk(img, 0, -45));
                ph.setLeading(12f);
                document.add(ph);
                parsedBuf = null;
              }
              catch (FileNotFoundException fnf){
                System.out.println("Image " + signatureId + " not found
in " + sigImageDir);
              }
              catch (Exception e) {
                e.printStackTrace();
                // Add returns to line if image was not inserted
                parsedBuf.append("\n\n\n");
              }
            }
            else if (attribute.toString().compareTo("SignatureName") ==
0) {
              parsedBuf.append(signatureName);
            }
            else if
(attribute.toString().compareTo("SignatureInitials") == 0) {
              parsedBuf.append(signatureInitials);
            }
            else if (attribute.toString().compareTo("PageBreak") == 0)
{
              document.newPage();
            }
            else if (attribute.toString().compareTo("DeskCodeFax") ==
0){
              parsedBuf.append(deskCodeFax);
            }
            else {
              try {
                System.out.println("Found attribute that requires a
method not able to be handled in this class:  " +
attribute.toString());
              }
              catch (Exception ex) {
                ex.printStackTrace();
              }
            }
          }
          else {
            parsedBuf.append(line.charAt(i));
          }
          i++;
        }
        if (parsedBuf != null) {
          line = parsedBuf.toString();
          ph = new Phrase(line + "\n", font);
          ph.setLeading(12f);
          document.add(ph);
        }
        else {
          ph = new Phrase("\n\n\n\n");
          ph.setLeading(12f);
          document.add(ph);
        }
      }
    }
    catch (NullPointerException ne) {
      System.err.println(ne.getMessage());
      System.out.println("NullPointerException occurred in
PDFiText....");
    }
    catch (DocumentException de) {
      System.err.println(de.getMessage());
    }
    catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }

    document.close();
  }

Since I'm using the Document and PdfWriter.getInstance(), in order to
use ColumnText, I'm going to have to redesign the page using:

PdfWriter writer = PdfWriter.getInstance(document, bos);
PdfContentByte cb = writer.getDirectContent();
ColumnText ct = new ColumnText(cb);

Then I'll do everything with cb and ct tho I don't really care about
absolute positioning of the text since I'll add text as I read it in the
position it was last written.  If I have to use this is there a way to
just showText() without setting the alignment or positioning?  If I do
have to supply the positioning, then my guess is top-most left-most part
of the page is (0,0)?  Then I'll have to take in account the margins and
the full text width of a line minus the margin size.  This could get
ugly:-)  I guess what I'm getting at - there is no
Document.getLineNumber()?

Thanks,
Patrick
>>> "Paulo Soares" <[EMAIL PROTECTED]> 12/10/2004 10:44:44 AM >>>
You must use ColumnText for that kind of control. 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Patrick DeZenzio
> Sent: Friday, December 10, 2004 4:27 PM
> To: [EMAIL PROTECTED] 
> Subject: [iText-questions] How do I determine where I am in 
> the document?
> 
> Hello all,
> 
> I have a question about how to determine where I am at on the page. 
> All of my letters I create using iText are either one or two 
> pages.  The
> one letter that is 2 pages has it clearly defined in the text I use
to
> create the PDF document.  I use embedded attribute tags that 
> tells me to
> go out and grab data (name, address, phone, etc.) and I 
> created special
> tags like #BREAK# where I use the newPage() method.  
> 
> The problem is I now have a letter that is dynamic enough 
> that it could
> go to the next page.  iText handles this quite well but I need to be
> able to keep track of where I am on the page, so that if I 
> get too close
> to the bottom, I want to force my own newPage().  This is 
> important when
> I pull in signatures and it partially prints on both pages;  I would
> rather do the "Sincerely Yours," on the next page with the 
> signature and
> initials.
> 
> How can I do this?
> 
> Thanks,
> Patrick
> 
> *** *** *** *** *** *** *** *** *** ***
>   CONFIDENTIALITY NOTICE  
> This e-mail is intended for the sole use of the individual(s) 
> to whom it is addressed, and may contain information that is 
> privileged, confidential and exempt from disclosure under 
> applicable law.  You are hereby notified that any 
> dissemination, duplication, or distribution of this 
> transmission by someone other than the intended addressee or 
> its designated agent is strictly prohibited.  If you receive 
> this e-mail in error, please notify me immediately by 
> replying to this e-mail.
> *** *** *** *** *** *** *** *** *** ***
> 
> 
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from 
> real users.
> Discover which products truly live up to the hype. Start reading now.

> http://productguide.itmanagersjournal.com/ 
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED] 
> https://lists.sourceforge.net/lists/listinfo/itext-questions 
> 


*** *** *** *** *** *** *** *** *** ***
  CONFIDENTIALITY NOTICE  
This e-mail is intended for the sole use of the individual(s) to whom it is 
addressed, and may contain information that is privileged, confidential and 
exempt from disclosure under applicable law.  You are hereby notified that any 
dissemination, duplication, or distribution of this transmission by someone 
other than the intended addressee or its designated agent is strictly 
prohibited.  If you receive this e-mail in error, please notify me immediately 
by replying to this e-mail.
*** *** *** *** *** *** *** *** *** ***


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to