Java: Convert PDF to Excel

2022-06-09 07:27:00 Written by Koohji

For security reasons, many financial documents such as invoices are usually saved in PDF format. If you want to perform data analysis and calculation on these documents, you may need to convert them to Excel. In this article, we will introduce how to convert PDF to Excel in Java using Spire.PDF for Java.

Install Spire.PDF for Java

First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>11.12.16</version>
    </dependency>
</dependencies>

Convert PDF to Excel in Java

The following are the steps to convert a PDF document to Excel:

  • Initialize an instance of PdfDocument class.
  • Load the PDF document using PdfDocument.loadFromFile(String) method.
  • Save the document to Excel using PdfDocument.saveToFile(String, FileFormat) method.
  • Java
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;

public class ConvertPdfToExcel {
    public static void main(String[] args) {
        //Initialize an instance of PdfDocument class
        PdfDocument pdf = new PdfDocument();
        //Load the PDF document
        pdf.loadFromFile("Sample.pdf");

        //Save the PDF document to XLSX
        pdf.saveToFile("PdfToExcel.xlsx", FileFormat.XLSX);
    }
}

Java: Convert PDF to Excel

This example converts multiple PDF pages to multiple Excel worksheets. If you want to convert a multi-page PDF to a single Excel sheet, please refer to this article: Java: Convert a Multi-Page PDF to One Excel Worksheet.

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Java: Highlight Text in PowerPoint

2022-09-29 06:44:00 Written by Koohji

When you want to emphasize a particular point in a PowerPoint presentation, you can highlight it with a bright color to help the audience catch it at first glance. In this article, we will explain how to highlight text in a PowerPoint presentation in Java using Spire.Presentation for Java.

Install Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>11.1.1</version>
    </dependency>
</dependencies>

Highlight Text in PowerPoint in Java

The following are the steps to highlight specific text in a PowerPoint document:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Loop through the slides in the presentation and the shapes on each slide.
  • Check if the current shape is of IAutoShape type.
  • If the result is true, typecast it to IAutoShape.
  • Initialize an instance of TextHighLightingOptions class, and set the text highlighting options such as whole words only and case sensitive using TextHighLightingOptions.setWholeWordsOnly() and TextHighLightingOptions.setCaseSensitive() methods.
  • Highlight a specific text in the shape using IAutoShape.getTextFrame().highLightText() method.
  • Save the result file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

import java.awt.*;

public class HighlightTextInPPT {
    public static void main(String []args) throws Exception {
        //Create an instance of Presentation class
        Presentation presentation = new Presentation();
        //Load a PowerPoint file
        presentation.loadFromFile("Input.pptx");

        //Loop through all slides
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            //Get the current slide
            ISlide slide = presentation.getSlides().get(i);
            //Loop through the shapes on the slide
            for (int j = 0; j < slide.getShapes().getCount(); j++)
            {
                //Check if the current shape is of IAutoShape type
                if (slide.getShapes().get(j) instanceof IAutoShape)
                {
                    //Typecast the shape to IAutoShape
                    IAutoShape shape = (IAutoShape)slide.getShapes().get(j);

                    //Create an instance of TextHighLightingOptions class
                    TextHighLightingOptions options = new TextHighLightingOptions();
                    //Set text highlighting options
                    options.setCaseSensitive(true);
                    options.setWholeWordsOnly(true);

                    //Highlight specific text within the shape with color
                    shape.getTextFrame().highLightText("Spire", Color.YELLOW, options);
                }
            }
        }

        //Save the result file
        presentation.saveToFile("HighlightText.pptx", FileFormat.PPTX_2013);

    }
}

Java: Highlight Text in PowerPoint

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

This article demonstrates how to find the text that matches a specific regular expression in a PDF document using Spire.PDF for Java.

" //Load a PDF document
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\test.pdf");

        //Create a object of PdfTextFind collection
        PdfTextFindOptions findOptions = new PdfTextFindOptions();

        //Loop through the pages
        for (Object page : (Iterable) pdf.getPages()) {
            PdfPageBase pageBase = (PdfPageBase) page;

            //Define a regular expression
            String pattern = "\\#\\w+\\b";
            // Set search parameter to use regular expression
            findOptions.setTextFindParameter(EnumSet.of(TextFindParameter.Regex));

            // Create a text finder object for the page
            PdfTextFinder textFinder = new PdfTextFinder(pageBase);

            // Find text fragments that match the pattern
            List finds = textFinder.find(pattern, findOptions);

            //Highlight the search results with yellow
            for (PdfTextFragment find : finds) {
                find.highLight(Color.yellow);
            }
        }

        //Save to file
        pdf.saveToFile("FindByPattern.pdf");"

Find Text in PDF by Regular Expression in Java

page 40