Skip to main content

Posts

Showing posts from 2019

Find, Replace and Highlight Data in Excel in Java

Finding and replacing data is one of the most useful features in Microsoft Excel, it allows us to quickly locate the position of a particular data and replace it with another data. This blog demonstrates how to find a specified text, replace it with another text and then highlight the result in Excel file in Java using Free Spire.XLS for Java library. Before using the below code, please download Free Spire.XLS for Java package then and import Spire.Xls.jar under the lib folder into your project. import com.spire.xls.CellRange; import com.spire.xls.ExcelVersion; import com.spire.xls.Workbook; import com.spire.xls.Worksheet; import java.awt.*; public class ReplaceAndHightlightText {     public static void main(String[] args){         //Create a Workbook instance         Workbook workbook = new Workbook();         //Load the Excel file         workbook.loadFromFile( "test.xlsx" );         //Get the first worksheet         Worksheet worksheet = workbook.getWork

Encrypt and Decrypt Excel Files in Java

This blog demonstrates how to encrypt and decrypt Excel Files in Java using Free Spire.XLS for Java library. Installation First of all, you need to download spire.xls.jar and add it to your project as dependency. If you use maven, you need to add the following dependencies to your pom.xml file. <repositories>         <repository>             <id>com.e-iceblue</id>             <name>e-iceblue</name>             <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>         </repository> </repositories> <dependencies>     <dependency>         <groupId>e-iceblue</groupId>         <artifactId>spire.xls.free</artifactId>         <version>2.2.0</version>     </dependency> </dependencies> Encrypt Excel file Free Spire.XLS for Java supports the following encrypt options: Encrypt the whole excel file with password E

Convert PDF to Image in Java

This blog demonstrates how to convert PDF to Image using Free Spire.PDF for Java library. Free Spire.PDF is a Java library which supports converting PDF to multiple commonly used image formats such as .png, .jpg, .tiff and .svg. Free Spire.PDF for Java provide a saveAsImage method in PdfDocument class which enables us to save PDF to image. In the following example, we will see how to convert a PDF file to .png images using Free Spire.PDFfor Java. Before start with coding, you need to Download  Free Spire.PDF for Java package , unzip it and import Spire.Doc.jar file from the  lib  folder in your project as a denpendency. import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import com.spire.pdf.PdfDocument; import javax.imageio.ImageIO; public class PDFtoImage {         public static void main(String[] args) throws IOException {         //load a PDF file         PdfDocument pdf = new PdfDocument();         pdf.loadFromF

Create Excel File in Java

In this blog, I will show you how to create an Excel file in Java with Free Spire.XLS for Java API. Free Spire.XLS for Java is a free and independent Java Excel API that empowers developers to create, read, edit, convert and print Excel files without installing Microsoft Office. 1. Installation Download the Free Spire.XLS for Java API from this link , unzip the package and then add the Spire.Xls.jar to your project as a dependency. For maven project, you can add the following code to pom.xml file to import Spire.Xls.jar into your project. <repositories>         <repository>             <id>com.e-iceblue</id>             <name>e-iceblue</name>             <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>         </repository> </repositories> <dependencies>     <dependency>         <groupId> e-iceblue </groupId>         <artifactId>spire.xl

Add Table of Contents (TOC) to PDF in Java

Adding table of contents (TOC) to our document is a useful way to show readers what chapters are included in our document. When readers click on the table of contents, they can quickly navigate to the specific parts that they’re interested. In this blog, I will introduce how to add table of contents (TOC) to a PDF document programmatically in Java using Free Spire.PDF for Java library. import com.spire.pdf.*; import com.spire.pdf.actions.PdfGoToAction; import com.spire.pdf.annotations.*; import com.spire.pdf.general.PdfDestination; import com.spire.pdf.graphics.*; import java.awt.*; import java.awt.geom.*; public class TableOfContent {     public static void main(String[] args) throws Exception     {         //load PDF document         PdfDocument doc = new PdfDocument( "sample.pdf" );         int pageCount = doc.getPages().getCount();         //Insert a page as the first page to draw TOC         PdfPageBase tocPage = doc.getPages().insert( 0 );

Split PDF File in Java

In this article, I will introduce two methods to split a PDF file in Java application: 1. Split a PDF to single page PDF files 2. Split a PDF to multiple PDF files by page range The below examples use Free Spire.PDF for Java library. Imported NameSpace: import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; import com.spire.pdf.graphics.PdfMargins; import java.awt.geom.Point2D; Split a PDF to single page PDF files //load the PDF file PdfDocument doc = new PdfDocument(); doc.loadFromFile( "sample.pdf" ); //split every page of the PDF into a separate file doc.split( "Split/splitDocument-{0}.pdf" , 0 ); doc.close();   Split a PDF to multiple PDF by page range //load the PDF file PdfDocument doc = new PdfDocument(); doc.loadFromFile( "sample.pdf" ); //create a new PDF file PdfDocument newDoc1 = new PdfDocument(); PdfPageBase page; //add 2 pages to the new PDF, and draw the content of page 1

Extract Text From PDF in Java

In this article, we’re going to explain how to extract text from a Pdf file in Java. An overview of content: Extract All Text from a Pdf Read/Extract Text from a Specific Rectangle Area in a Pdf Page Read/Extract Text using SimpleTextExtractionStrategy The Pdf library we need: Spire.PDF for Java The example Pdf file: Sample Code Imported Namespaces import com.spire.pdf.*; import com.spire.pdf.exporting.text.SimpleTextExtractionStrategy; import java.awt.geom.Rectangle2D; import java.io.*; Read/Extract All Text from a Pdf //Instantiate a PdfDocument object PdfDocument pdf = new PdfDocument(); //Load the Pdf file pdf.loadFromFile("Additional.pdf"); StringBuilder sb= new StringBuilder(); //Extract text from every page of the Pdf for (PdfPageBase page: (Iterable<PdfPageBase>) pdf.getPages()) {     sb.append(page.extractText(true)); } try {     //Write the text into a .txt file      FileWriter writer = new FileWrite