List of usage examples for com.itextpdf.text Image getInstance
public static Image getInstance(final Image image)
From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java
License:Open Source License
public int handle(final User user, final User manager, final ExpenseNote en) throws MalformedURLException, IOException, DocumentException { log.info("Building list of expenses ..."); List<Expense> expenses = Expense.list(en); log.info("Retrieved " + expenses.size() + " expenses from the datastore"); log.info("Creating ExpenseNoteDocOutputStream"); ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en); Document document = new Document(); PdfWriter.getInstance(document, stream); document.open();//from w w w . j av a 2s . c om document.addTitle("Expense note " + en.id + " of " + user.name); document.addSubject("Expense note generated by Rogerthat Enterprise!"); document.addKeywords("expense note"); document.addAuthor(user.name); document.addCreator("Rogerthat OneApp Enterprise Mobility"); Paragraph preface = new Paragraph(); preface.add(new Paragraph("TP Vision expense note", titleFont)); preface.add(new Paragraph(" ")); DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); Date date = new Date(); preface.add(new Paragraph("Date: " + dateFormat.format(date))); preface.add(new Paragraph("Requestor: " + user.name)); preface.add(new Paragraph("Approver: " + manager.name)); preface.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(7); table.setWidthPercentage(110); table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 }); addHeader(table, "Id"); addHeader(table, "Date"); addHeader(table, "Nature"); addHeader(table, "Description"); addHeader(table, "Account"); addHeader(table, "Amount"); addHeader(table, "Voucher"); table.setHeaderRows(1); Collections.sort(expenses, new Comparator<Expense>() { @Override public int compare(Expense e1, Expense e2) { return (int) (e1.date - e2.date); } }); int i = 0; double total = 0; for (Expense expense : expenses) { PdfPCell c1 = new PdfPCell(new Phrase("" + ++i)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.addCell(dateFormat.format(new Date(expense.date * 1000))); table.addCell(expense.nature); table.addCell(expense.description); table.addCell("" + expense.account); c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency)); c1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(c1); table.addCell(expense.voucher); total += expense.amount; } preface.add(table); preface.add(new Paragraph(" ")); preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont)); document.add(preface); i = 0; for (Expense expense : expenses) { i++; if (expense.receipt == null) continue; document.newPage(); Paragraph receipt = new Paragraph(); receipt.add(new Paragraph("Attachment " + i, titleFont)); document.add(receipt); Image image = Image.getInstance(new URL(expense.receipt)); image.setRotationDegrees(-90); float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100; image.scalePercent(scaler); document.add(image); } document.close(); stream.close(); return stream.getSize(); }
From source file:com.mui.certificate.core.HalalCertification.java
License:Apache License
@Override public void exportCertificate(Certificate cert, File outputPdf) throws Exception { ByteMatrix matrix = generateQRCode(cert.getCertificateURL().toString()); int scale = sMagicNumber / matrix.getWidth(); BufferedImage buffImage = convertToImage(matrix, scale); File tempOutput = new File("tmp-qrcode.png"); ImageIO.write(buffImage, "png", tempOutput); Image itImage = Image.getInstance(tempOutput.getCanonicalPath()); PdfReader reader = new PdfReader("doc/template_certificate_halal.pdf"); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdf)); int centerY = 715; int centerX = 135; itImage.setAbsolutePosition(centerX - (itImage.getWidth() / 2), centerY - (itImage.getHeight() / 2)); stamper.getOverContent(1).addImage(itImage); AcroFields form1 = stamper.getAcroFields(); String nameHeader = "topmostSubform[0].Page1[0]."; form1.setField(nameHeader + "no_certificate[0]", cert.getCertificateNumber().toString()); form1.setField(nameHeader + "name_product[0]", cert.getProductName()); form1.setField(nameHeader + "type_product[0]", cert.getProductType()); form1.setField(nameHeader + "name_company[0]", cert.getCompanyName()); form1.setField(nameHeader + "company_address[0]", cert.getCompanyAddress()); Calendar cal = Calendar.getInstance(new Locale("id")); Locale idLocale = new Locale("id"); cal.setTime(cert.getIssuedDate());// ww w . j a v a2 s .c o m form1.setField(nameHeader + "issued_date[0]", String.format(idLocale, "%1$tA, %1$te %1$tB %1$tY", cal)); cal.setTime(cert.getValidDate()); form1.setField(nameHeader + "expired_date[0]", String.format(idLocale, "%1$tA, %1$te %1$tB %1$tY", cal)); stamper.setFormFlattening(true); stamper.close(); tempOutput.delete(); }
From source file:com.mx.ipn.clases.PDF.java
public PdfPTable Tabla_Simple() throws BadElementException, IOException { Paragraph paragraph1 = new Paragraph(); Font nomb = FontFactory.getFont(FontFactory.TIMES_BOLD, 9, Font.NORMAL, BaseColor.DARK_GRAY); Image image;/* www. jav a 2 s .c o m*/ // Obtenemos el logo de datojava image = Image.getInstance(getClass().getResource("/com/ipn/mx/imagenes/logo.png")); image.scaleAbsolute(70f, 60f); //creamos la tabla con 3 columnas PdfPTable mitablasimple = new PdfPTable(2); PdfPCell cellimage = new PdfPCell(image); // Propiedades de la celda cellimage.setBorderColor(BaseColor.WHITE); cellimage.setHorizontalAlignment(Element.ALIGN_CENTER); paragraph1.add(new Phrase("1. Nombre completo Y/O Razn Social.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("2. Direccin.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("3. Registro Federal de Contribuyentes Y/O CURP.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("4. Telfonos de Oficina y mviles.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("5. Actividad econmica e ingreso promedio.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("6. Correo Electrnico. ", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); PdfPCell cell = new PdfPCell(paragraph1); // Propiedades de la celda cell.setBorderColor(BaseColor.WHITE); cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); mitablasimple.addCell(cell); mitablasimple.addCell(cellimage); //retornamos la tabla return mitablasimple; }
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET) protected final void downloadUserInformation(@PathVariable int id, HttpServletRequest request, final HttpServletResponse response) throws ServletException, BusinessException, DocumentException { UserBean user = userService.select(id, FetchMode.EAGER); if (user == null) { return;/* w w w . ja va 2s . co m*/ } Document document = new Document(); document.setMargins(70, 70, 20, 20); try { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + user.getName() + "_profile.pdf\""); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Image profileImage = null; try { profileImage = Image.getInstance(user.getContent().getFilePath()); } catch (Exception e) { // e.printStackTrace(); } if (profileImage != null) { profileImage.setAlignment(Image.MIDDLE | Image.TEXTWRAP); profileImage.setBorder(Image.BOX); profileImage.setBorderWidth(5); BaseColor bgcolor = WebColors.getRGBColor("#E5E3E3"); profileImage.setBorderColor(bgcolor); profileImage.scaleToFit(100, 100); document.add(profileImage); } document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); // Adding Table Data PdfPTable table = new PdfPTable(2); // 2 columns. table.setWidthPercentage(100); // Width 100% table.setSpacingBefore(15f); // Space before table table.setSpacingAfter(15f); // Space after table // Set Column widths float[] columnWidths = { 1f, 2f, }; table.setWidths(columnWidths); // Name setTableHeader("Name", table); setTableContent(user.getName(), table); // Gender setTableHeader("Gender", table); String gender = "Male"; if (user.getGender() == Gender.FEMALE) { gender = "Female"; } setTableContent(gender, table); // Age setTableHeader("Age", table); setTableContent("" + user.getAge(), table); // Date of Birth setTableHeader("DOB", table); DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); setTableContent(dateFormatter.format(user.getDob()), table); // Email setTableHeader("Email", table); setTableContent(user.getEmail(), table); // NRC setTableHeader("NRC", table); setTableContent(user.getNrc(), table); // Phone setTableHeader("Phone", table); setTableContent(user.getPhone(), table); // Roles String roleStr = ""; List<RoleBean> roles = user.getRoles(); if (roles != null && roles.size() > 0) { Iterator<RoleBean> itr = roles.iterator(); while (itr.hasNext()) { RoleBean role = itr.next(); roleStr += role.getName(); if (itr.hasNext()) { roleStr += ","; } } } setTableHeader("Role(s)", table); setTableContent(roleStr, table); // Address setTableHeader("Address", table); setTableContent(user.getAddress(), table); document.add(table); document.add(new Paragraph(new Date().toString())); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:com.mycompany.bandaru_exam.accountDriver.java
/** * @param args the command line arguments *//* w w w . ja v a 2 s . c o m*/ public static void main(String[] args) throws FileNotFoundException, DocumentException, BadElementException, IOException { // TODO code application logic here ReadfromExcel rd = new ReadfromExcel(); List<Account> accountList = rd.getAccountListFromExcel(); for (Account a : accountList) { System.out.println(a.getFirstName()); OutputStream file = new FileOutputStream(new File(a.getLastName() + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); //Inserting Image in PDF Image image = Image.getInstance("logo.png"); image.scaleAbsolute(600f, 100f);//image width,height //Now Insert Every Thing Into PDF Document document.open();//PDF document opened........ document.add(image); document.add(new Paragraph("Welcome! " + a.getFirstName() + " " + a.getLastName() + "!")); document.add(new Paragraph(" ")); document.add(new Paragraph(" " + "Below are your Account Details :")); document.add(new Paragraph(" " + "First Name:" + a.getFirstName())); document.add(new Paragraph(" " + "Last Name:" + a.getLastName())); document.add(new Paragraph(" " + "Account Number:" + a.getAccNumber())); document.add(new Paragraph(" " + "Account Balance:$" + a.getBalance())); document.close(); file.close(); } }
From source file:com.mycompany.mavenproject1.Createpdf.java
private void generateLayout(Document doc, PdfContentByte cb) { try {/*from w w w . ja v a 2s.c o m*/ cb.setLineWidth(1f); // Invoice Header box layout cb.rectangle(420, 700, 150, 60); cb.moveTo(420, 720); cb.lineTo(570, 720); cb.moveTo(420, 740); cb.lineTo(570, 740); cb.moveTo(480, 700); cb.lineTo(480, 760); cb.stroke(); // Invoice Header box Text Headings createHeadings(cb, 422, 743, "Account No."); createHeadings(cb, 422, 723, "Invoice No."); createHeadings(cb, 422, 703, "Invoice Date"); // Invoice Detail box layout cb.rectangle(20, 50, 550, 600); cb.moveTo(20, 630); cb.lineTo(570, 630); cb.moveTo(50, 50); cb.lineTo(50, 650); cb.moveTo(150, 50); cb.lineTo(150, 650); cb.moveTo(430, 50); cb.lineTo(430, 650); cb.moveTo(500, 50); cb.lineTo(500, 650); cb.stroke(); // Invoice Detail box Text Headings createHeadings(cb, 22, 633, "Qty"); createHeadings(cb, 52, 633, "Item Number"); createHeadings(cb, 152, 633, "Item Description"); createHeadings(cb, 432, 633, "Price"); createHeadings(cb, 502, 633, "Ext Price"); //add the images Image companyLogo = Image.getInstance("images/olympics_logo.gif"); companyLogo.setAbsolutePosition(25, 700); companyLogo.scalePercent(25); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.mycompany.peram_inclassexam.WritePDFFile.java
public void createPDF(AccountDetails account) throws DocumentException, FileNotFoundException, BadElementException, IOException { Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter write = PdfWriter.getInstance(document, new FileOutputStream(account.getLastName() + "_output.pdf")); document.open();//w w w . j a v a2 s . c o m Image image = Image.getInstance("image.png"); image.scaleToFit(450f, 1800f); document.add(image); document.add(new Paragraph( "--------------------------------------------------------------------------------------------------------------------------")); Paragraph welcomeParagraph = new Paragraph( "Welcome! " + account.getFirstName() + " " + account.getLastName() + "!"); welcomeParagraph.setSpacingBefore(50); document.add(welcomeParagraph); String firstName = "First Name: " + account.getFirstName(); String lastName = "Last Name: " + account.getLastName(); String acctNumber = "Account Number: " + account.getAccountNo(); String acctBalance = String.format("Account Balance: $%.1f", account.getAccountBalance()); Paragraph detailsPara = new Paragraph("Below are your Account Details:\n" + firstName + "\n" + lastName + "\n" + acctNumber + "\n" + acctBalance); detailsPara.setIndentationLeft(30); detailsPara.setSpacingBefore(20); document.add(detailsPara); document.close(); write.close(); }
From source file:com.netsteadfast.greenstep.bsc.command.KpiReportPdfCommand.java
License:Apache License
private void createBody(PdfPTable table, VisionVO vision) throws Exception { Map<String, String> managementMap = BscKpiCode.getManagementMap(false); //Map<String, String> calculationMap = BscKpiCode.getCalculationMap(false); PdfPCell cell = null;/*from ww w.ja v a2 s. c o m*/ for (PerspectiveVO perspective : vision.getPerspectives()) { Image pImage = Image.getInstance(BscReportSupportUtils.getByteIconBase("PERSPECTIVES", perspective.getTarget(), perspective.getMin(), perspective.getScore(), "", "", 0)); pImage.setWidthPercentage(10f); String content = this.getItemsContent(perspective.getName(), perspective.getScore(), perspective.getWeight(), perspective.getTarget(), perspective.getMin()); cell = new PdfPCell(); cell.addElement(pImage); cell.addElement(new Phrase("\n" + content, this.getFont(perspective.getFontColor(), false))); this.setCellBackgroundColor(cell, perspective.getBgColor()); cell.setRowspan(perspective.getRow()); table.addCell(cell); for (ObjectiveVO objective : perspective.getObjectives()) { Image oImage = Image.getInstance(BscReportSupportUtils.getByteIconBase("OBJECTIVES", objective.getTarget(), objective.getMin(), objective.getScore(), "", "", 0)); oImage.setWidthPercentage(10f); content = this.getItemsContent(objective.getName(), objective.getScore(), objective.getWeight(), objective.getTarget(), objective.getMin()); cell = new PdfPCell(); cell.addElement(oImage); cell.addElement(new Phrase("\n" + content, this.getFont(objective.getFontColor(), false))); this.setCellBackgroundColor(cell, objective.getBgColor()); cell.setRowspan(objective.getRow()); table.addCell(cell); for (KpiVO kpi : objective.getKpis()) { /* content = this.getKpisContent( kpi, managementMap, calculationMap); */ Image kImage = Image.getInstance(BscReportSupportUtils.getByteIconBase("KPI", kpi.getTarget(), kpi.getMin(), kpi.getScore(), kpi.getCompareType(), kpi.getManagement(), kpi.getQuasiRange())); kImage.setWidthPercentage(10f); content = this.getKpisContent(kpi, managementMap); cell = new PdfPCell(); cell.addElement(kImage); cell.addElement(new Phrase("\n" + content, this.getFont(kpi.getFontColor(), false))); this.setCellBackgroundColor(cell, kpi.getBgColor()); table.addCell(cell); } } } }
From source file:com.netsteadfast.greenstep.bsc.command.KpiReportPdfCommand.java
License:Apache License
private void createDateRange(PdfPTable table, VisionVO vision, Context context, int maxRows) throws Exception { String frequency = (String) context.get("frequency"); String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim(); String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim(); String startDate = StringUtils.defaultString((String) context.get("startDate")).trim(); String endDate = StringUtils.defaultString((String) context.get("endDate")).trim(); String date1 = startDate;//from w w w .j av a 2 s . c o m String date2 = endDate; if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) { date1 = startYearDate + "/01/01"; date2 = endYearDate + "/12/" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12); } Map<String, Object> headContentMap = new HashMap<String, Object>(); this.fillHeadContent(context, headContentMap); String content = "Frequency: " + BscMeasureDataFrequency.getFrequencyMap(false).get(frequency) + " Date range: " + date1 + " ~ " + date2 + "\n" + StringUtils.defaultString((String) headContentMap.get("headContent")); PdfPCell cell = null; cell = new PdfPCell(); cell.addElement(new Phrase(content, this.getFont(BscReportPropertyUtils.getFontColor(), false))); this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor()); cell.setColspan(maxRows); table.addCell(cell); for (PerspectiveVO perspective : vision.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { for (KpiVO kpi : objective.getKpis()) { cell = new PdfPCell(); cell.addElement(new Phrase(kpi.getName(), this.getFont(kpi.getFontColor(), false))); this.setCellBackgroundColor(cell, kpi.getBgColor()); cell.setColspan(4); cell.setRowspan(2); table.addCell(cell); for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) { cell = new PdfPCell(); cell.addElement( new Phrase(dateScore.getDate(), this.getFont(dateScore.getFontColor(), false))); this.setCellBackgroundColor(cell, dateScore.getBgColor()); table.addCell(cell); } for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) { Image image = Image .getInstance(BscReportSupportUtils.getByteIcon(kpi, dateScore.getScore())); image.setWidthPercentage(20f); cell = new PdfPCell(); cell.addElement(new Phrase(BscReportSupportUtils.parse2(dateScore.getScore()), this.getFont(dateScore.getFontColor(), false))); cell.addElement(image); this.setCellBackgroundColor(cell, dateScore.getBgColor()); table.addCell(cell); } } } } }
From source file:com.netsteadfast.greenstep.bsc.command.KpiReportPdfCommand.java
License:Apache License
private void putCharts(PdfPTable table, Context context) throws Exception { String pieBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("pieCanvasToData")); String barBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("barCanvasToData")); BufferedImage pieImage = SimpleUtils.decodeToImage(pieBase64Content); BufferedImage barImage = SimpleUtils.decodeToImage(barBase64Content); ByteArrayOutputStream pieBos = new ByteArrayOutputStream(); ImageIO.write(pieImage, "png", pieBos); pieBos.flush();/*from ww w. j ava 2 s . c om*/ ByteArrayOutputStream barBos = new ByteArrayOutputStream(); ImageIO.write(barImage, "png", barBos); barBos.flush(); PdfPCell cell = null; Image pieImgObj = Image.getInstance(pieBos.toByteArray()); pieImgObj.setWidthPercentage(100f); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.addElement(pieImgObj); table.addCell(cell); Image barImgObj = Image.getInstance(barBos.toByteArray()); barImgObj.setWidthPercentage(100f); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.addElement(barImgObj); table.addCell(cell); }