public void createPdf() Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("data.pdf")); document.open(); document.add(new Paragraph("Invoice #" + invoiceBean.getId())); // Add your JSF data here document.close();
: Rename the file extension from .jsf to .txt or .html , open it in a web browser, and use the Print to PDF function (Ctrl+P). 2. Developer Guide: Dynamic PDF Generation
En ese caso:
import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.context.FacesContext; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletResponse;
// Close the document document.close();
In this article, we explored two approaches for converting JSF files to PDF documents. The first approach used iText and JSF templates, while the second approach used PDF generation libraries such as Apache PDFBox. Both approaches have their advantages and disadvantages, and the choice of approach depends on your specific requirements.