Hi Allan, I'm not sure whether the getWidth() method was already available in version 2.0.6. You can try to download the latest version 2.1.3, it should work. Or if you cannot upgrade your iText lib, try the getLeft() and getRight() methods of the Rectangle class. You can get the width by saying float width = Math.abs(rectangle.getRight() - rectangle.getLeft()).
hth, Ellen N. Zhao Udkik.dk schrieb: > Hi community, > > I need your help. > I have an exception error regarding "Rectangle.getWidth()", I cannot > solve myself. > The exception, and the Java source is listed below. > iText version: 2.0.6 > java.vm.version: 1.4.2_09-b05 > Apache Tomcat/5.0.30 > If you need other systems values, please look here: > http://www.yachtdatabase.com/app/sysmonitor.jsp > > Exception: > HTTP Status 500 - > type Exception report > message > description The server encountered an internal error () that prevented > it from fulfilling this request. > exception > javax.servlet.ServletException: Invoker service() exception > > org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:477) > > org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133) > javax.servlet.http.HttpServlet.service(HttpServlet.java:689) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > root cause > java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.getWidth()F > adnote66$myPageEvent.onEndPage(adnote66.java:47) > com.lowagie.text.pdf.PdfDocument.newPage(PdfDocument.java:830) > com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:788) > com.lowagie.text.Document.close(Unknown Source) > adnote66.doGet(adnote66.java:78) > javax.servlet.http.HttpServlet.service(HttpServlet.java:689) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > > org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419) > > org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133) > javax.servlet.http.HttpServlet.service(HttpServlet.java:689) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > > > Java source (servlet): > import java.io.*; > import java.util.*; > import java.text.*; > import java.awt.*; > > import javax.servlet.*; > import javax.servlet.http.*; > > import com.lowagie.text.Chunk; > import com.lowagie.text.Document; > import com.lowagie.text.DocumentException; > import com.lowagie.text.Element; > import com.lowagie.text.ExceptionConverter; > import com.lowagie.text.Font; > import com.lowagie.text.FontFactory; > import com.lowagie.text.Image; > import com.lowagie.text.PageSize; > import com.lowagie.text.Paragraph; > import com.lowagie.text.Rectangle; > import com.lowagie.text.pdf.PdfContentByte; > import com.lowagie.text.pdf.PdfPageEventHelper; > import com.lowagie.text.pdf.PdfPCell; > import com.lowagie.text.pdf.PdfPTable; > import com.lowagie.text.pdf.PdfWriter; > > public class adnote66 extends HttpServlet { > > public void init(ServletConfig config) > throws ServletException { > super.init(config); > } > > public class myPageEvent extends PdfPageEventHelper { > > public void onEndPage(PdfWriter writer, Document document) { > try { > Rectangle page = document.getPageSize(); > PdfPTable foot = new PdfPTable(2); > foot.addCell("left"); > foot.addCell("right"); > foot.setTotalWidth(page.getWidth() - document.leftMargin() - > document.rightMargin()); > foot.writeSelectedRows(0, -1, document.leftMargin(), > document.bottomMargin(), writer.getDirectContent()); > } > catch (Exception e) { > throw new ExceptionConverter(e); > } > } > } > /** > * Returns a PDF document. > * > */ > public void doGet (HttpServletRequest request, HttpServletResponse > response) > throws IOException, ServletException { > > Document.compress = false; > Document document = new Document(); > try { > response.setContentType("application/pdf"); > PdfWriter writer = PdfWriter.getInstance(document, > response.getOutputStream()); > writer.setPageEvent(new myPageEvent()); > document.open(); > document.add(new Paragraph("hello world")); > } > catch(DocumentException de) { > throw new ExceptionConverter(de); > } > catch(IOException ioe) { > throw new ExceptionConverter(ioe); > } > > document.close(); > } > } > > Thanks, > Allan Unnerup > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > 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 > > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ 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