#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    125
    Rep Power
    9

    Exclamation IText PDF template help


    Hey all, was just wondering if anyone would be able to help me out.

    I'm currently creating a pdf document using the iText classes. All has gone fine but now I'm trying to export using a template document.

    All I want the template document to be used for is a background image. So every page that is in the new document to contain the background. I have sort of got this working but I'm having a couple problems.

    1. The template appears over the added content/text? I add the template first and then the content so not sure what happening there.

    2. It only appears on the first page. I'm not sure how to make it appear on all the pages?

    Heres what I'm doing
    Code:
    FileOutputStream outputStream = new FileOutputStream("file.pdf");
    
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);
    document.open();
    
    PdfReader reader = new PdfReader("template.pdf");
    
    PdfImportedPage page = writer.getImportedPage(reader, 1);
    
    PdfContentByte cb = writer.getDirectContent();
    cb.addTemplate(page, 0, 0);
    
    document.add(new Paragraph("Test Text");
    
    documnet.close();
    Any idea?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    125
    Rep Power
    9
    Does anyone know how to use iText to add an image to the background off all pages within a pdf. Can't really find a solution anywhere.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    125
    Rep Power
    9
    Originally Posted by doush.
    Does anyone know how to use iText to add an image to the background off all pages within a pdf. Can't really find a solution anywhere.
    All good people, I've got it working. For those wondering, I justed used a water mark. Just add it before you call document.open() and it will add to all pages

    headache gone now
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Getting the content in the background


    To get the content to appear below the text (as a background image) use writer.getDirectContentUnder()

    See this page for more information ( http :// stderr . org/doc/libitext-java-doc/www/tutorial/ch10.html

    I don't know how to repeat on every page yet.

IMN logo majestic logo threadwatch logo seochat tools logo