pdf file should get down when clicking on button

Hi Team,

I need to generate the pdf file with table custom action. Pdf file should download in browser automatically.

Please find the below code and assist me to complete this task.

package com.company.invoiceapp.web.invoice;

import com.haulmont.cuba.core.entity.FileDescriptor;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.components.AbstractLookup;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.File;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class InvoiceBrowse extends AbstractLookup {

    /** Path to the resulting PDF file. */
    public static final String RESULT
            = "D://Checking//CubaPlatform//itext//hello.pdf";

    public void generateInvoice() throws IOException,DocumentException {

        AppConfig.createExportDisplay(this).show(new FileDescriptor());


    public Document createPdf(String filename)
            throws DocumentException, IOException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        // step 4
        document.add(new Paragraph("Hello World!"));
        // step 5

        return document;



Thank your for the question. It would be great if you improve it and we will be able to help you. Here are some hints: https://www.cuba-platform.com/discuss/t/faq-guidelines/5

I am implementing the custom action for Table apart from create, edit,remove button.

When i click the custom action button then pdf file should get download in the browser.

Attached the browser table screen shot for your reference.

It seems Report generator could help you to solve the problem. It provides means to generate PDF reports.
You can launch reports on screens by assigning PrintformAction to a Button.
You can also use YARG for reports generation.
If you want to download the generated PDF file instead of open it in browser define the cuba.web.viewFileExtensions application property without “pdf” in the value.