0

I'm trying to create a pdf from my tiff image using itext5 and java11 in a springboot project. These are the dependencies:


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.9</version>
        <relativePath/>
    </parent>
    <!--    PDF Generator   -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.13.3</version>
    </dependency>

Following some example I'm using:

RandomAccessSourceFactory rasf = new RandomAccessSourceFactory();
RandomAccessFileOrArray  myTiffFile = new RandomAccessFileOrArray(rasf.createBestSource(tiffFilepath));

to access the image file I want to add to the pdf. PROBLEM: This method doesn't implement Autocloseable, so I have to do it manually and can't use a try-with-resources. When I try to do it manually, in console I have this log:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.itextpdf.text.io.ByteBufferRandomAccessSource$1 (file:/C:/Users/user/.m2/repository/com/itextpdf/itextpdf/5.5.13.3/itextpdf-5.5.13.3.jar) to method java.nio.DirectByteBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.itextpdf.text.io.ByteBufferRandomAccessSource$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

and the resource remain not closed. Do you know how to solve this and what can I use to create the pdf?

Alexxxx
  • 19
  • 4
  • Does this answer your question? [What is an illegal reflective access?](https://stackoverflow.com/questions/50251798/what-is-an-illegal-reflective-access) – stdunbar Mar 26 '23 at 23:18
  • iText5 is pretty prehistoric. This error can be ignored for now but it's time to move into this decade. – stdunbar Mar 26 '23 at 23:20
  • The problem is not only the warning: the access to the file still remain open, so I can't delete it – Alexxxx Mar 27 '23 at 00:28
  • I know, but I'm not sure I can use iText7 without License in commercial project. Have you got something else to suggest for tiff to pdf conversion? – Alexxxx Mar 27 '23 at 01:31
  • Itext 5 and iText 7 are licensed the same way. So, unless you have a commercial iText 5 license, there is no difference in what you may or may not do with either version. – mkl Mar 27 '23 at 04:48
  • That being said, the warning is but a warning, it does not prevent anything yet. Thus, there likely is some issue in your code (or in iText underneath) that holds the resources. – mkl Mar 27 '23 at 04:51

0 Answers0