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: https://doc.cuba-platform.com/manual-6.6/file_download.html


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: https://doc.cuba-platform.com/reporting-6.6/template_html.html

1 Like

Thanks !