Pdfbox Table

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

Categories

Categories

PDFBox Business Logic Libraries PDF Data
GroupId

GroupId

com.moebiusgames
ArtifactId

ArtifactId

pdfbox-table
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Pdfbox Table
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Source Code Management

Source Code Management

https://github.com/entrusc/pdfbox-table

Download pdfbox-table

How to add to project

<!-- https://jarcasting.com/artifacts/com.moebiusgames/pdfbox-table/ -->
<dependency>
    <groupId>com.moebiusgames</groupId>
    <artifactId>pdfbox-table</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.moebiusgames/pdfbox-table/
implementation 'com.moebiusgames:pdfbox-table:1.1.1'
// https://jarcasting.com/artifacts/com.moebiusgames/pdfbox-table/
implementation ("com.moebiusgames:pdfbox-table:1.1.1")
'com.moebiusgames:pdfbox-table:jar:1.1.1'
<dependency org="com.moebiusgames" name="pdfbox-table" rev="1.1.1">
  <artifact name="pdfbox-table" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.moebiusgames', module='pdfbox-table', version='1.1.1')
)
libraryDependencies += "com.moebiusgames" % "pdfbox-table" % "1.1.1"
[com.moebiusgames/pdfbox-table "1.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.apache.pdfbox : pdfbox jar 2.0.16
org.jsoup : jsoup jar 1.8.3

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-core jar 1.3

Project Modules

There are no modules declared in this project.

PDFBox Table

A small library to add multipage table support to Apache's PDFBox (https://pdfbox.apache.org/).

How to use?

You can then use the library in your Maven projects like this (it's on Maven Central):

<dependency>
    <groupId>com.moebiusgames</groupId>
    <artifactId>pdfbox-table</artifactId>
    <version>1.1.1</version>
</dependency>

License

This library is licensed under MIT license and can therefore be used in any project, even for commercial ones.

Example

public class PDFTableExample {

    private static final int COLUMN_DATE = 0;
    private static final int COLUMN_TIME_FROM = 1;
    private static final int COLUMN_TIME_TO = 2;
    private static final int COLUMN_COMMENT = 3;

    public static void main(String[] args) throws Exception {
        try (PDDocument doc = new PDDocument()) {
            PDPage firstPage = new PDPage(PDRectangle.A4);
            PDFRenderContext context = new PDFRenderContext(doc, firstPage);

            //heading
            PDFLabel heading = new PDFLabel((int) (PDRectangle.A4.getWidth() - 40));
            heading.setText("Some Heading");
            heading.getCell().setFontSize(16).setPaddingBottom(10 * PDFUtils.MM_TO_POINTS_72DPI);
            heading.render(context, 10 * PDFUtils.MM_TO_POINTS_72DPI,
                    PDRectangle.A4.getHeight() - 10 * PDFUtils.MM_TO_POINTS_72DPI);

            PDFTable reportTable = PDFTable.createWithSomeFixedColumnWidths(
                    PDRectangle.A4.getWidth() - 20 * PDFUtils.MM_TO_POINTS_72DPI, // full A4 width minus 20mm margin
                    22 * PDFUtils.MM_TO_POINTS_72DPI,       // width COLUMN_DATE
                    24 * PDFUtils.MM_TO_POINTS_72DPI,       // width COLUMN_TIME_FROM
                    24 * PDFUtils.MM_TO_POINTS_72DPI,       // width COLUMN_TIME_TO
                    PDFTable.AUTO_DETERMINE_COLUMN_WIDTH    // width COLUMN_COMMENT uses the rest that is available
                    );

            // repeat headers on every new page
            reportTable.setColumnHeadersMode(PDFTable.ColumnHeadersMode.COLUMN_HEADERS_ON_EVERY_PAGE);

            reportTable.getColumn(COLUMN_DATE)
                    .setHeading("Date")
                    .setHeadingBackgroundColor(Color.LIGHT_GRAY);

            reportTable.getColumn(COLUMN_TIME_FROM)
                    .setHeading("From")
                    .setHeadingBackgroundColor(Color.LIGHT_GRAY);

            reportTable.getColumn(COLUMN_TIME_TO)
                    .setHeading("Till")
                    .setHeadingBackgroundColor(Color.LIGHT_GRAY);

            reportTable.getColumn(COLUMN_COMMENT)
                    .setHeading("Comment")
                    .setHeadingBackgroundColor(Color.LIGHT_GRAY);


            for (int i = 0; i < 200; ++i) {
                PDFTableRow row = reportTable.addRow();

                LocalDateTime from = LocalDateTime.now();
                LocalDateTime till = from.plus(12, ChronoUnit.MINUTES);

                row.getCell(COLUMN_DATE).setContent(from.toLocalDate().format(DateTimeFormatter.ISO_DATE));
                row.getCell(COLUMN_TIME_FROM).setContent(from.format(DateTimeFormatter.ISO_LOCAL_TIME));
                row.getCell(COLUMN_TIME_TO).setContent(till.format(DateTimeFormatter.ISO_LOCAL_TIME));
                row.getCell(COLUMN_COMMENT).setContent("Some multiline comment for line number "
                        + i + " which will span over multiple lines for sure");
            }

            reportTable.render(context,
                    10 * PDFUtils.MM_TO_POINTS_72DPI   // margin left of 10mm
            );

            // make sure to call this before saving the document
            // to close all content streams on all pages
            context.closeAllPages();

            doc.save(new File("test.pdf"));
        }

    }

}

which will render a PDF document like this:

pdfbox-table-example

Versions

Version
1.1.1
1.1.0
1.0