Hello, I am creating a pushbutton inside a PdfpCell and trying to put an image on it. The image is not appearing on the button. Please help!!
Below is the code i am using and attached is the image I am trying to add as well as the a sample resultant PDF. iText version 2.1.4. Thanks, Subhro. public static void pushButtonTest(){ Document appendDoc; try { File tempAppendFile=File.createTempFile("TMPPDFGEN", ".PDF"); appendDoc = new Document(new Rectangle(PageSize.A4.getWidth(),PageSize.A4.getHeight()/4)); final PdfWriter writer=PdfWriter.getInstance(appendDoc, new FileOutputStream(tempAppendFile)); appendDoc.open(); appendDoc.newPage(); PdfPTable mainTable=new PdfPTable(1); PdfPCell agreeToSignCell=new PdfPCell(); //agreeToSignCell.disableBorderSide(Rectangle.BOTTOM|Rectangle.TOP|Rectangle.LEFT|Rectangle.RIGHT); agreeToSignCell.setCellEvent(new PdfPCellEvent(){ public void cellLayout(PdfPCell cell, Rectangle position,PdfContentByte[] cbArray) { try { Image agreeToSignImg=Image.getInstance(PDFModifierTest.class.getResource("agreeToSignButton.png")); Rectangle submitButtonRect=new Rectangle(position.getLeft(),position.getBottom(),position.getLeft()+agreeToSignImg.getWidth(),position.getBottom()+agreeToSignImg.getHeight()); PushbuttonField button = new PushbuttonField(writer, submitButtonRect, "submit"); button.setText("Submit Data"); button.setIconFitToBounds(true); button.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); button.setBorderColor(Color.BLUE); button.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); * button.setImage(agreeToSignImg);* PdfFormField submit = button.getField(); int typeInt=PdfAction.SUBMIT_CANONICAL_FORMAT;//.SUBMIT_HTML_FORMAT;// .SUBMIT_CANONICAL_FORMAT; submit.setAction(PdfAction.createSubmitForm(" http://www.google.com", null, typeInt)); writer.addAnnotation(submit); /*PdfContentByte baseCanvas=cbArray[PdfPTable.BACKGROUNDCANVAS]; baseCanvas.addImage(agreeToSignImg);*/ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); //agreeToSignCell.addElement(agreeToSignImg); //agreeToSignCell.addElement(agreeToSignImg); mainTable.addCell(agreeToSignCell); mainTable.setTotalWidth(appendDoc.right()-appendDoc.rightMargin()); mainTable.writeSelectedRows(-1, -1, appendDoc.left(), appendDoc.top(), writer.getDirectContent()); appendDoc.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } //appendDoc.add(mainTable); }
<<attachment: agreeToSignButton.png>>
TMPPDFGEN5904215543487654417.PDF
Description: Adobe PDF document
------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net 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/