opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.19k stars 368 forks source link

illegal reflective access while using default example #641

Open BishopWolf opened 3 months ago

BishopWolf commented 3 months ago

I am using fr.opensagres.poi.xwpf.converter.pdf version 2.0.4 with apache poi 5.2.5

This is the error I am getting

Converting DOCX to PDF...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.lowagie.text.pdf.MappedRandomAccessFile$1 (file:/~/.m2/repository/com/lowagie/itext/2.1.7/itext-2.1.7.jar) to method java.nio.DirectByteBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.lowagie.text.pdf.MappedRandomAccessFile$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
Failed to generate PDF

I could change the dependency to fr.opensagres.poi.xwpf.converter.pdf.itext5

but then I am getting Class not Found PdfConverter

This is my code example

/**
     * Converts a DOCX file to PDF using XDocReport API.
     * 
     * @param inputFileName The input file name (full path).
     */
    static public void convertToPDF(String inputFileName, String outputFileName) {
        // Set the output file names
        String outputNamePDF = changeFileExtension(outputFileName, "pdf");

        try ( // Open the input file
                InputStream docStream = new FileInputStream(new File(inputFileName));
                // Create a new DOCX document from the input stream
                XWPFDocument document = new XWPFDocument(docStream);
                // Create an output stream for the ODT file
                FileOutputStream pdfStream = new FileOutputStream(new File(outputNamePDF));) {

            // Convert the DOCX to PDF
            IJ.log("Converting DOCX to PDF...");
            // Instantiate the converter options
            PdfOptions optionsPDF = PdfOptions.create();
            // Instantiate the converter
            IXWPFConverter<PdfOptions> converter = PdfConverter.getInstance();
            // Convert the document to PDF
            converter.convert(document, pdfStream, optionsPDF);
        } catch (Exception e) {
            IJ.log("Failed to generate PDF: " + outputNamePDF);
            IJ.log(e.getMessage());
        }
    }

Am I doing something wrong or is this a bug??

BishopWolf commented 3 months ago

Changing the dependency to fr.opensagres.poi.xwpf.converter.pdf.openpdf it works for template files (no images nor tables) But it shows java.lang.NullPointerException on final reports. That's it, nothing more in the log file even when I log all exceptions.