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.22k stars 371 forks source link

Template image is not replaced with the image set in the code #132

Open sjasaniel opened 8 years ago

sjasaniel commented 8 years ago

This is more of a question than an issue in xdocreport.

I want to add an image in my template. Shown below is the code. However when I the run the program, the image is not displayed/replaced with the image i set in the code. When I checked path of the image, it is correct and the file exists. Could you tell me what's wrong?

i doubt that the problem has something to do with the template because I just followed the examples that I found here. Anyway, here's how I did it. I insert an image, select image, click 'bookmark', set the name and press add.

    public Boolean createHTML(OutputStream out, Header header, List<Detail> details) {

        try {

            def InputStream inn = new FileInputStream(new File(getTemplatePath("template1")));
            def IXDocReport report = XDocReportRegistry.getRegistry().loadReport(inn, TemplateEngineKind.Freemarker);
            def FieldsMetadata metadata = report.createFieldsMetadata();
            metadata.load("details", Detail.class, true);
            metadata.addFieldAsImage("companyLogo", NullImageBehaviour.KeepImageTemplate);
//            report.setFieldsMetadata(metadata);

            File f = new File("C:/Users/abcde/Documents//logo.png");
            IImageProvider image = new FileImageProvider(f);

//            IImageProvider image = new ByteArrayImageProvider(new BufferedInputStream(new FileInputStream("web-app/images/Logo.png")), true);
            IContext context = report.createContext();
            context.put("companyLogo", image);
            context = prepareDataForExport(context, header, details);

            Options options = Options.getTo(ConverterTypeTo.XHTML).via(ConverterTypeVia.DOCX4J);
            report.convert(context, options, out);

        } catch (IOException io) {

            io.printStackTrace();
            return false;

        } catch (XDocReportException xd) {

            xd.printStackTrace();
            return false;
        }

        return true;
    }
SuperPat45 commented 8 years ago

May be related to https://github.com/opensagres/xdocreport/issues/159