List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:pdf.PDFDesign.java
private PdfPTable createStyle6_4x7Table(List<Item> list) throws DocumentException, IOException { PdfPTable table = new PdfPTable(nColumns); table.setWidthPercentage(100.0f);//from w w w . j a va 2s .c o m for (int i = 0; i < list.size(); i++) { Item item = list.get(i); PdfPTable innerTable = new PdfPTable(1); Paragraph p1 = new Paragraph(); p1.setFont(titleLineFont); String t = item.getTitle(); String[] split = t.split("//"); for (String split1 : split) { p1.add(split1 + "\n"); } PdfPCell innercCell1 = new PdfPCell(p1); innercCell1.setBorder(0); if (t.contains("//")) { innercCell1.setFixedHeight(titleLineFixedHeight); } else { innercCell1.setFixedHeight(15.0f + textFontInc); } innercCell1.setHorizontalAlignment(Element.ALIGN_CENTER); Paragraph p2 = new Paragraph(); p2.setFont(amountAndPriceLabelLineFont); p2.add("Mnostv: " + item.getAmount() + item.getUnit() + "\n"); PdfPCell innercCell2 = new PdfPCell(p2); innercCell2.setLeading(5f, 0f); innercCell2.setBorder(0); innercCell2.setFixedHeight(12.0f); innercCell2.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell innercCell3 = new PdfPCell(createLine3Table(item, 0, 0, 0)); innercCell3.setBorder(0); innercCell3.setLeading(2.0f, 0f); innercCell3.setFixedHeight(67.0f); innercCell3.setHorizontalAlignment(Element.ALIGN_CENTER); Paragraph p4 = new Paragraph(); p4.setFont(unitPriceLineFont); p4.add("Cena za 1" + item.getXUnit() + ": " + item.getUnitPrice() + " " + item.getCurrency()); PdfPCell innercCell4 = new PdfPCell(p4); innercCell4.setBorder(0); innercCell4.setLeading(1f, 0f); innercCell4.setHorizontalAlignment(Element.ALIGN_CENTER); innerTable.addCell(innercCell1); innerTable.addCell(innercCell2); innerTable.addCell(innercCell3); innerTable.addCell(innercCell4); PdfPCell cell = new PdfPCell(innerTable); cell.setFixedHeight(cellHeight); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(BaseColor.GRAY); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } int remainder = list.size() % nColumns; if (remainder != 0) { remainder = nColumns - remainder; } for (int i = 0; i < remainder; i++) { PdfPCell c = new PdfPCell(new Phrase(" ")); c.setBorderColor(BaseColor.GRAY); table.addCell(c); } return table; }
From source file:pdf.PDFDesign.java
private PdfPTable createLine3Table(Item item, int s1, int s2, int s3) throws DocumentException { if (s1 != 0 && s1 != 0 && s3 != 0) { bigPriceNumberFont.setSize(s1);// www . ja va 2 s. c om decimalPriceNumberFont.setSize(s2); decimalPriceNumberFont.setSize(s3); } else { bigPriceNumberFont.setSize(70); } Paragraph p3 = new Paragraph(); p3.setFont(bigPriceNumberFont); p3.add(item.getPrice().substring(0, item.getPrice().length() - 3)); Paragraph p3_2 = new Paragraph(); p3_2.setFont(decimalPriceNumberFont); p3_2.add(item.getPrice().substring(item.getPrice().length() - 2, item.getPrice().length())); Paragraph p3_3 = new Paragraph(); p3_3.setFont(decimalPriceNumberFont); p3_3.add(item.getCurrency()); PdfPTable table = new PdfPTable(2); if (item.getPrice().length() == 6) { table.setWidths(new float[] { 2.8f, 1 }); } else if (item.getPrice().length() == 5) { table.setWidths(new float[] { 1.8f, 1 }); } else { table.setWidths(new float[] { 1.5f, 1 }); } PdfPCell cell = new PdfPCell(p3); cell.setRowspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); if (s1 != 0 && s1 != 0 && s3 != 0) { cell.setLeading(42.0f, 0f); } else { cell.setLeading(55.0f, 0f); } cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(p3_2); cell.setRowspan(1); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(p3_3); cell.setRowspan(1); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); table.addCell(cell); return table; }
From source file:pdf.PDFDesign.java
private PdfPCell createEuroCell(Item item) throws DocumentException, IOException { Font descFont = new Font(droidsans, 12, Font.NORMAL, color); Font unitPriceFont = new Font(droidsans, 10, Font.NORMAL, color); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f);//from w ww . j av a2 s .c om PdfPCell cell; Paragraph p; cell = new PdfPCell(); p = new Paragraph(); p.setFont(descFont); p.add(item.getTitle()); cell.setFixedHeight(28f); cell.setPhrase(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(); p = new Paragraph(); p.setFont(descFont); p.add(item.getAmount() + item.getUnit()); cell.setFixedHeight(16f); cell.setPhrase(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(0); table.addCell(cell); table.addCell(createEuroInnerPrice(item)); cell = new PdfPCell(); p = new Paragraph(); p.setFont(unitPriceFont); p.add("Cena za 1" + item.getXUnit() + ": " + item.getUnitPrice() + item.getCurrency() + "/" + item.getSecondUnitPrice() + item.getSecondCurrency()); cell.setPhrase(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(0); cell.setLeading(2f, 0f); table.addCell(cell); PdfPCell finalCell = new PdfPCell(table); finalCell.setFixedHeight(117.4f); finalCell.setBorderColor(BaseColor.GRAY); return finalCell; }
From source file:pdf.PDFDesign.java
private PdfPCell createEuroInnerInnerPrice(String price, String curr, boolean isFirst) throws DocumentException { Font bigPriceFont = new Font(droidsans, 40, Font.BOLD, color); Font smallPriceFont = new Font(droidsans, 18, Font.NORMAL, color); Font unitFont = new Font(droidsans, 12, Font.NORMAL, color); PdfPTable table = new PdfPTable(2); table.setWidths(new float[] { 3f, 1f }); PdfPCell cell;//from ww w .j a v a2s . com Paragraph para; para = new Paragraph(""); para.setFont(bigPriceFont); if (price.length() >= 4) { para.add(price.substring(0, price.length() - 3)); } cell = new PdfPCell(para); cell.setRowspan(2); cell.setFixedHeight(57f); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); para = new Paragraph(""); para.setFont(smallPriceFont); if (price.length() >= 4) { para.add(price.substring(price.length() - 2, price.length())); } cell = new PdfPCell(para); cell.setRowspan(1); cell.setFixedHeight(35f); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorder(0); table.addCell(cell); para = new Paragraph(); para.setFont(unitFont); para.add(curr); cell = new PdfPCell(para); cell.setRowspan(1); cell.setFixedHeight(22f); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorder(0); table.addCell(cell); PdfPCell finalCell = new PdfPCell(table); finalCell.setBorder(0); /*if (isFirst) { finalCell.setBorder(Rectangle.RIGHT); }*/ return finalCell; }
From source file:pdf.PDFDesign.java
private PdfPCell createEuro_6_Cell(Item item) throws DocumentException { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f);// w ww.j av a 2 s . com PdfPCell cell; Paragraph p; cell = new PdfPCell(); p = new Paragraph(); p.setFont(new Font(droidsans, 13, Font.NORMAL, color)); String t = item.getTitle(); String[] split = t.split("//"); for (String split1 : split) { p.add(split1 + "\n"); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPhrase(p); cell.setColspan(2); cell.setFixedHeight(30f); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(); p = new Paragraph(); p.setFont(new Font(droidsans, 11, Font.NORMAL, color)); p.add(item.getAmount() + "" + item.getUnit()); cell.setPhrase(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); table.addCell(createEuro_6_InnerPrice(item)); cell = new PdfPCell(); p = new Paragraph(); p.setFont(new Font(droidsans, 11, Font.NORMAL, color)); p.add("Cena za 1" + item.getXUnit() + ": " + item.getUnitPrice() + item.getCurrency() + "/" + item.getSecondUnitPrice() + item.getSecondCurrency()); cell.setPhrase(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(0); table.addCell(cell); PdfPCell finalCell = new PdfPCell(table); finalCell.setFixedHeight(cellHeight);//175f finalCell.setBorderColor(BaseColor.GRAY); return finalCell; }
From source file:pdf.PDFDesign.java
private PdfPCell createEuro_6_InnerInnerPrice(String price, String curr, boolean isFirst) throws DocumentException { PdfPTable table = new PdfPTable(2); table.setWidths(new float[] { 3f, 1.2f }); PdfPCell cell;/*w ww .j a va 2 s.c o m*/ Paragraph para; para = new Paragraph(""); para.setFont(new Font(droidsans, 60, Font.BOLD, color)); if (price.length() >= 4) { para.add(price.substring(0, price.length() - 3)); } cell = new PdfPCell(para); cell.setRowspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setLeading(50f, 0f); cell.setBorder(0); table.addCell(cell); para = new Paragraph(""); para.setFont(new Font(droidsans, 28, Font.NORMAL, color)); if (price.length() >= 4) { para.add(price.substring(price.length() - 2, price.length())); } cell = new PdfPCell(para); cell.setRowspan(1); cell.setFixedHeight(32f); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorder(0); table.addCell(cell); para = new Paragraph(); para.setFont(new Font(droidsans, 16, Font.NORMAL, color)); para.add(curr); cell = new PdfPCell(para); cell.setRowspan(1); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorder(0); table.addCell(cell); PdfPCell finalCell = new PdfPCell(table); finalCell.setBorder(0); /*if (isFirst) { finalCell.setBorder(Rectangle.RIGHT); }*/ return finalCell; }
From source file:pdf.PDFmultiple.java
private static void agregarTitulo(Document documento, String titulo) throws DocumentException { Paragraph preface = new Paragraph(); // Agregamos una linea vacia addEmptyLine(preface, 1);/*from ww w . jav a2 s. co m*/ // Escribimos el titulo preface.add(new Paragraph(titulo, catFont)); addEmptyLine(preface, 2); preface.add(new Paragraph( "A continuacion se presenta el desarrollo para la regresin lineal multiple, se muestra la tabla con las operaciones necesarias, algunas variables de gran importancia y la prediccion de las variables.", smallBold)); addEmptyLine(preface, 1); documento.add(preface); }
From source file:pdf.PDFsimple.java
private static void agregarTitulo(Document documento, String titulo) throws DocumentException { Paragraph preface = new Paragraph(); // Agregamos una linea vacia addEmptyLine(preface, 1);/*w w w. jav a 2 s . c o m*/ // Escribimos el titulo preface.add(new Paragraph(titulo, catFont)); addEmptyLine(preface, 2); preface.add(new Paragraph( "A continuacion se presenta el desarrollo para la regresin lineal simple, se muestra la tabla con las operaciones necesarias, algunas variables de gran importancia y la prediccion de las variables.", smallBold)); addEmptyLine(preface, 1); documento.add(preface); }
From source file:pdf.PDFtexto.java
private static void agregarTitulo(Document documento, String titulo) throws DocumentException { Paragraph preface = new Paragraph(); // Agregamos una linea vacia addEmptyLine(preface, 1);//from ww w . ja v a 2 s .c o m // Escribimos el titulo preface.add(new Paragraph(titulo, catFont)); addEmptyLine(preface, 2); if (titulo.equals("Mineria de Texto")) { preface.add(new Paragraph( "A continuacion se presentan las palabras recopiladas a partir de la mineria de texto.", smallBold)); } addEmptyLine(preface, 1); documento.add(preface); }
From source file:PDF.PDFTrackGenerator.java
License:Open Source License
/** * Metda generateTrackPDFA4 sli na samotn vygenerovanie PDF dokumentu trasy na formt A4. * @param lineWeight - hrbka ?iary trasy na mape * @param color - farba ?iary trasy na mape * @param width - rka mapy//from w w w .j ava2 s . c o m * @param height - vka mapy * @param scale - klovacia kontanta mapy (n x rozlenie mapy) * @param startDate - dtum a ?as prvho bodu trasy * @param endDate - dtum a ?as poslednho bodu trasy * @param activity - aktivita trasy * @param user - pouvate (majite) trasy */ public void generateTrackPDFA4(int lineWeight, String color, int width, int height, int scale, String startDate, String endDate, String activity, String user) { try { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(path + fileName + ".pdf")); doc.open(); Font nadpisFont = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Font detailyFont = new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL); Paragraph nadpisPar = new Paragraph(); nadpisPar.setAlignment(Element.ALIGN_CENTER); Phrase nadpis = new Phrase(fileName, nadpisFont); nadpisPar.add(nadpis); nadpisPar.add(""); doc.add(nadpisPar); doc.add(Chunk.NEWLINE); PdfPTable tabulka = new PdfPTable(2); tabulka.setWidthPercentage(100); float[] columnWidth = { 6f, 4f }; tabulka.setWidths(columnWidth); StaticMapResolver res = new StaticMapResolver(loader); String mapUrl = res.getStaticMapTrackURLWithMultimedia(lineWeight, color, width, height, scale); Image img = Image.getInstance(new URL(mapUrl)); //img.scalePercent(50); PdfPCell riadokSObr = new PdfPCell(img, true); riadokSObr.setBorder(Rectangle.NO_BORDER); riadokSObr.setPaddingBottom(10f); PdfPCell riadokSText = new PdfPCell(new Phrase("Description: " + loader.getTrackDescription() + "\n\n\nTrack activity: " + activity.substring(4) + "\n\n\nStart place: " + loader.getStartAddress() + "\n\n\nEnd Place: " + loader.getEndAddress() + "\n\n\nTrack length: " + loader.getLength() + " km\n\n\nMin elevation: " + loader.getMinElevation() + " m\n\n\nMax elevation: " + loader.getMaxElevation() + " m\n\n\nHeight difference: " + loader.getHeightDiff() + " m\n\n\nStart: " + startDate + "\n\n\nEnd: " + endDate + "\n\n\nDuration: " + loader.getDuration(), detailyFont)); riadokSText.setBorder(Rectangle.NO_BORDER); riadokSText.setPaddingLeft(20f); riadokSText.setPaddingTop(5f); riadokSText.setPaddingBottom(10f); tabulka.addCell(riadokSObr); tabulka.addCell(riadokSText); doc.add(tabulka); //doc.add(new Phrase("\n", detailyFont)); PdfPTable obrTabulka = new PdfPTable(3); obrTabulka.setWidthPercentage(100); ArrayList<String> goodFiles = new ArrayList<String>(); for (int i = 0; i < loader.getMultimediaFiles().size(); i++) { if (!loader.getMultimediaFiles().get(i).getPath().startsWith("YTB")) { String extension = loader.getMultimediaFiles().get(i).getPath().substring( loader.getMultimediaFiles().get(i).getPath().lastIndexOf("."), loader.getMultimediaFiles().get(i).getPath().length()); String newPath = loader.getMultimediaFiles().get(i).getPath().substring(0, loader.getMultimediaFiles().get(i).getPath().lastIndexOf(".")) + "_THUMB" + extension; goodFiles.add(newPath); } } if (!goodFiles.isEmpty()) { int freeCount = 9; if (goodFiles.size() <= 9) { for (int i = 0; i < goodFiles.size(); i++) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } for (int i = 0; i < 9 - goodFiles.size(); i++) { PdfPCell tempCell = new PdfPCell(); tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } else if (goodFiles.size() <= 18) { for (int i = 0; i < 9; i++) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } else { for (int i = 0; i < (goodFiles.size() % 9); i++) { goodFiles.remove(goodFiles.size() - 1 - i); } int counting = (goodFiles.size() / 9); for (int i = 0; i < goodFiles.size(); i = i + counting) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); freeCount--; } for (int i = 0; i < freeCount; i++) { PdfPCell tempCell = new PdfPCell(); tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } } doc.add(obrTabulka); Font lastFont = new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC); Phrase lastText = new Phrase("This PDF document was generated by gTrax app for user " + user, lastFont); doc.add(lastText); doc.close(); } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot CREATE PDF for track " + fileName + " for user " + user + " !!!"); System.out.println("pruser"); } }