Posts

Showing posts from March, 2012

Export Jasper Report As PDF And Content Disposition

public void createPdfInvoice(String inputFileName, String outputFileName, Collection dataCollection, Map inputParameters) throws Exception { FacesContext fc = FacesContext.getCurrentInstance(); ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); ServletOutputStream servletOutputStream = response.getOutputStream(); String jrxmlReportPath = context.getRealPath("/WEB-INF/resources/report/" + inputFileName + ".jrxml"); response.setContentType("application/pdf"); try { JasperCompileManager.compileReportToFile(jrxmlReportPath); } catch (Exception e) { System.out.println("jrxml exception :::: createReportAsPdf"); e.printStackTrace(); } try { ...

Export Jasper Report As PDF And Save Into FileSystem

public void savePdfInvoice(String inputFileName, String outputFileName, Collection dataCollection, Map inputParameters) throws Exception { ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); String jrxmlReportPath = context.getRealPath("/WEB-INF/resources/report/" + inputFileName + ".jrxml"); try { JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlReportPath); JRBeanCollectionDataSource jrbcds = new JRBeanCollectionDataSource(dataCollection); /*if (jrbcds == null) { System.out.println("....JRBCDS is null"); } if (inputParameters == null) { System.out.println("....inputParameters is null"); } */ JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, inputParameters, jrbcds); S...

Append hyperlink into PDF file using iText

download iText library filepath = valid path to pdf file url = hyperlink to show at the end of the pdf file public boolean appendUrlPdf() { try { File inputFile = new File(filepath); Document document = new Document(PageSize.A4); PdfReader reader = new PdfReader(new FileInputStream(inputFile)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(inputFile)); document.open(); PdfContentByte cb = writer.getDirectContent(); for (int i = 1; i PdfImportedPage page = writer.getImportedPage(reader, i); Image instance = Image.getInstance(page); document.add(instance); } Paragraph paragraph = new Paragraph(); Anchor anchor = new Anchor(url); anchor.setReference(url); paragraph.add(anchor); document.add(paragraph); document.clo...

Appending hyperlink into Docx file using docx4j library

Download docx4j library. filepath = valid path to .docx file url = hyperlink to append into end of the file public boolean appendUrlDocx() { try { File inputFile = new File(filepath); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(inputFile); // Create hyperlink P.Hyperlink link = createHyperlink(wordMLPackage, url); // Add it to a paragraph org.docx4j.wml.ObjectFactory wmlFactory = new org.docx4j.wml.ObjectFactory(); org.docx4j.wml.P paragraph = wmlFactory.createP(); paragraph.getParagraphContent().add(link); wordMLPackage.getMainDocumentPart().addObject(paragraph); // Now save it wordMLPackage.save(inputFile); return true; } catch (InvalidFormatException ex) { ex.printStackTrace(); return false; } catch (Exception ex) { ex.printStackTr...

Java Enterprise Edition 6 Tutorial

Java Enterprise Edition 6 Tutorial

Adding row data dynamically in datatable in JSF

Image
This code is useful when making order bill dynamically. default.xhtml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"         xmlns:h="http://java.sun.com/jsf/html"       xmlns:f="http://java.sun.com/jsf/core">     <h:head>         <h:outputStylesheet library="css" name="table-style.css"  />     </h:head>     <h:body>         <h:form>             <h:dataTable value="#{order.orderList}" var="o"                      ...