HTML JPG PDF XML DOCX
  Product Family
PDF

Create Table for PDF in Java SDK

Create a Table with extended properties for PDF Document using server-side Java API.

Get Started

How to create Table for PDF via Cloud Java SDK

In order to create Table for PDF via Cloud Java SDK , we’ll use Aspose.PDF Cloud Java SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in Java language for various cloud platforms. Open Repository package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console for install it using Maven.

Add Aspose Cloud repository to your application pom.xml

Add Aspose Cloud repository


    <repositories>
        <repository>
            <id>aspose-cloud</id>
            <name>Aspose Cloud Repository</name>
            <url>https://releases.aspose.cloud/java/repo/</url>
        </repository>
    </repositories>

To install the API client library to your local Maven repository, simply execute:

Installation from Github


    mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

Deploy Maven repository


    mvn clean deploy

Steps to create Table for PDF via Java SDK

Aspose.PDF Cloud developers can easily load & create Table with extended properties for PDF in just a few lines of code.

  1. Upload the File to Cloud Storage
  2. Define the Table’s Appearance
  3. Define Table Content
  4. Add the Table to the PDF
  5. Download the Updated File
 

This sample code shows adding Table to PDF documents


    import java.util.ArrayList;

    import com.aspose.asposecloudpdf.model.BorderInfo;
    import com.aspose.asposecloudpdf.model.Cell;
    import com.aspose.asposecloudpdf.model.Color;
    import com.aspose.asposecloudpdf.model.FontStyles;
    import com.aspose.asposecloudpdf.model.GraphInfo;
    import com.aspose.asposecloudpdf.model.Row;
    import com.aspose.asposecloudpdf.model.Table;
    import com.aspose.asposecloudpdf.model.TextRect;
    import com.aspose.asposecloudpdf.model.TextState;

    public class TableInitialize {
        public static Table create() {
            int numOfCols = 5;
            int numOfRows = 5;

            TextState textState = new TextState()
                .fontSize(10.);

            TextState headerState = new TextState()
                .fontSize(10.)
                .fontStyle(FontStyles.BOLD);

            Table table = new Table();        
            table.setRows(new ArrayList<>());

            String colWidths = "";
            for (int c = 0; c < numOfCols; c++)
            {
                colWidths += " 70";
            }
            table.columnWidths(colWidths);

            table.defaultCellTextState(textState);

            GraphInfo borderTableBorder = new GraphInfo();
            borderTableBorder.setColor(new Color().A(255).G(255));
            borderTableBorder.setLineWidth(1.);

            table.setDefaultCellBorder(new BorderInfo()
                .top(borderTableBorder)
                .right(borderTableBorder)
                .bottom(borderTableBorder)
                .left(borderTableBorder)
            );

            table.setTop(100.);

            for (int r = 0; r < numOfRows; r++) {
                Row row = new Row().cells(new ArrayList<>());

                for (int c = 0; c < numOfCols; c++) {
                    Cell cell = new Cell();
                
                    cell.setBackgroundColor(new Color().A(255).R(150).G(150).B(150));
                    cell.setParagraphs(new ArrayList<>());
                    cell.getParagraphs().clear();

                    // change properties on cell
                    if (r == 0) {
                        cell.setDefaultCellTextState(headerState);
                        cell.getDefaultCellTextState().setForegroundColor(new Color().A(255).B(255));
                        cell.getParagraphs().add(new TextRect().text(String.format("Col #%d", c)));
                    } else {
                        if (c == 0) {
                            cell.setDefaultCellTextState(headerState);
                            cell.getDefaultCellTextState().setForegroundColor(new Color().A(255).B(255));
                            cell.getParagraphs().add(new TextRect().text(String.format("Row #%d", r)));
                        } else {
                            cell.setDefaultCellTextState(textState);
                            cell.getDefaultCellTextState().setForegroundColor(new Color().A(255).R(255));
                            cell.getParagraphs().add(new TextRect().text(String.format(" Value: row #%d - col #%d", r, c)));
                        }
                    }
                    row.getCells().add(cell);
                }
                table.getRows().add(row);
            }
            return table;
        }
    }
    
 

Work with Table in PDF

Tables provide a structured format for presenting data systematically, making it easier for readers to understand and analyze information. They also enhance the visual appeal of a document, adding professionalism and organization. When dealing with numerical or comparative data, tables improve clarity by grouping related information in an easy-to-read format. Additionally, tables can incorporate real-time or dynamically generated content, such as data from databases or analytics dashboards. Create the Table with extended properties for PDF documents with Aspose.PDF Cloud Java SDK.

With our Java library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & stamps (text or image) to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to extract Table into PDF files online and test the functionality.

  •