Label printing

Hi,

I need to print shipping labels from CUBA. My idea is to use an existing CSS format inside a Freemarker template, and merge the CUBA data with the template.

Is there any way to output the generated html in a new, independent window (i.e. without CUBA formatting). Or should I generate the labels to an html file and then download that file ?

Do you suggest any other method ? Perhaps use the reporting module ? What do you recommend ?

Hi,

You can easily open new browser popup window using ExportDisplay bean: Downloading Files - CUBA Platform. Developer’s Manual


public class DemoScreen extends AbstractWindow {
    @Inject
    private ExportDisplay exportDisplay;

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);

        String htmlPage =
                "<html>\n" +
                "  <body>\n" +
                "    <h1> Html page </h1>\n" +
                "  </body>\n" +
                "</html>";
        exportDisplay.show(new ByteArrayDataProvider(htmlPage.getBytes(StandardCharsets.UTF_8)),
                "my-html.html", ExportFormat.HTML);
    }
}

Also, I’d recommend that you use our reports add-on because it supports printing of HTML files to PDF, that might be useful if you want to give PDF files to users. Check this manual page: HTML Template - CUBA Platform. Report Generator

1 Like

Thanks !