1. Products
  2.   PDF
  3.   Java
  4.   Aspose.PDF for Java

Aspose.PDF for Java

 
 

Create, Parse & Convert PDFs via Java PDF API

Leading Java Library for PDF document making, rendering, parsing, manipulation & conversion to other supported file formats without using Adobe Acrobat.

What is Aspose.PDF for Java?

Aspose.PDF for Java is a top Java tool that simplifies developers’ tasks by enabling them to build robust applications for handling PDF files. This library allows you to generate both straightforward and intricate PDF documents effortlessly. What makes Aspose.PDF for Java stand out is its ability to generate PDFs using an API or XML templates. The best part is that it’s fully Java-based and seamlessly integrates with JDK 1.8 and newer versions.

The library offers full assistance with many input and output formats like DOC, DOCX, PDF, PDF/A, TEX, XPS, SVG, XLSX, PPTX, JPEG, PNG, BMP, and more. With this library, developers can do various document tasks like making new PDFs, working on existing ones, adding text and images, handling forms, managing metadata, annotations, bookmarks, watermarks, custom fonts, and more. It’s a handy tool for creating and working with different types of documents. The library also provides support for controlling the layout and formatting of the content with ease.

With Aspose.PDF for Java, you can easily pull out text, images, and more from your PDF files and store them in various formats. This API is super flexible and robust, making it perfect for many types of projects. Whether you’re making new PDFs, editing current ones, or changing them into different formats, this tool has all the features you require to complete your tasks effectively. With its rich feature set and easy-to-use methods, Aspose.PDF for Java is a valuable tool for any developer working with PDF documents in a Java environment.

Previous Next

Getting Started with Aspose.PDF for Java

The recommend way to install Aspose.PDF for Java is via Maven repository. You can easily use Aspose.PDF for Java API directly in your Maven Projects with simple configurations.

Maven repository for Aspose.Pdf for Java

 //First you need to specify Aspose Repository configuration / location in your Maven pom.xml as follows:

<repositories>
	<repository>
	<id>AsposeJavaAPI</id>
	<name>Aspose Java API</name>
	<url>https://releases.aspose.com/java/repo/</url>
	</repository>
</repositories>

//Define Aspose.PDF for Java API Dependency

<dependencies>
	<dependency>
	<groupId>com.aspose</groupId>
	<artifactId>aspose-pdf</artifactId>
	<version>21.7</version>
	</dependency>
</dependencies>

You can download the library directly from Aspose.PDF product page

Convert PDF Files via Java API

Aspose.PDF for Java has provided very powerful support for converting PDF documents to numerous supported formats as well as converting from other formats to PDF. The library has included support loading and saving of several popular document formats. Using Aspose.PDF you can convert PDF to Microsoft Excel formats like XLSX, ODS, CSV and SpreadSheetML, HTML to PDF, PDF to PowerPoint, PDF to EPUB & XPS, PDF documents to HTML and many more. It also allows converting different images formats to PDF as well as exporting PDF pages as images in JPEG, PNG and other formats.

How to Convert PDF to XLS with Control Column via Java?

    public static void ConvertPDFtoExcelAdvanced_InsertBlankColumnAtFirst() {
        // Load PDF document
        Document pdfDocument = new Document(_dataDir + "input.pdf");
        // Instantiate ExcelSave Option object
        ExcelSaveOptions excelsave = new ExcelSaveOptions();
        excelsave.setInsertBlankColumnAtFirst(false);
        // Save the output in XLS format
        pdfDocument.save("PDFToXLS_out.xls", excelsave);
    }

PDF Documents Parsing via Java Library

Aspose.PDF for Java makes it easy for software professionals to parse their PDF documents inside java applications with just a couple of lines of Java code. The library allows to extraction various kind of information from PDF file with ease. It supports text parsing or extraction from a whole PDF document, a particular page, or a particular region in a page. The library also supports extracting images, fonts, data from those forms as well as extract AcroForms data from PDF files. Aspose.PDF also supports extracting tabular from PDF.

How to Extract Images from a PDF File via Java API ?

public static void Extract_Images(){
       // The path to the documents directory.
       String _dataDir = "/home/admin1/pdf-examples/Samples/";
       String filePath = _dataDir + "ExtractImages.pdf";

       // Load PDF document
       com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(filePath);

       com.aspose.pdf.Page page = pdfDocument.getPages().get_Item(1);
       com.aspose.pdf.XImageCollection xImageCollection = page.getResources().getImages();
       // Extract a particular image
       com.aspose.pdf.XImage xImage = xImageCollection.get_Item(1);

       try {
           java.io.FileOutputStream outputImage = new java.io.FileOutputStream(_dataDir + "output.jpg");
           // Save output image
           xImage.save(outputImage);
           outputImage.close();
       } catch (java.io.FileNotFoundException e) {
           // TODO: handle exception
           e.printStackTrace();
       } catch (java.io.IOException e) {
           // TODO: handle exception
           e.printStackTrace();
       }
   }

Working with Tables in PDF Documents via Java

Aspose.PDF for Java has included support for handling tables which helps software developers in displaying information in a systematic manner. The library allows software developers to create or add new tables inside PDF files with just a couple of lines of java code. The library have included several important features for handling tables such as, extract tables from PDF documents, manipulate PDF tables, modify existing tables, integrate table with data sources , remove tables from PDF and many more.

How to Create Table with Rounded Corner via Java API?

 public static void RoundedBorderRadius() {
        Document doc = new Document();
        Page page = doc.getPages().add();

        // Instantiate a table object
        Table tab1 = new Table();

        // Add the table in paragraphs collection of the desired section
        page.getParagraphs().add(tab1);

        GraphInfo graph = new GraphInfo();
        graph.setColor(Color.getRed());
        // Create a blank BorderInfo object
        BorderInfo bInfo = new BorderInfo(BorderSide.All, graph);
        // Set the border a rounder border where radius of round is 15
        bInfo.setRoundedBorderRadius(15);
        // Set the table Corner style as Round.
        tab1.setCornerStyle(BorderCornerStyle.Round);
        // Set the table border information
        tab1.setBorder(bInfo);
        // Create rows in the table and then cells in the rows
        Row row1 = tab1.getRows().add();
        row1.getCells().add("col1");
        row1.getCells().add("col2");
        row1.getCells().add();

        TextFragment mytext = new TextFragment("col3 with large text string");

        row1.getCells().get_Item(2).getParagraphs().add(mytext);
        row1.getCells().get_Item(2).setWordWrapped(false);

        Row row2 = tab1.getRows().add();
        row2.getCells().add("item1");
        row2.getCells().add("item2");
        row2.getCells().add("item3");

        // Save the PDF
        doc.save(_dataDir + "BorderRadius_out.pdf");
    }

Manage Images inside PDF Documents via Java

Aspose.PDF for Java is a very smart and efficient library that fully supports images insertion as well as management inside PDF documents. The library allows software developers to add images to existing PDF documents and change its properties with ease. The library supports various properties for handling images such as extract images from PDF files, replace images in PDF, set image size, delete unwanted images from a PDF, search images in PDF, get resolution and dimension of embed images, generate thumbnail images from PDF documents and many more.

How to Add Image in an Existing PDF via Java API?

 
    public static void AddImageInAnExistingPDFFile_Facades() {
        // Open document
        PdfFileMend mender = new PdfFileMend();

        // Create PdfFileMend object to add text
        mender.bindPdf(_dataDir + "AddImage.pdf");

        // Add image in the PDF file
        mender.addImage(_dataDir + "aspose-logo.jpg", 1, 100, 600, 200, 700);

        // Save changes
        mender.save(_dataDir + "AddImage_out.pdf");

        // Close PdfFileMend object
        mender.close();
    }
 English