Hi to all, 

 

I've just downloaded iText 5.1 and I try to set a watermark on a PDF file
created with  Scanner. 

It's size is 3772 KB and contains 3 pages.

When I try to close watermarked file I get this error:  Can somebody tell me
the reason?

Thanks

Eug

  _____  

java.io.EOFException

      at
com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrAr
ray.java:261)

      at
com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrAr
ray.java:253)

      at
com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2344)

      at
com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2381)

      at com.itextpdf.text.pdf.PRStream.toPdf(PRStream.java:215)

      at
com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)

      at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:396)

      at com.itextpdf.text.pdf.PdfWriter.addToBody(PdfWriter.java:847)

      at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:304)

      at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:189)

      at
test.itext.ProvaWatermark.aggiungiNonConforme(ProvaWatermark.java:45)

  _____  

My JUnit test is the following:

  _____  

package test.itext;

 

import java.io.FileOutputStream;

import java.io.IOException;

 

import org.junit.Test;

 

import com.itextpdf.text.DocumentException;

import com.itextpdf.text.Image;

import com.itextpdf.text.pdf.PdfContentByte;

import com.itextpdf.text.pdf.PdfReader;

import com.itextpdf.text.pdf.PdfStamper;

 

public class ProvaWatermark {

 

  @Test

  public void prova() throws IOException, DocumentException {

    String szIn = "C:/temp/pippo.pdf";

    String szOut = "C:/temp/pippoOut.pdf";

    aggiungiNonConforme(szIn, szOut);

 

  }

 

  private void aggiungiNonConforme(String nome, String nomeOut) throws
IOException, DocumentException {

    PdfReader reader = null;

    PdfStamper stamper = null;

    reader = new PdfReader(nome);

    int number_of_pages = reader.getNumberOfPages(); 

    stamper = new PdfStamper(reader, new FileOutputStream(nomeOut));

    Image img = Image.getInstance("C:/temp/NonConforme.gif");

    PdfContentByte under;

    img.setAbsolutePosition(0, 20); 

 

    for (int i = 1; i <= number_of_pages; i++) {

      under = stamper.getUnderContent(i); 

      under.addImage(img); 

    }

    stamper.close();

  }

}

 

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to