Here's a bit of code. Modify it to fit your needs.

Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream("c:\\embimage.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.setColorStroke(Color.red);
cb.rectangle(200, 400, 100, 100);
cb.stroke();
document.add(new Paragraph("Images"));
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, 
"saitoz-n.mpeg",   "saitoz-n.mpeg", null);
PdfAnnotation annot = PdfAnnotation.createScreen(writer, new  Rectangle(200f, 
400f, 300f,  500f), "saitoz-n.mpeg",fs,"video/mpeg",false);
writer.addAnnotation(annot);

Image img = Image.getInstance("d:/PX100.jpg");
PushbuttonField bt = new PushbuttonField(writer, new Rectangle(100, 680, 150, 
710), "Button1");
bt.setImage(img);
bt.setLayout(PushbuttonField.LAYOUT_ICON_TOP_LABEL_BOTTOM);
bt.setBackgroundColor(Color.white);
bt.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
bt.setBorderColor(Color.black);
bt.setBorderWidth(1);
PdfFormField ff = bt.getField() ;
ff.put(PdfName.A, ann.get(PdfName.A);            
writer.addAnnotation(ff); 

document.close();
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Jérome Vérité
> Sent: Wednesday, October 26, 2005 1:30 PM
> To: [email protected]
> Subject: [iText-questions] PdfAction with PushbuttonField 
> doesn't want to work
> 
> Hi,
> 
> I try to add a rendition PdfAction to a PushbuttonField. The 
> execution of my java program do it. But when I click the 
> button in the Pdf File, I get the message
> 
> "Impossible d'effectuer l'action. Le fichier est incorrect ou 
> requiert une version plus récente d'Acrobat." for which the 
> translation is approximately "Impossible to manage the 
> action. The file is incorrect or it needs a more recent 
> version of Acrobat".
> 
> But if I use a simple Annotation, it works. Could you explain 
> me why please ?
> 
> The sample code I used follows
> 
>             PdfContentByte cb2 = writer2.getDirectContent();
>             Annotation a15 = new Annotation(100f, 580f, 150f, 
> 600f, "d:/chanson.mp3", "audio/mpeg", false);   
>             document2.add(a15);
>                        
>             PdfFileSpecification fs = 
> PdfFileSpecification.fileEmbedded(writer2, "d:/chanson.mp3", 
> "chanson", null);
>             Image img = Image.getInstance("d:/PX100.jpg");
>             PushbuttonField bt = new PushbuttonField(writer2, 
> new Rectangle(100, 680, 150, 710), "Button1");
>             bt.setImage(img);
>             
> bt.setLayout(PushbuttonField.LAYOUT_ICON_TOP_LABEL_BOTTOM);
>             bt.setBackgroundColor(Color.white);
>             bt.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
>             bt.setBorderColor(Color.black);
>             bt.setBorderWidth(1);
>             PdfFormField ff = bt.getField() ;
>             
>             PdfAction ac = 
> PdfAction.rendition("chanson",fs,"audio/mpeg",writer2.getPdfIn
> directReference()) ;
>             ff.setAction(ac);
>             writer2.addAnnotation(ff); 
> 
> Thanks a lot.
> 
> Excuse me for my poor english
> 
> Jérôme
> 
> 


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to