Underline and strike-through in a cell

This is a code example of iText PDF, discover more.

11th October 2015
admin-marketing

Switch code for this example

SimpleTable6.java
  1. /**
  2.  * Example written by Bruno Lowagie in answer to the following question:
  3.  * http://stackoverflow.com/questions/28617095/strikethrough-in-cell-using-itext-in-android-java
  4.  */
  5. package sandbox.tables;
  6.  
  7. import com.itextpdf.text.Chunk;
  8. import com.itextpdf.text.Document;
  9. import com.itextpdf.text.DocumentException;
  10. import com.itextpdf.text.Font;
  11. import com.itextpdf.text.Font.FontFamily;
  12. import com.itextpdf.text.Phrase;
  13. import com.itextpdf.text.pdf.PdfPTable;
  14. import com.itextpdf.text.pdf.PdfWriter;
  15.  
  16. import java.io.File;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import sandbox.WrapToTest;
  20.  
  21. @WrapToTest
  22. public class SimpleTable6 {
  23.     public static final String DEST = "results/tables/simple_table6.pdf";
  24.  
  25.     public static void main(String[] args) throws IOException,
  26.             DocumentException {
  27.         File file = new File(DEST);
  28.         file.getParentFile().mkdirs();
  29.         new SimpleTable6().createPdf(DEST);
  30.     }
  31.     public void createPdf(String dest) throws IOException, DocumentException {
  32.         Document document = new Document();
  33.         PdfWriter.getInstance(document, new FileOutputStream(dest));
  34.         document.open();
  35.         PdfPTable table = new PdfPTable(2);
  36.         table.addCell(new Phrase("0123456789"));
  37.         Font font = new Font(FontFamily.HELVETICA, 12f, Font.STRIKETHRU);
  38.         table.addCell(new Phrase("0123456789", font));
  39.         Chunk chunk1 = new Chunk("0123456789");
  40.         chunk1.setUnderline(1.5f, -1);
  41.         table.addCell(new Phrase(chunk1));
  42.         Chunk chunk2 = new Chunk("0123456789");
  43.         chunk2.setUnderline(1.5f, 3.5f);
  44.         table.addCell(new Phrase(chunk2));
  45.         document.add(table);
  46.         document.close();
  47.     }
  48.  
  49. }
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now