vandeseer / easytable Goto Github PK
View Code? Open in Web Editor NEWSmall table drawing library built upon Apache PDFBox
License: MIT License
Small table drawing library built upon Apache PDFBox
License: MIT License
Do we have a way to add first 2/3 rows for header. I have requirement where I would like to repeat first 3 rows on each page while drawing table data. please let me know your comments.
Since i cant make a pull request for whatever reason:
Theres a bug in the TableDrawer which causes glitches like this (replace this test with the actual one) :
@Test
public void createSampleDocumentWithCellSpanning() throws Exception {
// Define the table structure first
TableBuilder tableBuilder = TableBuilder.newBuilder()
.addColumnOfWidth(300)
.addColumnOfWidth(120)
.addColumnOfWidth(70)
.setFontSize(8)
.setFont(HELVETICA);
// Header ...
tableBuilder.addRow(RowBuilder.newBuilder()
.add(Cell.withText("This is right aligned without a border").setHorizontalAlignment(RIGHT))
.add(Cell.withText("Sum")..setBackgroundColor(Color.ORANGE))
.setBackgroundColor(Color.BLUE)
.build());
// Header ...
tableBuilder.addRow(RowBuilder.newBuilder()
.add(Cell.withText("This is right aligned without a border").span(2).setHorizontalAlignment(RIGHT))
.setBackgroundColor(Color.BLUE)
.build());
createDocumentWithTable(tableBuilder.build(), "target/sampleWithCellSpanning.pdf");
}
You see, adding span on the second cell in a row works. But on the first one it turns to a unwanted result.
Simply replace:
columnCounter++;
with
columnCounter += cell.getSpan()
in your drawBackgroundAndText and drawBorders.
Regards
Hey, sorry for no response on the other thread, will get to that later. So, question:
row.getHeight() only works apparently when i fake a table like here:
private float getRowHeight(Row row) {
Table dummy = baseTable().addRow(row).build();
return row.getHeight();
}
Is there a way to return the expected row Height (need it for formatting multipage bills)
I tried creating a table with cyrillic text in it, but I get an exception in TableDrawer->draw(); The same snippet works fine with text in English.
final Row headerRow = Row.builder().add(CellText.builder().text("Проба").build()).build();
tableBuilder.addRow(headerRow);
float startY = page.getMediaBox().getHeight() - 10;
TableDrawer.builder().contentStream(contentStream).table(tableBuilder.build())
.startY(startY).build()
.draw();
Hi,
I am trying to use a different font which is not part of default pdfbox. so loading the ttf file for that font and adding modifying the contentstream to use that font.
but i am not able to make the font bold where needed in tables. like some columns require bold for the same font and some does not. can you tell me if its possible to bold the font (without using existing fonts like times bold) etc
The pdf drawing takes too long. Like to get a 300 pages pdf from dynamic data creating 300 tables i.e. a table on each page, it took me 3 minutes. Any way for faster performance.
Love the tool but it would be helpful to set a different font style/size on a row or cell. For example, having the header row be bold. Currently, font style is set for entire table. Only color can be changed per cell.
When you have single character CellTexts WordBreak breaks (haha.) .
How to reproduce:
Create a cell with only one single CellText. Causes this StackoverflowError:
Exception in thread "JavaFX Application Thread" java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:412)
at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:324)
at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:353)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.getStringWidth(PdfUtil.java:27)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.isLineFine(PdfUtil.java:120)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:65)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.wrapLine(PdfUtil.java:72)
at org.vandeseer.pdfbox.easytable.util.PdfUtil.splitBySize(PdfUtil.java:87)
Quick fix is to add an empty character to the given CellText. Looks a bit off when entered or right aligned but is still better then nothing. Will next week look into this issue myself if it isnt fixed until then, but due to the lack of time im just writing an issue for now.
Hi,
when I insert a paragraph inside a table, sometimes the text, if too long, goes out of border. Attached is the code with a little example, the pom.xml file and the output.
what am I doing wrong?
Thank you
If a table is drawn over several pages the header row should be shown on top of each new page.
This should be configurable, e.g. in the builder for TableDrawer
.
Also see: https://stackoverflow.com/questions/54233886/pdfbox-header-in-all-pages-using-easytable
The table gets always added to the last page in my implementation.
Is there a way to add the copy of a table to each page? Would be handy to create footers or headers of a document.
val contentStream = PDPageContentStream(
pdfDocument, pdfDocument.getPage(0),
PDPageContentStream.AppendMode.APPEND, false, false
)
TableDrawer.builder()
.table(table)
.startY(yPos)
.startX(tableRect.lowerLeftX)
.contentStream(contentStream)
.build()
.draw(Supplier<PDDocument> { pdfDocument }, Supplier<PDPage> { PDPage(PDRectangle.A4) }, headerOffset)
Hello,
I try to put different border and color and is never show.
Great project.
Thanks
Currently easytable is suffering from "excessive data hiding", e.g. you cannot easily subclass the TableDrawer
class because its constructor is private
. That makes it unnecessary hard or prohibits simple customisations for the library user.
Hello, first of all thanks for this amazing little lib. Do you think it would be possible for you to push this in jcenter and maven ? It would be easier for new versions and maintenance.
Thanks again !
... I stongly suggest to bind the library build to a fixed release version of PDF Box, i.e., to replace the version of the PDF box dependency as current:
[2.0.4,)
with e.g.,
2.0.15</version
Hello, first of all thank you very much for releasing this great library. I wanted to ask if there has been any update on Hyperlink support. I can see in issue #39 that this was mentioned.
Moreover, I am in need also of underlining text so that it looks like a link. Is this currently possible?
Thank you very much.
I'm facing an issue with borders of different color and width.
The output of the following snippet of code is attached
test.pdf
public static void main(String[] args) {
try (PDDocument doc = new PDDocument()) {
String header = "HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER "
+ "HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER "
+ "HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER "
+ "HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER ";
PDPage page = new PDPage();
doc.addPage( page );
final TableBuilder tableBuilder = Table.builder()
.addColumnsOfWidth(250, 250);
final org.vandeseer.easytable.structure.Row headerRow = org.vandeseer.easytable.structure.Row.builder()
.add(CellText.builder().text(header).horizontalAlignment(CENTER).colSpan(2).borderColor(Color.BLACK).borderWidth(1).build())
.backgroundColor(Color.WHITE)
.textColor(Color.BLACK)
.font(PDType1Font.HELVETICA_BOLD)
.fontSize(11)
.build();
tableBuilder.addRow(headerRow);
for (int row = 0; row < 10 ; row++) {
final org.vandeseer.easytable.structure.Row dataRow = org.vandeseer.easytable.structure.Row.builder()
.add(CellText.builder()
.text("Name"+row)
.horizontalAlignment(LEFT)
.backgroundColor(Color.WHITE)
.textColor(Color.BLACK)
.borderColor(Color.WHITE)
.borderWidth(0.5f).build())
.add(CellText.builder()
.text("Value"+row)
.horizontalAlignment(RIGHT)
.backgroundColor(Color.CYAN)
.textColor(Color.BLUE)
.borderColor(Color.BLACK)
.borderWidth(0.5f).build())
.font(PDType1Font.HELVETICA_BOLD)
.fontSize(9)
.build();
tableBuilder.addRow(dataRow);
final org.vandeseer.easytable.structure.Row spareRow = org.vandeseer.easytable.structure.Row.builder()
.add(CellText.builder()
.text("Spare"+row)
.horizontalAlignment(LEFT)
.backgroundColor(Color.WHITE)
.textColor(Color.BLACK)
.font(PDType1Font.HELVETICA_OBLIQUE)
.borderColor(Color.WHITE)
.borderWidth(1).build())
.add(CellText.builder()
.text("")
.horizontalAlignment(RIGHT)
.backgroundColor(Color.WHITE)
.textColor(Color.BLUE)
.borderColor(Color.WHITE)
.borderWidth(1).build())
.font(PDType1Font.HELVETICA_BOLD).fontSize(9)
.build();
tableBuilder.addRow(spareRow);
}
String footer = "FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER "
+ "FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER "
+ "FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER "
+ "FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER FOOTER ";
final org.vandeseer.easytable.structure.Row footerRow = org.vandeseer.easytable.structure.Row.builder()
.add(CellText.builder().text(footer).horizontalAlignment(CENTER).colSpan(2).borderWidth(1).build())
.backgroundColor(TURQUOISE)
.textColor(Color.BLACK)
.font(PDType1Font.HELVETICA_BOLD).fontSize(9)
.build();
tableBuilder.addRow(footerRow);
try (final PDPageContentStream contentStream = new PDPageContentStream(doc, page)) {
float startY = page.getMediaBox().getHeight() - PADDING;
Table pdfTable = tableBuilder.build();
TableDrawer.builder()
.contentStream(contentStream)
.table(pdfTable)
.startX(PADDING)
.startY(startY)
.build()
.draw();
}
String fileName="test.pdf";
doc.save(fileName);
} catch (Exception e) {
e.printStackTrace();
}
}
the upper white border of the first name cell, falls in the middle of the thicker black header border, while the upper white border of spare rows hides the lower black border of value cells.
Is this a real issue or am I doing something wrong?
One of doing this could be to register a callback with the content stream so that the users of the library could place the image themselves.
For a project we have different fonts. The regular fonts, for "normal" characters. And "fallback"-fonts, for ❤ (emojis).
Our example for this fallback-method looks like this:
private void printWithFallback(final String line, final int fontSize, final float startX, final float startY) throws IOException {
this.contentStream.beginText();
this.contentStream.newLineAtOffset(startX, startY);
for (int offset = 0; offset < line.length(); ) {
PDFont fontToPrint = this.document.getFonts().get(0);
final int codePoint = line.codePointAt(offset);
offset += Character.charCount(codePoint);
String codePointAsString = new String(new int[]{codePoint}, 0, 1);
//try all available fonts
for (final PDFont fontToTry : this.document.getFonts()) {
try {
fontToTry.encode(codePointAsString);
fontToPrint = fontToTry;
break;
} catch (final IllegalArgumentException e) {
//try next font
}
}
try {
fontToPrint.encode(codePointAsString);
} catch (final IllegalArgumentException e) {
log.error("Codepoint {} could not be printed to PDF and has been replaced by the fallback character {}. " +
"This probably means that a font which can encode this codepoint should be included in the next release.",
codePoint, FALLBACK_CHARACTER);
codePointAsString = FALLBACK_CHARACTER;
}
this.contentStream.setFont(fontToPrint, fontSize);
this.contentStream.showText(codePointAsString);
}
this.contentStream.endText();
}
How to draw multiple tables paginated across different pages using current lib..i.e. new table should be drawn next to existing one in paginated fashion
Right now one cannot enter newlines, i.e. "\n" in cell texts.
I have two rows where the first cell of each row is spanning the two rows. The remainder of the cells in each row contains images. The first row of images is sized correctly, but the first cell of the second row will resize image in the first cell with the remaining cells in the row sized correctly.
If I disable the row spanning of the first cell all the images are sized correctly.
I have not found a possible work around.
Hi,
I have written a table with 4 columns but i have a requirement of that table to sometime display either two or one image in one of the rows.
I do that by doing the col Span if one row then span col to 4 cells. else if two images then span two columns into two cells.
The only problem i am facing here is the size of the image which is coming its very small.
When i create the Table of two columns and use the same image , the image is better but is there a way to increase the width of image in case of Col span as well?
below is part of my code for table and some of the if else conditions for image display:
Table.TableBuilder tableBuilder = Table.builder()
.addColumnOfWidth(145)
.addColumnOfWidth(145)
.addColumnOfWidth(145)
.addColumnOfWidth(145);
if (pdfImage5_4 && pdfImage5_6)
{
tableBuilder.addRow(
Row.builder()
.add(ImageCell.builder().image(image5_4).maxHeight(2000l).borderWidth(1).horizontalAlignment(HorizontalAlignment.CENTER).colSpan(2).build())
.add(ImageCell.builder().image(image5_6).maxHeight(2000l).borderWidth(1).horizontalAlignment(HorizontalAlignment.CENTER).colSpan(2).build())
.build());
}
if (pdfImage5_4)
{
tableBuilder.addRow(
Row.builder()
.add(ImageCell.builder().image(image5_4).borderWidth(1).maxHeight(2000l).colSpan(4).horizontalAlignment(HorizontalAlignment.CENTER).build())
.build());
}
if (!(pdfImage5_4) && pdfImage5_6)
{
tableBuilder.addRow(
Row.builder()
.add(TextCell.builder().text(Constants.NOPREVIEWPREUPGRADE).font(TIMES_ROMAN).fontSize(6).borderWidth(1).colSpan(2).horizontalAlignment(HorizontalAlignment.LEFT).build())
.add(ImageCell.builder().image(image5_6).borderWidth(1).maxHeight(2000l).horizontalAlignment(HorizontalAlignment.CENTER).colSpan(2).build())
.build());
}
All characters in the table show wired characters if I send the Pdf via Slack. Also, if I copy the text in the table from pdf to notepad, shows wired characters.
Hello :)
I think I found a bug with the new Settings object. I have taken this example from your tests and slightly modified it:
Row row = Row.builder()
.add(CellText.builder().text(RandomStringUtils.randomAlphabetic(23)).span(2).borderWidth(1).build())
.add(CellText.builder().text("Booz").build())
.font(COURIER_BOLD).fontSize(8)
.build();
tableBuilder.addRow(row);
If I call row.getHeight()
now, I get a NullPointerException. This used to work in version 0.1.0.
If I first call tableBuilder.build()
and row.getHeight()
afterwards, it works just fine.
I've identified that this is caused by the Cell Settings being filled with fillingMergeBy
when the Table is built. But when the Row is built the Cells Settings remain empty.
Edit: I just noticed that it's not as easy as filling the Cells when the Rows are built. We still can't get the correct height because at that time we don't know yet if the Table will have line breaking :/
I have a requirement where I want to draw rectangle in each column of rows.
e.g. I want to show the estimates and actual hours worked using filled rectangle color (RGB) for each row. In iText this can be achieved using PdfTemplate (rectangle, setRGBColorFill, setRGBColorStroke methods).
Long cell text spanning into multiple pages is not handled. Code gets stuck into infinite loop.
According to your integration test, the way to draw a multipage table is:
/* builder details here */
.draw(() -> document, () -> new PDPage(PDRectangle.A4), 50f);
But this seems to call a new page for every section of the table. On the other hand, if I list an existing page, the table will just overwrite the same page. Would it be too hard to provide a function or class that takes two PDPage objects? The first would be the initial page the table starts in. The second would be a constructor for any table overflow (preferably, the new pages would be inserted in between existing pages if, for example, you wanted a table to be inserted in a document on page 2, with the document already containing 3 pages). For example:
/* builder details here */
.draw(() -> document, () -> existingPage, () -> new PDPage(PDRectangle.A4), 50f);
When a cell in the table of the drawer has text that exceeds the length of the page, then the draw() method never finishes. Edit the TwoPagesTableTest integration test
public class TwoPagesTableTest {
@Test
public void createTwoPageTable() throws IOException {
final Table.TableBuilder tableBuilder = Table.builder()
.addColumnOfWidth(200)
.addColumnOfWidth(200);
CellText dummyHeaderCell = CellText.builder()
.text("Header dummy")
.backgroundColor(Color.BLUE)
.textColor(Color.WHITE)
.borderWidth(1F)
.build();
String longText = "Sed turpis nisl, ullamcorper vitae ornare eget, porta ac odio. Nunc lacinia convallis urna sit amet scelerisque. Morbi neque est, tempor sit amet sagittis in, luctus et nisl. Phasellus ut mollis felis. Sed viverra tortor in ligula ultricies, quis faucibus turpis varius. Duis ante leo, ornare sed lectus in, finibus placerat est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus rhoncus felis sit amet ex consequat aliquam. Ut euismod odio iaculis vulputate malesuada. Donec euismod ipsum id erat ullamcorper elementum. Aenean malesuada mattis libero ac pretium. Nam non tempor risus, in congue turpis. Nam mi dolor, gravida ac imperdiet quis, pulvinar sed metus. Sed tempor orci magna, non aliquet nisl posuere vitae. Cras erat felis, euismod et sodales cursus, fermentum at arcu. Aenean maximus magna vel dignissim ullamcorper.Sed turpis nisl, ullamcorper vitae ornare eget, porta ac odio. Nunc lacinia convallis urna sit amet scelerisque. Morbi neque est, tempor sit amet sagittis in, luctus et nisl. Phasellus ut mollis felis. Sed viverra tortor in ligula ultricies, quis faucibus turpis varius. Duis ante leo, ornare sed lectus in, finibus placerat est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus rhoncus felis sit amet ex consequat aliquam. Ut euismod odio iaculis vulputate malesuada. Donec euismod ipsum id erat ullamcorper elementum.";
CellText dummyCell = CellText.builder()
.text("dummy")
.borderWidth(1F)
.build();
CellText bigCell = CellText.builder()
.text(longText)
.borderWidth(1F)
.build();
tableBuilder.addRow(
Row.builder()
.add(dummyHeaderCell)
.add(dummyHeaderCell)
.build());
tableBuilder.addRow(
Row.builder()
.add(dummyCell)
.add(bigCell)
.build());
final PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
TableDrawer drawer = TableDrawer.builder()
.table(tableBuilder.build())
.startX(50)
.startY(page.getMediaBox().getHeight() - 50)
.endY(50F) // note: if not set, table is drawn over the end of the page
.build();
do {
document.addPage(page);
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
drawer.contentStream(contentStream).draw();
}
} while (!drawer.isFinished());
document.save("target/twoPageTable.pdf");
document.close();
}
Hi, I am planning on adding A1A and accessibility to the easytable framework, because I need this. Can you please add a branch for me, I can work on. I would like to push some code in between, instead of pushing everything in the end.
Love the tool, but it would be helpful if it had row spanning. The idea is that a cell could span two or more rows, with alignment of top/middle/bottom for the text that in it. Would also be helpful if text within could be broken across multiple lines.
Hi,
imagine I want to add a table in a header section of a pdf. So I render the content area for all pages in the pdf and afterwards i want to render a table containing "Page x of 10" in the top area on every page.
This was not easy in 0.5.2 but I managed to subclass "TableDrawer" to not use the last page of the document every time draw() is called. In 0.6.0 this is not so easy anymore because of the refactorings. There should be a page supplier which is not only for new appended pages but for every existing page I want Easytable to render onto.
Are there plans supporting that kind of feature?
2nd question: is there an easy way to determine where the table ends? I mean, getting the y coordinate after adding the table.
Thank you
When i draw a repeated header table the endY gets shifted lower with every page the table gets drawn on. The vice versa effect happens with the header offset inside the .draw() function of the RepeatedHeaderTableDrawer (the table gets shifted higher every time the table reaches a new page).
private fun drawTable(
table: Table,
tableRect: PDRectangle,
pdfDocument: PDDocument,
contentStream: PDPageContentStream
) {
RepeatedHeaderTableDrawer.builder()
.table(table)
.startY(tableRect.upperRightY)
.startX(tableRect.lowerLeftX)
.contentStream(contentStream)
.endY(footerOffset)
.build()
.draw(Supplier<PDDocument> { pdfDocument }, Supplier<PDPage> { PDPage(PDRectangle.A4) }, headerOffset)
}
On version 0.5.2 the offsets are working correctly.
Hey vandeseer,
many thanks for your little project. At the moment I´m trying to use the easytable for the first time. I need to create a table over several pages and with pdfarcform in it.
I played around with your .setWordBreaking() function. It would be great if it would be possible to use a vertical alignment within a row, if the wordbreaking feature is used.
I attached an image regarding this topic.
Best regards
Kevin
Like dotted, dashed etc.
Also see: https://stackoverflow.com/questions/30590780/how-to-draw-dotted-line-in-pdfbox
As of now ParagraphCell supports StyledText, Markup and Hyperlink. I also want to add image in ParagraphCell.
... for easier dealing with different units etc.
Also see: https://gist.github.com/ecmel/3204aa6a9aa30a0b5649
I have a row of cells and in one cell the text wraps causing the row height to increase. One of the cells contains an image and when this row height increase occurs the image is aligned to the bottom of its cell. Setting the vertical alignment to MIDDLE does not affect the image placement.
Hi,
I am trying to add multiple tables appended in the same page.
Because i have a requirement to display the data from multiple table and the fomat for each data is Different, some needs to be written in 2 columns (cannot do the col span because the size of column should be less in this case )and some 4 -5 columns
Is therea way I can get the StartY location from the previous table which is written in page? so that i can append the table at correct location based on that?
I am using your EasyTable library and it is fantastic, for my use it is better than itext7. I have only one problem. I'm trying to insert a paragraph with multiple lines inside a cell but it gives me an error. Here is my class.
The error is:
Exception in thread "main" java.lang.NullPointerException at org.vandeseer.easytable.drawing.cell.ParagraphCellDrawer.drawContent(ParagraphCellDrawer.java:52) at org.vandeseer.easytable.TableDrawer.lambda$new$0(TableDrawer.java:53) at org.vandeseer.easytable.TableDrawer.drawRow(TableDrawer.java:161) at org.vandeseer.easytable.TableDrawer.drawWithFunction(TableDrawer.java:145) at org.vandeseer.easytable.TableDrawer.lambda$drawPage$1(TableDrawer.java:75) at java.lang.Iterable.forEach(Iterable.java:75) at org.vandeseer.easytable.TableDrawer.drawPage(TableDrawer.java:74) at org.vandeseer.easytable.TableDrawer.draw(TableDrawer.java:70) at it.baz.ProvaPDF.crea(ProvaPDF.java:66) at it.baz.ProvaPDF.main(ProvaPDF.java:21)
Thank you
Include hyperlink link support for the contents of a cell.
My code:
final TableBuilder tableBuilder = Table.builder()
.addColumnsOfWidth(35, 92, 50, 50, 72, 240)
.fontSize(8)
.font(HELVETICA)
.borderColor(Color.BLACK);
tableBuilder.addRow(Row.builder()
.add(TextCell.builder().text("XXXXXXXXX")
.colSpan(4)
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(Color.RED)
.fontSize(14)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("YYY YYY")
.colSpan(2)
.textColor(Color.BLACK)
.backgroundColor(Color.RED)
.fontSize(11)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.horizontalAlignment(LEFT)
.build());
tableBuilder.addRow(Row.builder()
.add(TextCell.builder().text("#")
.rowSpan(3)
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("CCC")
.rowSpan(3)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("QWERTY")
.colSpan(3)
.textColor(Color.BLACK)
.backgroundColor(Color.YELLOW)
.fontSize(10)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("John Black")
.textColor(Color.BLACK)
.backgroundColor(Color.YELLOW)
.fontSize(8)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.horizontalAlignment(LEFT)
.build());
tableBuilder.addRow(Row.builder()
.add(TextCell.builder().text("QQQQ")
.colSpan(3)
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("ZZZZZ")
.rowSpan(2)
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(PDType1Font.HELVETICA_BOLD)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.horizontalAlignment(LEFT)
.build());
tableBuilder.addRow(Row.builder()
.add(TextCell.builder().text("X")
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(HELVETICA)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("Y")
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(HELVETICA)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.add(TextCell.builder().text("LLLLLLLLLL")
.lineSpacing(1f)
.borderWidthTop(1)
.textColor(Color.BLACK)
.backgroundColor(GRAY_LIGHT_3)
.fontSize(8)
.font(HELVETICA)
.verticalAlignment(VerticalAlignment.MIDDLE)
.horizontalAlignment(CENTER)
.borderWidth(1)
.build())
.horizontalAlignment(LEFT)
.build());
return tableBuilder.build();
I tried to set the text of CellText as uppercase sigma character. In order to do this I used the code below
CellText sigmaCell = CellText.builder()
.text("S")
.borderWidth(1F)
.font(PDType1Font.SYMBOL)
.build();
It gives the following error
java.lang.IllegalArgumentException: U+2013 ('endash') is not available in this font Symbol encoding: SymbolEncoding
Thanks
Can you please add the License file to your code? It would be nice if i could see its license before using it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.