Mixing Document.add() and PdfContentByte can result in serious risks to
your health. Use the latest version and PdfWriter.getVerticalPosition().
It's safer but it still can fail.

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Jim Owen
> Sent: Wednesday, November 17, 2004 10:49 PM
> To: [EMAIL PROTECTED]
> Subject: [iText-questions] Help on graphics/text placement
> 
> Hi,
> 
>       I've run into a problem where I'm getting an extra page in a
> generated PDF file that contains images that I expected to be 
> placed on the
> prior page.  In other words, I output a bunch of text, then 
> place graphics
> on the page with a PdfContentByte. I'm ending up with the 
> text on one page
> and the graphics following on the next.
> 
>       It's probably something pretty simple, but I've bashed 
> on it long
> enough.
> 
> Here's the code with a lot of pseudo-code for simplicity:
> 
>       Any help would be appreciated.
> 
>       Regards,
> 
>       Jim
> 
> // Get an input file reader - just a text file
> BufferedReader in = new BufferedReader(new FileReader( 
> inputFilename ));
> PdfWriter writer = null;
> 
> // Get the first line and start processing
> String inputLine = in.readLine();
> while ( inputLine != null )
> {
>       // Check if we are starting a new statement from the file.  
>      // Find out if this line is an placeholder for a new 
> statement. Get
> // output file name from the line.
>       // If starting a new statement, then need to finalize the prior
> 
>       // statement.
>       If ( newStatement )
>       {
>       // Place images on page since we just finished some other
>               // statement. With special handing for  first 
> page.  But 
>               // want to do this before next page so images are 
>               // placed on the correct page.
>           PdfContentByte cb = writer.getDirectContent();
>            // Get the image
>            buffImage = (BufferedImage)eImages.nextElement();
>            // Now get a document image
>            Image image = Image.getInstance(buffImage, null);
>            // Calculate a value for x and y and set it in the image.
>            image.setAbsolutePosition(xPos, yPos );
>            // Add the image to the output.
>                cb.addImage(image);
>            // Null the reference
>            cb = null;
>            // close the document now
>            document.close();
>        }
>        // Now Start a new document
>        document = new Document(PageSize.LETTER );
>        // Open the output writer
>        writer = PdfWriter.getInstance(document, new FileOutputStream(
> pdfFile ));
>        // Set some preferences
>        // Open the document
>        document.open();
> 
>        // Init some values
>        currLine = 0;
>    }
>    // Check if we have a signature position
>    // If we have one, then store the image into the vector or later
> processing
> 
>       // Now output the line to the document.
>      inputLine += "\n";
>      Phrase p = new Phrase( inputLine,
> FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, new 
> Color(0, 0,
> 0)));
>       // Add the phrase to the document.
>      document.add( p );
> 
>      // Now check if we are at the end of a page in the statement
>      //  We'll need to output the images, if so.
>       // Do all the same stuff here as when we start a new statement
> except call newPage();
>       document.newPage();
> 
>      // Read the next line.
>      inputLine = in.readLine();
>  }
> 
>  // Close up stuff
>  in.close();
>  in = null;
> 
>  // See if there is anything to output on the final page and 
> output it if
> so.
>  // Close the document.
>  document.close();
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: InterSystems CACHE
> FREE OODBMS DOWNLOAD - A multidimensional database that combines
> robust object and relational technologies, making it a perfect match
> for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 


-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to