phax / ph-pdf-layout

Java library for creating fluid page layouts with Apache PDFBox. Supporting multi-page tables, different page layouts etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to embed the image/icon in the Table while creating PDF

mailidpankaj opened this issue · comments

Hi,

Can we embed the image/icon in the table that we create using PLTable?

image

I know PLImage API is there to create image in the PDF. My specific requirement is to embed the image as an icon in the table cell. Please let me know whether it is supported. If yes, what is the API for the same? A code snippet will be helpful. Thanks.

Regards,
Pankaj

Sure it is possible. You just need to ensure the icon is available as GIF/JPG/PNG and than you can read it with "ImageIO" - unfortunately I don't have time to build a new example.
See https://github.com/phax/ph-pdf-layout/blob/master/src/test/java/com/helger/pdflayout4/element/image/PLImageTest.java#L61 for how to read external files.
Than you just add them into the PLTableCell

Et voila

Hi Philip,

I can see one commit is done to the codebase. I wanted to use the latest test case to integrate the image in table cell and have added the below method in the code:

public static PLTableCell createEmptyCell ()
{
return new PLTableCell (new PLSpacerX ());
}

But, code is not built as the method is undefined in the .class file. I wanted to update the repository by changing the version in the dependency as below:

"
com.helger
ph-pdf-layout4
5.1.3
"

I get the dependency error saying artifact is not available. I would like to know when this will be available for the use? Thanks.

Regards,
Pankaj

Yes, that code is part of the next micro release. You can just use new PLTableCell (new PLSpacerX ()) directly in your code or create your own helper method. It is just "syntactic sugar".