List of usage examples for com.lowagie.text Document Document
public Document(Rectangle pageSize)
Document
-object. From source file:com.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java
public void init(String outputFileName, String fileId) throws FileNotFoundException, DocumentException, Exception { document = new Document(PageSize.A4); document.setMargins(10, 10, 10, 10); pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(outputFileName)); pdfWriter.setPageEvent(new FreightInvoiceLclPdfCreator(realPath, fileId)); company = new SystemRulesDAO().getCompanyDetails(); this.setBrand(fileId); HeaderFooter footer = new HeaderFooter( new Phrase(companyName, new Font(Font.HELVETICA, 10, Font.ITALIC, Color.BLACK)), false); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer);/*from w w w .j a v a 2s . c o m*/ document.open(); }
From source file:com.gp.cong.logisoft.reports.BookingCoverSheetPdfCreater.java
public void initialize(SearchBookingReportDTO searchBookingReportDTO, String simpleRequest, MessageResources messageResources, String documentName) throws FileNotFoundException, DocumentException { document = new Document(PageSize.A4); document.setMargins(15, 15, 10, 10); pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(searchBookingReportDTO.getFileName())); pdfWriter.setPageEvent(new BookingCoverSheetPdfCreater(searchBookingReportDTO, simpleRequest, messageResources, documentName)); document.open();/*from ww w. j a v a 2s . com*/ }
From source file:com.gst.infrastructure.dataqueries.service.ReadReportingServiceImpl.java
License:Apache License
@Override public String retrieveReportPDF(final String reportName, final String type, final Map<String, String> queryParams) { final String fileLocation = FileSystemContentRepository.FINERACT_BASE_DIR + File.separator + ""; if (!new File(fileLocation).isDirectory()) { new File(fileLocation).mkdirs(); }//from www .ja v a 2 s.co m final String genaratePdf = fileLocation + File.separator + reportName + ".pdf"; try { final GenericResultsetData result = retrieveGenericResultset(reportName, type, queryParams); final List<ResultsetColumnHeaderData> columnHeaders = result.getColumnHeaders(); final List<ResultsetRowData> data = result.getData(); List<String> row; logger.info("NO. of Columns: " + columnHeaders.size()); final Integer chSize = columnHeaders.size(); final Document document = new Document(PageSize.B0.rotate()); PdfWriter.getInstance(document, new FileOutputStream(new File(fileLocation + reportName + ".pdf"))); document.open(); final PdfPTable table = new PdfPTable(chSize); table.setWidthPercentage(100); for (int i = 0; i < chSize; i++) { table.addCell(columnHeaders.get(i).getColumnName()); } table.completeRow(); Integer rSize; String currColType; String currVal; logger.info("NO. of Rows: " + data.size()); for (int i = 0; i < data.size(); i++) { row = data.get(i).getRow(); rSize = row.size(); for (int j = 0; j < rSize; j++) { currColType = columnHeaders.get(j).getColumnType(); currVal = row.get(j); if (currVal != null) { if (currColType.equals("DECIMAL") || currColType.equals("DOUBLE") || currColType.equals("BIGINT") || currColType.equals("SMALLINT") || currColType.equals("INT")) { table.addCell(currVal.toString()); } else { table.addCell(currVal.toString()); } } } } table.completeRow(); document.add(table); document.close(); return genaratePdf; } catch (final Exception e) { logger.error("error.msg.reporting.error:" + e.getMessage()); throw new PlatformDataIntegrityException("error.msg.exception.error", e.getMessage()); } }
From source file:com.ideaspymes.proyecttemplate.stock.web.ProductoConsultaBean.java
public String createPdf() throws IOException, DocumentException { EtiquetaConf conf = etiquetaConfDAO.getEtiquetaConfDefault(); if (hayParaImprimir() && conf != null) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); float ancho = Utilities.millimetersToPoints(conf.getAnchoHoja().floatValue()); System.out.println("Ancho: " + ancho); float largo = Utilities.millimetersToPoints(conf.getLargoHoja().floatValue()); System.out.println("Alto: " + largo); // step 1 Document document = new Document(new Rectangle(ancho, largo)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();/*from w w w. j av a 2 s . c o m*/ // step 4 PdfContentByte cb = writer.getDirectContent(); for (Producto p : getLista()) { if (p.getCantidadEtiquetas() > 0) { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(96); Font fontbold = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); Chunk productTitle = new Chunk("HC", fontbold); Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_LEFT); pTitile.setLeading(6, 0); PdfPCell cellTitle = new PdfPCell(); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_TOP); cellTitle.setBorder(Rectangle.NO_BORDER); cellTitle.addElement(pTitile); Font font2 = FontFactory.getFont("Times-Roman", conf.getTamDescripcion().floatValue(), Font.NORMAL); Chunk productName = new Chunk(p.getNombre(), font2); Paragraph pName = new Paragraph(productName); pName.setAlignment(Element.ALIGN_CENTER); //pTitile.setLeading(0, 1); cellTitle.addElement(pName); table.addCell(cellTitle); Barcode39 code39 = new Barcode39(); code39.setCode(p.getCodigo()); //code39.setCodeType(Barcode.EAN13); code39.setBarHeight(conf.getAltoCodBarra().floatValue()); //codeEan.setX(0.7f); code39.setSize(conf.getTamDescripcion().floatValue()); //code39.setAltText("HC - " + p.getNombre()); PdfPCell cellBarcode = new PdfPCell(); cellBarcode.setHorizontalAlignment(Element.ALIGN_CENTER); cellBarcode.setBorder(Rectangle.NO_BORDER); cellBarcode.addElement(code39.createImageWithBarcode(cb, null, Color.BLACK)); table.addCell(cellBarcode); for (int i = 0; i < p.getCantidadEtiquetas(); i++) { document.add(table); document.newPage(); } } } // step 5 document.close(); response.getOutputStream().flush(); response.getOutputStream().close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", "")); } return null; }
From source file:com.ikon.util.DocConverter.java
License:Open Source License
/** * Convert HTML to PDF//from w w w . ja v a2s. c o m */ public void html2pdf(File input, File output) throws ConversionException, DatabaseException, IOException { log.debug("** Convert from HTML to PDF **"); FileOutputStream fos = null; try { fos = new FileOutputStream(output); // Make conversion Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, fos); doc.open(); HTMLWorker html = new HTMLWorker(doc); html.parse(new FileReader(input)); doc.close(); } catch (DocumentException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:com.ikon.util.DocConverter.java
License:Open Source License
/** * Convert TXT to PDF/*from w w w .j ava2 s . c o m*/ */ public void txt2pdf(InputStream is, File output) throws ConversionException, DatabaseException, IOException { log.debug("** Convert from TXT to PDF **"); FileOutputStream fos = null; String line = null; try { fos = new FileOutputStream(output); // Make conversion BufferedReader br = new BufferedReader(new InputStreamReader(is)); Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, fos); doc.open(); while ((line = br.readLine()) != null) { doc.add(new Paragraph(12F, line)); } doc.close(); } catch (DocumentException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:com.ikon.util.DocConverter.java
License:Open Source License
/** * Convert ZIP to PDF//from w ww. j a va 2 s . c o m */ @SuppressWarnings("rawtypes") public void zip2pdf(File input, File output) throws ConversionException, DatabaseException, IOException { log.debug("** Convert from ZIP to PDF **"); FileOutputStream fos = null; ZipFile zipFile = null; try { fos = new FileOutputStream(output); // Make conversion zipFile = new ZipFile(input); Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, fos); doc.open(); for (Enumeration e = zipFile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); doc.add(new Paragraph(12F, entry.getName())); } doc.close(); zipFile.close(); } catch (ZipException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } catch (DocumentException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Builds the pdf document.//from w ww . j ava2 s . c o m * * @param out * the out * @throws ReportException * the report exception * @throws IOException * Signals that an I/O exception has occurred. */ public void buildPdfDocument(final OutputStream out) throws ReportException, IOException { this.document = new Document(getPageRotation()); try { this.writer = PdfWriter.getInstance(this.document, out); this.document.open(); final PdfPTable pdfPTable = createPdfTable(); this.document.add(pdfPTable); this.document.close(); } catch (final DocumentException e) { throw new ReportException(e); } }
From source file:com.krawler.esp.servlets.ExportMPXServlet.java
License:Open Source License
public void createPDFFile(Connection conn, HttpServletRequest request, HttpServletResponse response) throws ConfigurationException { String projid = request.getParameter("projectid"); try {/*from w w w . ja va2s. c om*/ String userid = AuthHandler.getUserid(request); String companyid = AuthHandler.getCompanyid(request); String tasks = projdb.getProjectTasks(conn, projid, userid, companyid, 0, -1, true); ByteArrayOutputStream os = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); document.setPageSize(PageSize.A4.rotate()); PdfWriter writer = PdfWriter.getInstance(document, os); setHeaderFooter(document, request.getParameter("header")); JSONObject jobj = new JSONObject(request.getParameter("options")); JSONArray jarr = jobj.getJSONArray("data"); ArrayList tabCols = new ArrayList(); ArrayList tabArr = createTables(jarr, tabCols, document);//new ArrayList(); writer.setPageEvent(new EndPage()); HashMap taskIdIndex = new HashMap(); JSONArray taskArr = new com.krawler.utils.json.base.JSONObject(tasks).getJSONArray("data"); for (int c = 0; c < taskArr.length(); c++) { com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c); taskIdIndex.put(temp.getString("taskid"), temp.getInt("taskindex")); } taskIdIndex.put("0", 0); for (int c = 0; c < taskArr.length(); c++) { com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c); String pred = ""; if (!StringUtil.isNullOrEmpty(temp.getString("predecessor"))) { String[] p = temp.getString("predecessor").split(","); for (int i = 0; i < p.length; i++) { pred += taskIdIndex.get(p[i]).toString() + ","; } pred = pred.substring(0, (pred.length() - 1)); } String taskResourceNames = projdb.getTaskResourcesNames(conn, temp.getString("taskid"), projid); for (int i = 0; i < tabArr.size(); i++) { int lvl = 0; if (i == 0) { lvl = temp.getInt("level"); } String[] colArr = (String[]) tabCols.get(i); String[] values = getPDFCellOfRec(colArr, temp, pred, taskResourceNames); Font fnt = new Font(); if (temp.getBoolean("isparent")) { fnt.setStyle(Font.BOLD); } else { fnt.setStyle(Font.NORMAL); } addPdfRowToTable(values, (PdfPTable) tabArr.get(i), fnt, lvl); } } document.open(); getCompanyDetails(request); addComponyLogo(document); for (int i = 0; i < tabArr.size(); i++) { PdfPTable temp = (PdfPTable) tabArr.get(i); temp.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); document.add(temp); document.newPage(); } document.close(); os.close(); String fname = request.getParameter("filename"); os.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(os.size()); response.getOutputStream().write(os.toByteArray()); response.getOutputStream().flush(); String type = "[PDF]"; AddToAuditTrail(conn, request, projid, type); conn.commit(); } catch (ServiceException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException e) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e); } catch (SessionExpiredException e) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e); } }
From source file:com.krawler.spring.hrms.payroll.salaryslip.ExportSalarySlipService.java
License:Open Source License
public void exportSalarySlip(String userid, Date startdate, Date enddate, HttpServletRequest request, HttpServletResponse response, String historyid) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter writer = null;/*from w w w .ja va2 s .c o m*/ try { HrmsCommonPayroll hrmsCommonPayroll = new HrmsCommonPayroll(); DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); User user = exportSalarySlipDAO.getUser(userid); Empprofile empprofile = exportSalarySlipDAO.getEmpprofile(userid); Useraccount useraccount = exportSalarySlipDAO.getUserAccount(userid); Company company = user.getCompany(); PayrollHistory payrollHistory = exportSalarySlipDAO.getPayrollHistory(historyid); CompanyPreferences preferences = (CompanyPreferences) kwlCommonTablesDAO .getObject("com.krawler.common.admin.CompanyPreferences", company.getCompanyID()); Date financialStartDate = hrmsCommonPayroll.getFinanacialYearStartDate(enddate, preferences.getFinancialmonth()); Date financialEndDate = hrmsCommonPayroll.getFinanacialYearEndDate(enddate, preferences.getFinancialmonth() + 11); IncomeTax incomeTax = getIncomTaxObj(request); List<PayrollHistory> list = null; Map<String, Double> mapEPF = null; if (incomeTax != null) { list = incomeTax.getPayrollHistories(userid, HrmsPayrollConstants.PAYROLL_HISTORY_STATUS_PROCESSED_FINAL, financialStartDate, financialEndDate); mapEPF = incomeTax.getEPF(list, payrollHistory); } writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage(RequestContextUtils.getLocale(request))); document.open(); PdfPTable mainTable = new PdfPTable(1); mainTable.setWidthPercentage(100); mainTable.addCell(getEmployeeDetails(user, empprofile, useraccount, company, payrollHistory, sdf, Rectangle.NO_BORDER, request)); mainTable.addCell(getSalaryDetails(user, empprofile, useraccount, company, payrollHistory, sdf, Rectangle.NO_BORDER, request)); mainTable.addCell(getEmployeeAndEmployerDetails(user, empprofile, useraccount, company, payrollHistory, sdf, Rectangle.CELL, list, mapEPF, request)); document.newPage(); document.add(mainTable); document.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + user.getFirstName() + "_" + sdf.format(startdate) + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(baos.size()); response.getOutputStream().write(baos.toByteArray()); } catch (Exception e) { e.printStackTrace(); } finally { writer.close(); } }