PdfRectangle is a convenience class for a PdfArray. PdfReactangle is low level and Rectangle is the abstraction for the general user.
> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Jason Millard > Sent: Thursday, March 03, 2005 9:19 PM > To: [email protected] > Subject: [iText-questions] Working createPushButton()! Now > (Pdf)Rectangle confusion.. > > Paulo, > > Thanks for the response! I'm glad you'll be adding improved > button support. > > Since you said it was possible, I started studying your > CheckBox example and I finally got createPushButton() with an > image to work! > > Now I have a question about PdfRectangles/Rectangles. In > principle I understand what their difference should be. > However, at the same time, I'm confused about > PdfFormField.setWidget()'s use of a Rectangle. I would think > it should be a PdfRectangle. My code below works exactly like > I want it to, but I would think the overlayed image should be > slighly off. Also, is there an easier way to get a > PdfName.RECT into a PdfRectangle? > > import java.io.*; > import com.lowagie.text.*; > import com.lowagie.text.pdf.*; > import java.util.ArrayList; > > public class stamped > { > public static void main(String[] args) > { > try > { > // Load template pdf > > PdfReader reader = new PdfReader("template2.pdf"); > > PdfStamper stamp = > new PdfStamper(reader, > new FileOutputStream("final_output.pdf")); > > // Find ButtonPlaceHolder invisible field > > PRAcroForm form = reader.getAcroForm(); > > PdfDictionary an = > (PdfDictionary) reader.getPdfObject( > form.getRefByName( "ButtonPlaceHolder") ); > > PdfArray rect = > (PdfArray) reader.getPdfObject( an.get(PdfName.RECT) ); > > ArrayList arr = rect.getArrayList(); > > PdfRectangle rect2 = > new PdfRectangle( > ((PdfNumber) reader.getPdfObject( > (PdfObject)arr.get(0))).floatValue(), > ((PdfNumber) reader.getPdfObject( > (PdfObject)arr.get(1))).floatValue(), > ((PdfNumber) reader.getPdfObject( > (PdfObject)arr.get(2))).floatValue(), > ((PdfNumber) reader.getPdfObject( > (PdfObject)arr.get(3))).floatValue()); > > PdfWriter writer = stamp.getWriter(); > > PdfContentByte cb = writer.getDirectContent(); > > cb.moveTo(0, 0); > > Image image = > Image.getInstance( "overlayimage.jpg" ); > > PdfFormField field = > PdfFormField.createPushButton( writer ); > > // Make sure button image is only visible when printed > > field.setFlags( PdfAnnotation.FLAGS_PRINT | > PdfAnnotation.FLAGS_NOVIEW ); > > field.setFieldFlags( PdfFormField.FF_READ_ONLY ); > > PdfAppearance appearance = > cb.createAppearance( image.width(), image.height() ); > > appearance.addImage( image, > image.width(), 0, 0, > image.height(), 0, 0 ); > > // Set new button dimensions to > // ButtonPlaceHolder dimensions > > field.setWidget( > new Rectangle( rect2.left(), > rect2.bottom(), > rect2.right(), > rect2.top() ), > PdfAnnotation.HIGHLIGHT_NONE); > > field.setFieldName("OverlayingImage"); > > field.setAppearanceState("flatState"); > > field.setAppearance( > PdfAnnotation.APPEARANCE_NORMAL, > "flatState", appearance ); > > stamp.addAnnotation(field, 1); > > stamp.setFormFlattening( true ); > > stamp.close(); > > System.out.println("Finished."); > } > > catch (Exception de) > { > de.printStackTrace(); > } > } > } > > Thanks, > -- Jason > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from > real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
