phax / ph-pdf-layout

Java library for creating fluid page layouts with Apache PDFBox. Supporting multi-page tables, different page layouts etc.
Apache License 2.0
64 stars 11 forks source link

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

Closed mailidpankaj closed 4 years ago

mailidpankaj commented 4 years ago

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

phax commented 4 years ago

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

phax commented 4 years ago

Et voila

mailidpankaj commented 4 years ago

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
<artifactId>ph-pdf-layout4</artifactId>
<version>5.1.3</version>

"

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

phax commented 4 years ago

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".