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
document.open();
// step 4
document.add(new Paragraph("Hello World!"));
// step 5
document.close();
return document;
}
}