Discussion:
[iText-questions] Fw: java.lang.UnsupportedOperationException:
selvi
2006-09-13 06:44:37 UTC
Permalink
Hi,


when i execute the code listed .l iam getting below listed error.

ERROR:

C:\jerry>java ImageLink
java.lang.UnsupportedOperationException: Use PdfStamper.getUnderContent() or PdfStamper.getOverContent()
at com.lowagie.text.pdf.PdfStamperImp.getDirectContent(PdfStamperImp.java:1365)
at ImageLink.main(ImageLink.java:36)


code:


import java.io.FileOutputStream;

import java.util.HashMap;

import com.lowagie.text.Element;

import com.lowagie.text.Image;

import com.lowagie.text.PageSize;

import com.lowagie.text.Rectangle;

import com.lowagie.text.pdf.BaseFont;

import com.lowagie.text.pdf.PdfAnnotation;

import com.lowagie.text.pdf.PdfAppearance;

import com.lowagie.text.pdf.PdfContentByte;

import com.lowagie.text.pdf.PdfFileSpecification;

import com.lowagie.text.pdf.PdfReader;

import com.lowagie.text.pdf.PdfStamper;

/**

* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.

*/

public class ImageLink {


public static void main(String[] args) {

try {

// we create a reader for a certain document

PdfReader reader = new PdfReader("page81.pdf");

int n = reader.getNumberOfPages();

// we create a stamper that will copy the document to a new file

PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("page81_new.pdf"));

// adding some metadata

HashMap moreInfo = new HashMap();

moreInfo.put("Author", "Sundar");

stamp.setMoreInfo(moreInfo);

// adding content to each page

int i = 1;

// while (i < n) {

///i++;

PdfContentByte cb = stamp.getWriter().getDirectContent();

cb.rectangle(250/*left*/, 250/*top*/,250/*right*/, 250/*bottom*/);

cb.stroke();


Rectangle rect = new Rectangle(100/*left*/, 0/*top*/,350/*right*/, 350/*bottom*/);

PdfFileSpecification pf = PdfFileSpecification.fileEmbedded(stamp.getWriter(),"attached image.JPG", "attached image.JPG", null);

PdfAnnotation annot = PdfAnnotation.createFileAttachment(stamp.getWriter(), rect,"attached image.JPG", pf);



PdfAppearance ap = cb.createAppearance(300, 300);

ap.setBoundingBox(rect);

ap.setLineWidth(1);

annot.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);

annot.setAppearance(PdfAnnotation.APPEARANCE_DOWN, ap);

annot.setPage();

stamp.addAnnotation(annot, i);

//}

stamp.close();

}

catch (Exception de) {

de.printStackTrace();

}

}

}
Paulo Soares
2006-09-13 10:57:07 UTC
Permalink
Did you read the exception text? Did you look at the tutorial examples
on PdfStamper?

Paulo
-----Original Message-----
Behalf Of selvi
Sent: Wednesday, September 13, 2006 7:45 AM
To: itext
Hi,
when i execute the code listed .l iam getting below listed error.
C:\jerry>java ImageLink
java.lang.UnsupportedOperationException: Use
PdfStamper.getUnderContent() or PdfStamper.getOverContent()
at
com.lowagie.text.pdf.PdfStamperImp.getDirectContent(PdfStamper
Imp.java:1365)
at ImageLink.main(ImageLink.java:36)
import java.io.FileOutputStream;
import java.util.HashMap;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfAppearance;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFileSpecification;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
/**
* Reads the pages of an existing PDF file, adds pagenumbers
and a watermark.
*/
public class ImageLink {
public static void main(String[] args) {
try {
// we create a reader for a certain document
PdfReader reader = new PdfReader("page81.pdf");
int n = reader.getNumberOfPages();
// we create a stamper that will copy the document to a new file
PdfStamper stamp = new PdfStamper(reader, new
FileOutputStream("page81_new.pdf"));
// adding some metadata
HashMap moreInfo = new HashMap();
moreInfo.put("Author", "Sundar");
stamp.setMoreInfo(moreInfo);
// adding content to each page
int i = 1;
// while (i < n) {
///i++;
PdfContentByte cb = stamp.getWriter().getDirectContent();
cb.rectangle(250/*left*/, 250/*top*/,250/*right*/, 250/*bottom*/);
cb.stroke();
Rectangle rect = new Rectangle(100/*left*/,
0/*top*/,350/*right*/, 350/*bottom*/);
PdfFileSpecification pf =
PdfFileSpecification.fileEmbedded(stamp.getWriter(),"attached
image.JPG", "attached image.JPG", null);
PdfAnnotation annot =
PdfAnnotation.createFileAttachment(stamp.getWriter(),
rect,"attached image.JPG", pf);
PdfAppearance ap = cb.createAppearance(300, 300);
ap.setBoundingBox(rect);
ap.setLineWidth(1);
annot.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
annot.setAppearance(PdfAnnotation.APPEARANCE_DOWN, ap);
annot.setPage();
stamp.addAnnotation(annot, i);
//}
stamp.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
Aviso Legal:
Esta mensagem � destinada exclusivamente ao destinat�rio. Pode conter informa��o confidencial ou legalmente protegida. A incorrecta transmiss�o desta mensagem n�o significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. � proibido a qualquer pessoa que n�o o destinat�rio de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.
Loading...