dhorions/boxable

Who wants to work on documenting this library

dhorions opened this issue · 18 comments

Hi everyone,

a lot of helpful people have been adding great features to this library. I think there are now so many great features, that we should start thinking about properly documenting them and providing easy examples to people can get started using the library quickly.

Does anyone want to help with this?

Thanks,

Dries

Hi Dries,

I can gladly help with documentation of this library, I will make some small code snipets for those new merged features with proper description.

Hrvoje

Hi @Frulenzo,

I would like to collect all tutorial and documentation on http://dhorions.github.io/boxable/ .
I'll be releasing 1.4 which contains all the already merged changes and the dataTable (was csvTable) approach.

Hi @dhorions,
First of all, those predefined and customizable styles are pretty impressive! Very nice work! This project looks better each day.

Second, do you want to collect tutorials/documenation in this thread,gitter or per email? Just for now, I will put some quick tutorials right here.

Boxable features

Some of the features that Boxable supports:

  • HTML tags in cell content (not all! <p>,<i>,<b>,<br>,<ul>,<ol>,<li>)
  • Horizontal & Vertical Alignment of the text
  • Images inside cells and outside table (image scale is also supported)
  • basic set of rendering attributes for lines (borders)
  • rotated text (by 90 degrees)
  • writing text outside tables

Retrieving current table page

If table is displayed on multiple pages. the "new Page" can be retrieved with table.getCurrentPage().

Maybe something like :

[...]
// did we change the page?
if (table.getCurrentPage() != page) {
    cos.close();
    page = table.getCurrentPage();
    cos = new PDPageContentStream(document, page, true, true);
}

Where page represents page of the document where table started and cos represents current PDPageContentStream.

Retrieving last position of the current table

Last position of the table can be retrieved as follow:

float yPosition = table.draw()

Writing inside PDF Document

It is pretty easy to write some text inside PDF Document with PDStreamUtils.write(final PDPageContentStream stream, final String text, final PDFont font, final float fontSize, final float x, final float y, final Color color) method where :

  • text - The text which will be displayed.
  • font - The font of the text
  • fontSize - The font size of the text
  • x - Start X coordinate for text.
  • y - Start Y coordinate for text.
  • color - Color of the text

Maybe it is better to put that in some context, for example, writing document title

[...]
private PDPageContentStream cos;
private PDPage page;
private PDFont font = PDType1Font.HELVETICA;
private float leftMargin = 50;
private marginBetweenYElements = 10;
private float titleFontSize = 18;
[...]
private void drawPageTitle() throws IOException {
        // draw document title first
        PDStreamUtils.write(cos, "Document title", titleFontSize, leftMargin, yPosition,
                Color.BLACK);

        // drop Y position with default margin between vertical elements
        yPosition -= marginBetweenYElements;
    }

Drawing images in PDF Document

It is very similar process just like writing text. All work is done by Ìmage.draw(final PDDocument doc, final PDPageContentStream stream, float x, float y) method where

  • doc - PDDocument where drawing will be applied
  • stream - PDPageContentStream where drawing will be applied
  • x - X coordinate for image drawing
  • y - Y coordinate for image drawing

Lets put that in context, for example, drawing logo on our PDF document:

private PDPageContentStream cos;
private PDDocument doc;
[...]
Image image = new Image(ImageIO.read(new File("/../logo.png")));
// imagine we have pretty big logo and we want scale that a little bit
float imageWidth = 75;
image = image.scaleByWidth(imageWidth);
image.draw(doc, cos, xPosition, yPosition)

Hello, is it possible to add rows to existing pdf ?
I have pdf template having predefined table with empty rows along with other data in other pages.
Now can I add rows to this existing table without modifying other data using Boxable API? P

Hi guys, while adding Maven dependencies as per your website [http://dhorions.github.io/boxable/] I noticed that you have default version pointing to 1.4 when I think that it should be 1.5-RC due to the fact that there are missing methods in classes for example the Table Class under ver 1.4 was missing:

  • tableStartedAtNewPage() method
  • getLineSpacing() method
  • setLineSpacing() method

so when running sample tests in TableTest Class I ran into several errors. It took me a few hours to realize that the my Maven dependency was pointing to an older version of boxable and not 1.5-RC.. . .or is there a specific reason you guys have ver 1.4 as the default ?

I am not that much expert in this library, but after using it, I think we definitely need documentation. I am ready to contribute.

@davdavarshal Thanks for your interest in documentation of this library! Please when you have something just drop it here as reponse because I will try to collect all reponses, make more documentation myself and then start making quality wiki.

I'm still working on documentation of this library and what I really want to know is which problems/questions did you have at first glance of this library? What did you really want to see in Wiki FAQ?

how can I use the boxable in my simple jsp servlet web application, please give me some guidance, give me the .jar file link

Hi,

Is it possible to draw more than one tables in the same page one after another?

hi i would like to push changes to library
i fixed unsupported csv Parser chars

Hello, I am interested in helping out with documenting this library. How can I help out?

Any updates to the wiki are more than welcome.

Hello, is there any possibility if table continue to multiple pages automatically create that pages as new PDPage?
I need to add footer (with author, datetime, page count) to each page.
Thank you

Hello, is there any possibility if table continue to multiple pages automatically create that pages as new PDPage?
I need to add footer (with author, datetime, page count) to each page.

Currently I am iterating on all pages at last and them printing the footer on them, if need I can share my code snippet. We can think of whether such a feature can be added to the library later, like header and footers. These are typical reporting requirements and I am working on reporting features.

Hi All,
Is there a way to create accessible (508 compliant) tables using this library. Can we add tags to the table rows, columns and data?