List of usage examples for com.itextpdf.layout Document add
@Override
public Document add(IBlockElement element)
From source file:quiz.student.result.NoOfTestTakenController.java
/** * This method exports the statistics to pdf * @param e ActionEvent//from ww w .j a v a 2s . com */ @FXML public void viewStats(ActionEvent e) { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().add(new ExtensionFilter("PDF files", "*.pdf")); File file = chooser.showSaveDialog(application.stage); if (file != null) { try { WritableImage img = Display.snapshot(null, null); ImageData imgData = ImageDataFactory.create(SwingFXUtils.fromFXImage(img, null), null); com.itextpdf.layout.element.Image pdfImg = new com.itextpdf.layout.element.Image(imgData); PdfWriter writer = new PdfWriter(new FileOutputStream(file)); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); doc.add(pdfImg); doc.close(); } catch (Exception exc) { exc.printStackTrace(); } } }
From source file:ru.waytosky.itext.Main.java
public static void main(String[] args) throws FileNotFoundException, MalformedURLException { // Document document = new Document(PageSize.A4, 20, 20, 20, 20); // PdfWriter.getInstance(document, new FileOutputStream("C:/test.pdf")); // document.open(); // Image image = Image.getInstance(getClass().getResource("/logo.png")); // document.add(image); // document.close(); //Initialize PDF writer String dest = "hello.pdf"; PdfWriter writer = new PdfWriter(dest); //Initialize PDF document PdfDocument pdf = new PdfDocument(writer); // Initialize document Document document = new Document(pdf); //Add paragraph to the document Image image = new Image(ImageDataFactory.create("darksouls.jpg")); // Image.getInstance(getClass().getResource("/logo.png")); document.add(image); //Close document document.close();/*from www . j a va 2 s .co m*/ }
From source file:Utils.PdfUtil.java
private void addTitle(Document document) throws IOException { Style styleTitle = new Style(); styleTitle.setFont(mCommonFont).setFontSize(20).setTextAlignment(TextAlignment.CENTER) .setHorizontalAlignment(HorizontalAlignment.CENTER); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); document.add(new Paragraph("Ha ?n Thanh Ton - Ngy: " + sdf.format(System.currentTimeMillis())) .addStyle(styleTitle));//from www.j a v a2 s . c o m }
From source file:Utils.PdfUtil.java
private void addContent(Document document) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Paragraph paragraphCustomer = new Paragraph(); paragraphCustomer.add(new Text("Khch hng ").setFont(mCommonFont)); com.itextpdf.layout.element.List listCustomer = new com.itextpdf.layout.element.List().setSymbolIndent(12) .setListSymbol("\u2022").setFont(mCommonFont); listCustomer.add(new ListItem("H? tn: " + mCustomer.getFullname())) .add(new ListItem("Chng minh nhn dn: " + mCustomer.getIdentityCode())) .add(new ListItem("S in thoi: " + mCustomer.getPhoneNumber())); listCustomer.setMarginLeft(30).setFont(mCommonFont); Room objRoom = (new ModelRoom()).getItemById(mRoomStatus.getIdRoom()); Paragraph paragraphRoom = new Paragraph(); paragraphRoom.add(new Text("Phng").setFont(mCommonFont)); com.itextpdf.layout.element.List listRoom = new com.itextpdf.layout.element.List().setSymbolIndent(12) .setListSymbol("\u2022").setFont(mCommonFont); listRoom.add(new ListItem("Tn phng: " + objRoom.getRoomName())) .add(new ListItem("Loi phng: " + Constant.ROOM_TYPE_NAME[objRoom.getType()])) .add(new ListItem("Gi: " + CommonFunction.convertDoubleToMoney(objRoom.getPrice()) + "")) .add(new ListItem("Ngy n: " + sdf.format(mRoomStatus.getDateCome()))) .add(new ListItem("Ngy i: " + sdf.format(mRoomStatus.getDateLeave()))); listRoom.setMarginLeft(30).setFont(mCommonFont); Paragraph paragraphService = new Paragraph(); paragraphService.add(new Text("Dch v").setFont(mCommonFont)); Table table = new Table(new float[] { 10f, 7f, 5f, 5f, 7f }); table.setWidthPercent(100).setTextAlignment(TextAlignment.CENTER) .setHorizontalAlignment(HorizontalAlignment.CENTER); String[] header = { "Tn dch v", "Gi ti?n", "S lng", "Ngy s dng" }; for (int i = 0, k = header.length; i < k; i++) { Cell cellHeader = new Cell(); cellHeader.add(header[i]);/*from w w w . j a va 2 s.co m*/ cellHeader.setNextRenderer(new RoundedCornersCellRenderer(cellHeader)); cellHeader.setPadding(5).setBorder(Border.NO_BORDER); table.addHeaderCell(cellHeader); } double total = 0; for (CustomerService objCustomerService : mListCustomerService) { total += (objCustomerService.getPrice() * objCustomerService.getNumber()); for (int i = 0; i < 4; i++) { Cell cell = new Cell(); switch (i) { case 0: cell.add(objCustomerService.getServiceName()); break; case 1: cell.add(CommonFunction.convertDoubleToMoney(objCustomerService.getPrice()) + ""); break; case 2: cell.add(objCustomerService.getNumber() + ""); break; case 3: cell.add(sdf.format(objCustomerService.getDateUsed())); break; } table.addCell(cell); } } Cell cellFooter = new Cell(1, 3); cellFooter.add("Tng ti?n: "); table.addCell(cellFooter); cellFooter = new Cell(); cellFooter.add(CommonFunction.convertDoubleToMoney(total) + ""); table.addCell(cellFooter); document.add(paragraphCustomer).add(listCustomer); document.add(paragraphRoom).add(listRoom); document.add(paragraphService).add(table); }
From source file:Utils.PdfUtil.java
private void addFooter(Document document) { Paragraph paragraph = new Paragraph("Khch hng ").setTextAlignment(TextAlignment.LEFT) .setUnderline().add("Nhn vin").setTextAlignment(TextAlignment.RIGHT).setUnderline() .setFont(mCommonFont);//from ww w . ja va 2 s. co m document.add(paragraph); paragraph.addStyle(new Style().setFont(mCommonFont).setTextAlignment(TextAlignment.LEFT) .setHorizontalAlignment(HorizontalAlignment.LEFT).setUnderline()); document.add(paragraph); }
From source file:wbs.jsf1.pdf.LottoReceiptBean.java
/** * Block f. Angaben zur Ziehungsteilnahme * ======================================= * /*from w ww. j a v a2s . co m*/ * Style : Schriftart: Normal Ausrichtung:zentriert * * Format : * * 1) <Lottoschein.TIPS> * 2) <Superzahl> * 3) <Losnummer> <Super6 NEIN/JA> * 4) <Spiel77 NEIN/JA> * 5) <Spieltag> * 6) <Laufzeit> <von> * 7) <bis> * ... * * @param document * @param font * @param bold * @throws MalformedURLException */ private void createZiehungsblock(Document document, PdfFont font, PdfFont bold) throws MalformedURLException { document.add(getHeaderTable()); // -- Lottozahlen auflisten -- // 1) <Lottoschein.TIPS> // 2) <Superzahl> document.add(getZiehungsDatenTable(font, bold)); // --- Losnummern --- // 2) <Superzahl> // 3) <Losnummer> <Super6 NEIN/JA> // 4) <Spiel77 NEIN/JA> document.add(getLosnummerTable(font, bold)); // --- Spieltage --- // 5) <Spieltag> document.add(getSpieltageTable(font, bold)); // --- Laufzeit --- // 6) <Laufzeit> <von> // 7) <bis> document.add(getLaufzeitTable(font, bold)); // --- Rechnungsbetrage d. Quittung --- document.add(getBetragTable(font, bold)); }
From source file:wbs.jsf1.pdf.LottoReceiptBean0.java
public byte[] createPdfFrom(Lottoschein lottoschein) { try {/*from w w w . ja v a 2 s. c o m*/ zahlen = lottoschein; ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); PdfWriter writer = new PdfWriter(pdfStream); PdfDocument pdf = new PdfDocument(writer); PageSize pageSize = new PageSize(PageSize.A6); Document document = new Document(pdf, pageSize); document.setMargins(20, 20, 40, 20); PdfFont font = PdfFontFactory.createFont(FontConstants.HELVETICA); PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD); // Header document.add(getHeaderTable()); // Lottozahlen auflisten document.add(getZiehungsDatenTable(font, bold)); // Losnummer document.add(getLosnummerTable(font, bold)); // Spieltage document.add(getSpieltageTable(font, bold)); // Laufzeit document.add(getLaufzeitTable(font, bold)); // Betrag document.add(getBetragTable(font, bold)); document.close(); LOG.log(Level.INFO, "PDF succesfully created."); return pdfStream.toByteArray(); } catch (IOException ex) { Logger.getLogger(LottoReceiptBean0.class.getName()).log(Level.SEVERE, "pdf creation problem", ex); } return null; }