Hi,

I'm trying to write a text over images to create a kind of title bar.
I though I fond a way but this is only working on the first page.
On the subsequent page, the images and text are messed up (shifted down)
once I add a paragraph between the title bars.
With no text, there's no shift at all ....

Here is my java code :
package personnal.blogprinter;

[truncated imports ...]

public class PdfTest {

        private static final int DEFAULT_MARGIN = 50;

        private static final String TITLE_RIGHT_CORNER = 
"title-right-corner.gif";

        private static final String TITLE_BACKGROUND = "title-background.gif";

        private static final String TITLE_LEFT_CORNER = "title-left-corner.gif";

        private static final Font POST_TITLE_FONT = new Font(Font.HELVETICA, 
17, Font.BOLD, Color.WHITE);

        @Test
        public void testCreatePdf() throws GenerationException {
                File outputFile = new File("target", "test.pdf");
                Document document = new Document(PageSize.A4, DEFAULT_MARGIN, 
DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN);
                try {
                        PdfWriter.getInstance(document, new 
FileOutputStream(outputFile));
                        document.open();
                        addTitle("My incredible title", document);
                        // Uncomment here to create the shift
                        //document.add(new Paragraph("Test"));
                        document.newPage();
                        addTitle("My other incredible title", document);
                } catch (IOException e) {
                        throw new GenerationException("Can't add image", e);
                } catch (DocumentException e) {
                        throw new GenerationException("Can't add title", e);
                } finally {
                        document.close();
                }
        }

        private void addTitle(String title, Document document)
                        throws BadElementException, IOException, 
DocumentException {
                Image cornerImg = getImage(TITLE_LEFT_CORNER);
                document.add(new Chunk(cornerImg, 0, -5));
                
                Image bgImg = getImage(TITLE_BACKGROUND);
                bgImg.scaleAbsoluteWidth(475);
                document.add(new Chunk(Image.getInstance(bgImg), 0, -5));

                Image flipedCornerImg = getImage(TITLE_RIGHT_CORNER);
                document.add(new Chunk(flipedCornerImg, 0, -5));
                
                Chunk titleChunk = new Chunk("     "+title, POST_TITLE_FONT);
                document.add(titleChunk);
                document.add(Chunk.NEWLINE);
        }

        protected Image getImage(String imageFilename) throws 
BadElementException, IOException {
                URL cornerImgUrl = 
Thread.currentThread().getContextClassLoader()
                        .getResource(imageFilename);
                return Image.getInstance(cornerImgUrl);
        }

}

I've also attached 2 resulting pdf file : one with no shift (but no text) and 
the other with text and shift ...
I don't understand what's going on ....

Regards,
Manuel

 <<test-bad.pdf>>  <<test-good.pdf>> 

Attachment: test-bad.pdf
Description: test-bad.pdf

Attachment: test-good.pdf
Description: test-good.pdf

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to