MIT License

项目介绍

vandeseer/easytable 是一个托管在 GitHub 上的开源项目,主要使用 Java 编写,采用 MIT License 许可证,目前获得 270 个 Star、93 次 Fork。

仓库全名
vandeseer/easytable
开源许可证
MIT License
Star 数
270
Fork 数
93
未关闭 Issue
38

README 摘要

easytable This is a small project that builds upon Apache's PDFBox (>= 3.0.0) and should allow you to create tables in a fairly simple way. It emerged from the need in another project. Therefore, it also may miss some crucial features. Nevertheless, there is: setting font and font size, table, row, column and cell level line breaking and line spacing background color and style on table, row, column and cell level…

完整内容见 GitHub 原始 README 或本页 。

常见问题

easytable 用什么语言开发?

主要使用 Java 编写,采用 MIT License 许可证,目前有 270 个 Star。

easytable 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 easytable 的源码?

可以直接克隆仓库:git clone https://github.com/vandeseer/easytable.git,默认分支为 master;安装与运行步骤见仓库 README。

easytable 最近还在维护吗?

仓库最近一次更新为 2024年7月16日,当前有 38 个未关闭 Issue;Star 数为 270,可作为社区活跃度的参考。

关于

Small table drawing library built upon Apache PDFBox

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
467
价值分
189
活跃状态
活跃

语言占比

Java

Release

README

easytable

This is a small project that builds upon Apache’s PDFBox (>= 3.0.0) and should allow you to create tables in a fairly simple way. It emerged from the need in another project. Therefore, it also may miss some crucial features. Nevertheless, there is:

  • setting font and font size, table, row, column and cell level
  • line breaking and line spacing
  • background color and style on table, row, column and cell level
  • padding (top, bottom, left, right) on table, row and cell level
  • border color, width and style (on table, row or cell level)
  • support for text alignment (right, left, center, justified)
  • vertical text alignment (top, middle, bottom)
  • column spanning and row spanning
  • images in cells
  • allowing for a lot of customizations
  • experimental: vertical text, drawing a large table’s overflow on the same page

One can also override classes that are responsible for table/cell drawing, i.e. their drawing behaviour can be customized to a pretty high extent.

It is also possible to draw a table over multiple pages (even with the header row being repeated on every new page) or to draw a large table’s overflow next to the already existing table on the same page (see below for examples).

Installation

Add this to your pom.xml:

<dependency>
    <groupId>com.github.vandeseer</groupId>
    <artifactId>easytable</artifactId>
    <version>1.0.2</version>
</dependency>

Or checkout the repository and install it locally with maven (e.g. for thedevelop branch):

mvn clean install -DskipTests -Dgpg.skip -Ddependency-check.skip=true

Examples

There is a minimal full working example which should help you to get started.

For a bit more involved tables have a look at this code which is needed for creating a PDF document with the following two tables:

easytable table

easytable table

For the next example have a look at the SettingsTest.java:

easytable table

The last one illustrates the use of vertical text in text cells. The code for it can be found here:

easytable table

Drawing the overflow of a large table on the same page is also possible:

easytable table

If you run the tests with mvn clean test there also some PDF documents created which you can find in the target folder. The corresponding sources (in order to understand how to use the code) can be found in the test package.

Kudos

  • to Binghammer for implementing cell coloring and text center alignment
  • to Sebastian Göhring for finding and fixing a bug (column spanning)
  • to AndreKoepke for the line breaking feature, some bigger nice refactorings and improvements
  • to Wolfgang Apolinarski for the printing over pages and bugfixes
  • to AdrianMiska for finding and fixing an issue with cell height
  • to TheRealSourceSeeker for finding a bug caused by using floats
  • to Drummond Dawson for code changes that allowed removing a dependency
  • to styssi for allowing several multipage tables being drawn on the same page
  • to Richard Mealing for adding the license section to the pom.xml
  • to msww for finding a small issue
  • to VakhoQ for implementing border styles
  • to Miloš Čadek for implementing alignment of vertical text cells
  • to Chemmic for adding repeating headers to tables that overflow on the same page

Q&A

Can I use the library with version PDFBox 2.x.x?

Every version of easytable < 1.0.0 is built on PDFBox 2.x.x.

Note that easytable 1.0.0 and below do basically only differ in the support PDFBox version, but not in their feature set. Only exception being the experimental support for paragraph cells which had to be dropped with the upgrade to PDFBox 3.

Also note that easytable >= 1.0.0 is built for Java 11 and higher, whereas lower versions are using Java 8.

Can I customize the drawers for my own specific needs?

Yep, you can customize the cell drawers itself or (depending on your use case) you can just create a custom cell.

For using a customized cell drawer, have a look at CustomCellDrawerTest.

In case you want to create your own type of cell (which shouldn’t really be necessary since the drawing can be completely adapted) you will need to use Lombok’s @SuperBuilder annotation. Again, just have a look at the code: CustomCellWithCustomDrawerUsingLombokTest

Can I draw a table over multiple pages?

Yes, have a look at TableOverSeveralPagesTest.java. Just use startY(...) and endY(..) in order to restrict the vertical part of the page where the table should be drawn:

RepeatedHeaderTableDrawer.builder()
    .table(createTable())
    .startX(50)
    .startY(100F)
    .endY(50F) // <-- If the table is bigger, a new page is started
    .build()

Is there a way to repeat the header on every page?

Depending on whether you want to repeat the header row or not you should use RepeatedHeaderTableDrawer or TableDrawer respectively.

Can I get the y coordinate of the end of a drawn table?

Yes. Just use the .getFinalY() method. Also see FinalYTest.java.

Cool, I like it, can I buy you a beer?

Yes. Or you can upvote this answer on stackoverflow. Or:

Donate with PayPal

评论

暂无评论