Strikethrough Text In Pdf in java


In this core java tutorial we will learn How To Strikethrough Text In Pdf in java using iText library - core java tutorial with program and examples.


Follow these steps to Strikethrough Text In Pdf in java using iText library >

  • Create new Chunk (Chunk textStrikethrough = new Chunk("Strikethrough Text"));
  • textStrikethrough.setUnderline(0.8f, 2.5f);
Where, 0.8f is the thickness of Strikethrough and 2.5f is the position of y axis, i.e. where Strikethrough will be drawn.
     


How to Set the Font Name, Size, Style and Colour In Pdf using itext in java

How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial

Convert Html To Pdf in java using iText - iText java tutorial

How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial



Download jars required to execute program >

Or, you may download jars from here.

Program/Example How To Strikethrough Text In Pdf in java - Using iText library

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
*  How To Strikethrough Text In Pdf Using Itext Example -
*  Using iText library - core java tutorial
*
*/
public class StrikethroughInPdfUsingItextExample {
public static void main(String[] args) throws Exception {
     String pdfFilePath = "e:/Strikethrough Text in Pdf Using Itext Example.pdf";
     OutputStream fos = new FileOutputStream(new File(pdfFilePath));
     Document document = new Document();
     PdfWriter.getInstance(document, fos);
     document.open();
     document.add(new Paragraph("This is Strikethrough Text in Pdf Example"));
     Chunk textStrikethrough = new Chunk("Strikethrough Text");
     textStrikethrough.setUnderline(0.8f, 2.5f); // 0.8f is the thickness of Strikethrough
             //and 2.5f is the position of y axis, i.e. where Strikethrough will be drawn.
             //Just for information
             //If you use -1f then it form underline text, try it.
          //If you use 10f then it form line above text, try this one too..
             
     document.add(textStrikethrough);
     document.close();
     fos.close();
     System.out.println("PDF created in >> " + pdfFilePath);
}
}
/* OUTPUT of above program/Example -
PDF created in >> e:/Strikethrough Text in Pdf Using Itext Example.pdf
*/


PDF formed after executing above java program will look like this >

Summary -

So in this core java tutorial we learned How To Strikethrough Text In Pdf in java using iText library - core java tutorial with program and examples.


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

References >



RELATED LINKS>

iText library tutorial in java - How to Create and work with PDF files in java


Creating IMAGES in pdf in java - iText tutorial >

Adding the Images In Pdf in java example using iText - iText java tutorial

How to Add And Rotate Images In Pdf in java - iText java tutorial example

How can you Add the Images from URL In Pdf in java program





Adding WATERMARK in pdf in java - iText tutorial >

How to add TEXT as Watermark In Pdf in java - iText java tutorial

How to add IMAGE as Watermark In Pdf in iText in java example



Creating CHAPTER, SECTION, CHUNK, PARAGRAPH AND PHRASE in pdf in java - iText tutorial >

Create Chapter And Section In Pdf in java - iText java tutorial

Create Chunk In Pdf in java - iText java tutorial program

how to Create Paragraph In Pdf - iText java tutorial program

Create Left, center and right aligned Paragraph In Pdf - iText java tutorial

Create Phrase In Pdf (with lead) Using Itext - iText java tutorial example


No comments:

Post a Comment