List of usage examples for com.itextpdf.text Font Font
public Font(final FontFamily family, final float size)
From source file:com.microware.intrahealth.Createpdf2.java
@SuppressLint("SdCardPath") public boolean write(Context context, String fname, String[] Header, ArrayList<HashMap<String, String>> data, String[] Page2, int Flag) throws Exception { try {/* w ww . j a va 2 s . c o m*/ // file = new File(Environment.getExternalStorageDirectory()+IIHSPdf+ "/"+fname+".pdf"); this.context = context; g = (Global) context.getApplicationContext(); BaseFont urName = BaseFont.createFont("assets/FreeSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); urFontName = new Font(urName, 12); urName1 = FontFactory.getFont("assets/mangal.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // urFontName = new Font(urName, 12); sHeader[0] = context.getResources().getString(R.string.hrpreport); sHeader[1] = context.getResources().getString(R.string.anmname) + " " + g.getsGlobalANMName() + " " + context.getResources().getString(R.string.distname); sHeader[2] = context.getResources().getString(R.string.Identificationcode); sHeader2[0] = context.getResources().getString(R.string.Identificationcode1); sHeader2[1] = context.getResources().getString(R.string.totalhrp); sHeader2[2] = context.getResources().getString(R.string.totalcheckup); sHeader2[3] = context.getResources().getString(R.string.anmsign); catFont2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); if (Flag == 2) { catFont = new Font(urName, 16, Font.BOLD); catFont1 = new Font(urName, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(urName, 14); smallBold = new Font(urName, 12, Font.BOLD, BaseColor.WHITE); } else { catFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD); catFont1 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(Font.FontFamily.TIMES_ROMAN, 14); smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.WHITE); } String fpath = "/sdcard/msakhi/Pdf"; File path = new File(fpath); File file = new File(path, fname + ".pdf"); if (!path.exists()) { path.mkdirs(); if (!file.exists()) { file.createNewFile(); } } else { if (!file.exists()) { file.createNewFile(); } } // Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); // Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); Document document = new Document(A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(file.getAbsoluteFile())); document.open(); // addMetaData(document); // addTitlePage(document); addContent(document, Header, data, sHeader2, Flag); document.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:com.microware.intrahealth.Createpdfall.java
@SuppressLint("SdCardPath") public boolean write(String fname, String[] Header1, String[] Page1, String[] Page1Value, String heading1, String Page1Remark,/* www . jav a2 s .c o m*/ String[] Header2, String[] Page2_1, String[] Page2_1source, String[] Page2_1value, String[] Page2_2, String[] Page2_2source, String[] Page2_2value, String[] Page2_3, String[] Page2_3source, String[] Page2_3value, String heading2, String heading3, String heading4, String heading5, String Remark2Value, String[] Header3, String[] Page31, String[] Page3Census1, String[] Page3Value1, String[] Page32, String[] Page3Census2, String[] Page3Value2, String heading6, String heading7, String heading8, String Page3Remark, String[] Header4, String[] Page4_1, String[] Page4Value1, String[] Page4_2, String[] Page4Value2, String[] Page4_3, String[] Page4Value3, String heading9, String heading10, String heading11, String heading12, String Page4Remark1, String Page4Remark3, String[] Header5, String[] Page5Value1, String[] Page5Value2, String[] Page5Value3, String[] Page5Value4, String[] Page5_2, String[] Page5Value5, String[] Page5_3, String[] Page5Value6, String text5, String value5, String heading13, String heading14, String heading15, String Page5Remark1, String Page5Remark2, String[] Header6, String[] Page6Value1, String[] Page6Value2, String[] Page6Value3, String[] Page6Value4, String text6, String value6, String heading16, String[] Header7_1, String[] Page7Value1, String[] Page7Value2, String[] Page7Value3, String[] Page7Value4, String[] Page7Value5, String[] Header7_2, String[] Page7Value6, String[] Page7Value7, String[] Page7Value8, String[] Page7Value9, String[] Page7Value10, String[] Page7Value11, String text7_1, String value7_1, String text7_2, String value7_2, String heading17, String heading18, String heading19, String pdf1, String pdf2, int Flag) throws Exception { try { // file = new File(Environment.getExternalStorageDirectory()+IIHSPdf+ "/"+fname+".pdf"); BaseFont urName = BaseFont.createFont("assets/baamini.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); urFontName = new Font(urName, 12); catFont2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); if (Flag == 2) { catFont = new Font(urName, 16, Font.BOLD); catFont1 = new Font(urName, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(urName, 14); smallBold = new Font(urName, 12, Font.BOLD, BaseColor.WHITE); } else { catFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD); catFont1 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(Font.FontFamily.TIMES_ROMAN, 14); smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.WHITE); } String fpath = "/sdcard/IIHS/Pdfs"; File path = new File(fpath); File file = new File(path, fname + ".pdf"); if (!path.exists()) { path.mkdirs(); if (!file.exists()) { file.createNewFile(); } } else { if (!file.exists()) { file.createNewFile(); } } // Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); // Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file.getAbsoluteFile())); document.open(); // addMetaData(document); // addTitlePage(document); addContent(document, Header1, Page1, Page1Value, heading1, Page1Remark, Header2, Page2_1, Page2_1source, Page2_1value, Page2_2, Page2_2source, Page2_2value, Page2_3, Page2_3source, Page2_3value, heading2, heading3, heading4, heading5, Remark2Value, Header3, Page31, Page3Census1, Page3Value1, Page32, Page3Census2, Page3Value2, heading6, heading7, heading8, Page3Remark, Header4, Page4_1, Page4Value1, Page4_2, Page4Value2, Page4_3, Page4Value3, heading9, heading10, heading11, heading12, Page4Remark1, Page4Remark3, Header5, Page5Value1, Page5Value2, Page5Value3, Page5Value4, Page5_2, Page5Value5, Page5_3, Page5Value6, text5, value5, heading13, heading14, heading15, Page5Remark1, Page5Remark2, Header6, Page6Value1, Page6Value2, Page6Value3, Page6Value4, text6, value6, heading16, Header7_1, Page7Value1, Page7Value2, Page7Value3, Page7Value4, Page7Value5, Header7_2, Page7Value6, Page7Value7, Page7Value8, Page7Value9, Page7Value10, Page7Value11, text7_1, value7_1, text7_2, value7_2, heading17, heading18, heading19, pdf1, pdf2, Flag); document.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:com.northcoders.controller.BookingReportsController.java
@FXML private void generatePdf() throws Exception { BaseFont bf;// www. j a va2s.c o m Font font; try { conditions = "Filtered by: Start Date:2017-03-15 End Date:2017-03-28"; /* Step-2: Initialize PDF documents - logical objects */ Document my_pdf_report = new Document(PageSize.LETTER.rotate()); PdfWriter.getInstance(my_pdf_report, new FileOutputStream("pdf_booking_report.pdf")); my_pdf_report.open(); //we have four columns in our table PdfPTable my_report_table = new PdfPTable(6); //create a cell object PdfPCell table_cell; bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); font = new Font(bf, 16); my_pdf_report.add(new Paragraph("Administration Report", font)); font = new Font(bf, 12); my_pdf_report.add(new Paragraph("Filter applied:" + conditions, font)); my_pdf_report.add(new Paragraph(" ")); table_cell = new PdfPCell(new Phrase("Customer")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Start Date")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("End Date")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Room")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Amount")); my_report_table.addCell(table_cell); table_cell = new PdfPCell(new Phrase("Transactions")); my_report_table.addCell(table_cell); for (Booking item : bookings) { String customer_b = item.getCustomerId().getId() + " " + item.getCustomerId().getFirstName() + " " + item.getCustomerId().getLastName(); table_cell = new PdfPCell(new Phrase(customer_b)); my_report_table.addCell(table_cell); String date_start_b = dateToStr(item.getStartDate()); table_cell = new PdfPCell(new Phrase(date_start_b)); my_report_table.addCell(table_cell); String date_end_b = dateToStr(item.getEndDate()); table_cell = new PdfPCell(new Phrase(date_end_b)); my_report_table.addCell(table_cell); String room_b = String.valueOf(item.getRoomId().getRoomNumber()); table_cell = new PdfPCell(new Phrase(room_b)); my_report_table.addCell(table_cell); String price_b = String.format("%1$,.2f", item.getTotalPrice()); table_cell = new PdfPCell(new Phrase(price_b)); my_report_table.addCell(table_cell); String transaction_b = ""; for (PaymentTransaction trans : item.getPaymentTransactionList()) { transaction_b += String.format("%1$,.2f", trans.getAmount()) + " " + trans.getPaymentTypeId().getDescription() + "\n"; } table_cell = new PdfPCell(new Phrase(transaction_b)); my_report_table.addCell(table_cell); } /* Attach report table to PDF */ my_pdf_report.add(my_report_table); my_pdf_report.add(new Paragraph(" ")); font = new Font(bf, 6); my_pdf_report.add(new Paragraph("Report Time:" + dateTimeToStr(new Date()))); my_pdf_report.close(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java
License:Open Source License
public static InterviewCandidateMaterial pdf(HttpServletRequest request, AddressBook addressbook) { // TODO Auto-generated method stub log.log(Level.INFO, "ApplicationFormPDFMaintenance --> pdf "); Document document = new Document(PageSize.A4, 50, 50, 50, 50); //Font myAdobeTypekit = FontFactory.getFont(request.getRealPath(File.separator)+"resources"+File.separator+"HDZB_35.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); try {// w ww.jav a 2 s. com //String fontPath = "C:/Windows/Fonts"; String fontPath = request.getRealPath("/") + "resources" + File.separator + "hxb-meixinti"; File f2 = new File(fontPath + "/hxb-meixinti.ttf"); BaseFont bf1 = null; if (f2.exists()) { bf1 = BaseFont.createFont(fontPath + "/hxb-meixinti.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } else { f2 = new File(fontPath + "/hxb-meixinti.ttf"); if (f2.exists()) { System.out.println("File existed"); bf1 = BaseFont.createFont(fontPath + "hxb-meixinti.ttf", BaseFont.IDENTITY_V, BaseFont.EMBEDDED); } else { bf1 = BaseFont.createFont(FontManager.getFontPath(true) + "/hxb-meixinti.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } } Font normalFontCH = new Font(bf1, 15); String fileName = request.getRealPath("/") + "resources" + File.separator + "upload" + File.separator; DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = new Date(); String time = (d1.getTime() + "").trim(); String str = df.format(new Date()) + time; PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName + "ApplicationForm_" + str + ".pdf")); InterviewCandidateMaterial material = new InterviewCandidateMaterial(); material.setMaterialFileName("ApplicationForm_" + str + ".pdf"); material.setCandidateCode(Integer.parseInt(request.getParameter("candidateCode"))); material.setInterviewCode(Integer.parseInt(request.getParameter("interviewCode"))); // PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E://applicatonForm2.pdf")); document.open(); addTitle(document, writer, "formHeaderTitle", "Application Form"); document = personalInformation(document, writer, addressbook, normalFontCH); document = familyInformation(document, writer, addressbook); document = workExperience(document, writer, addressbook); document = Education(document, writer, addressbook); document = personalCertification(document, writer, addressbook); document = ESingnature(document, writer, addressbook); document.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); File file = new File(fileName + "ApplicationForm_" + str + ".pdf"); FileInputStream fis = new FileInputStream(file); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); //no doubt here is 0 } material.setFormContent(bos.toByteArray()); material.setCreatedDate(new Date()); material.setMaterialDescrption("AppicationForm"); // applicationForm.setFormContent(bos.toByteArray()); return material; } catch (Exception e) { log.log(Level.INFO, "ApplicationFormPDFMaintenance --> pdf --> Exception " + e.getMessage()); e.printStackTrace(); e.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString()); } return null; }
From source file:com.softwaremagico.tm.pdf.complete.characteristics.CharacteristicColumn.java
License:Open Source License
private PdfPCell createContent(CharacterPlayer characterPlayer, List<CharacteristicDefinition> content) { float[] widths = { 3f, 1f, 0.1f }; PdfPTable table = new PdfPTable(widths); BaseElement.setTablePropierties(table); table.getDefaultCell().setBorder(0); for (CharacteristicDefinition characteristic : content) { Paragraph paragraph = new Paragraph(); paragraph.add(new Paragraph(getTranslator().getTranslatedText(characteristic.getId()), new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE))); paragraph.add(new Paragraph(" (", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE))); if (characterPlayer == null) { paragraph.add(new Paragraph(GAP, new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE))); } else {// w w w . j av a 2 s.c o m paragraph.add( new Paragraph(characterPlayer.getStartingValue(characteristic.getCharacteristicName()) + "", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme .getHandWrittingFontSize(FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE)))); } paragraph.add(new Paragraph(")", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE))); PdfPCell characteristicTitle = new PdfPCell(paragraph); characteristicTitle.setBorder(0); characteristicTitle.setMinimumHeight(ROW_WIDTH / content.size()); table.addCell(characteristicTitle); // Rectangle if (characterPlayer == null) { table.addCell(createRectangle()); } else { table.addCell(createRectangle(characterPlayer.getValue(characteristic.getCharacteristicName()) + getCharacteristicSpecialRepresentation(characterPlayer, characteristic.getCharacteristicName()))); } // Margin PdfPCell margin = new PdfPCell(); margin.setBorder(0); table.addCell(margin); } PdfPCell cell = new PdfPCell(); cell.addElement(table); BaseElement.setCellProperties(cell); return cell; }
From source file:com.softwaremagico.tm.pdf.complete.characteristics.CharacteristicsTableFactory.java
License:Open Source License
public static PdfPTable getCharacteristicsBasicsTable(CharacterPlayer characterPlayer) { float[] widths = { 1f, 1f, 1f, 1f }; PdfPTable table = new PdfPTable(widths); setTablePropierties(table);//from w w w .j a v a 2 s. c o m PdfPCell separator = createSeparator(); separator.setColspan(widths.length); table.addCell(separator); Phrase content = new Phrase(getTranslator().getTranslatedText("characteristics").toUpperCase(), new Font(FadingSunsTheme.getTitleFont(), FadingSunsTheme.TITLE_FONT_SIZE)); PdfPCell titleCell = new PdfPCell(content); setCellProperties(titleCell); titleCell.setColspan(widths.length); titleCell.setHorizontalAlignment(Element.ALIGN_CENTER); titleCell.setFixedHeight(30); table.addCell(titleCell); table.getDefaultCell().setPadding(0); for (CharacteristicType type : CharacteristicType.values()) { try { table.addCell(new CharacteristicColumn(characterPlayer, type, CharacteristicsDefinitionFactory.getInstance().getAll(type, Translator.getLanguage()))); } catch (NullPointerException npe) { PdfExporterLog.errorMessage(CharacteristicsTableFactory.class.getName(), npe); } } return table; }
From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java
License:Open Source License
public static PdfPCell getCell(String text, int border, int colspan, int align, BaseColor color, BaseFont font, float fontSize) { if (text == null) { text = ""; }/*from w w w . jav a 2 s.c o m*/ Phrase content = new Phrase(text, new Font(font, fontSize)); PdfPCell cell = new PdfPCell(content); cell.setColspan(colspan); cell.setBorderWidth(border); cell.setHorizontalAlignment(align); cell.setBackgroundColor(color); return cell; }
From source file:com.softwaremagico.tm.pdf.complete.elements.CustomPdfTable.java
License:Open Source License
protected PdfPCell createCompactTitle(String title, int fontSize) { Font font = new Font(FadingSunsTheme.getTitleFont(), fontSize); Phrase content = new Phrase(title, font); PdfPCell titleCell = new PdfPCell(content); titleCell.setColspan(getColumnWidths().length); titleCell.setHorizontalAlignment(Element.ALIGN_CENTER); titleCell.setBorder(0);// www. j a v a 2 s.com return titleCell; }
From source file:com.softwaremagico.tm.pdf.complete.elements.CustomPdfTable.java
License:Open Source License
protected PdfPCell createRectangle(String value) { if (value == null) { return createRectangle(); }/*from w ww .j a va2 s. c om*/ PdfPCell box = new PdfPCell(new Paragraph(value, new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.HANDWRITTING_DEFAULT_FONT_SIZE))); box.setVerticalAlignment(Element.ALIGN_MIDDLE); box.setHorizontalAlignment(Element.ALIGN_CENTER); box.setMinimumHeight(15); box.setBorder(0); box.setCellEvent( new CellCompleteBoxEvent(new Border[] { Border.TOP, Border.BOTTOM, Border.LEFT, Border.RIGHT })); return box; }
From source file:com.softwaremagico.tm.pdf.complete.elements.LateralHeaderPdfPTable.java
License:Open Source License
protected PdfPCell createLateralVerticalTitle(String title, int rowspan) { Font font = new Font(FadingSunsTheme.getTitleFont(), getTitleFontSize()); font.setColor(BaseColor.WHITE);//from w w w .j av a 2 s. c o m Phrase content = new Phrase(title, font); PdfPCell titleCell = new PdfPCell(content); titleCell.setPadding(0); titleCell.setRowspan(rowspan); titleCell.setRotation(90); titleCell.setHorizontalAlignment(Element.ALIGN_CENTER); // titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE); titleCell.setBackgroundColor(BaseColor.BLACK); return titleCell; }