List of usage examples for com.lowagie.text Paragraph setSpacingBefore
public void setSpacingBefore(float spacing)
From source file:jmemorize.core.io.PdfRtfBuilder.java
License:Open Source License
private static void writeCategoryHeader(Document doc, Category category) throws DocumentException { Chunk chunk = new Chunk(category.getPath()); chunk.setFont(new Font(Font.HELVETICA, 12, Font.BOLD)); Paragraph paragraph = new Paragraph(chunk); paragraph.setSpacingBefore(1f); doc.add(paragraph);//w w w. j a v a 2 s. c om }
From source file:managedbean.afos.FlightDutyBacking.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();/* w w w .ja v a 2 s . co m*/ pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "logo.png"; Image logoImg = Image.getInstance(logo); logoImg.scalePercent(20f); SimpleDateFormat sdf = new SimpleDateFormat("E, dd/MM/yyyy 'at' hh:mm:ss a"); Font titleFont = new Font(); Font subtitleFont = new Font(); titleFont.setSize(16); titleFont.setStyle(Font.BOLD); subtitleFont.setSize(12); subtitleFont.setStyle(Font.BOLD); Paragraph title = new Paragraph(flightReport.getType() + " Duty Report", titleFont); title.setAlignment(Element.ALIGN_CENTER); title.setSpacingAfter(12f); Paragraph subTitle1 = new Paragraph("Flight Information:", subtitleFont); subTitle1.setSpacingAfter(8f); Paragraph subTitle2 = new Paragraph(flightReport.getType() + " Checklist:", subtitleFont); subTitle2.setSpacingBefore(12f); subTitle2.setSpacingAfter(12f); com.lowagie.text.List list = new com.lowagie.text.List(true, 15); list.setLettered(true); list.add("Flight: " + selectedFlightSchedule.getFlight().getFlightNo()); list.add("Return Flight: " + selectedFlightSchedule.getFlight().getReturnedFlight().getFlightNo()); Airport departure, arrival; departure = selectedFlightSchedule.getLeg().getDepartAirport(); arrival = selectedFlightSchedule.getLeg().getArrivalAirport(); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(departure))); list.add("Departure Time: " + sdf.format(selectedFlightSchedule.getDepartDate()) + " (" + departure.getCity().getCityName() + " Time)"); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(arrival))); list.add("Arrival Time: " + sdf.format(selectedFlightSchedule.getArrivalDate()) + " (" + arrival.getCity().getCityName() + " Time)"); list.add("Origin: " + departure.getCity().getCityName() + " (" + departure.getAirportName() + ")"); list.add("Destination: " + arrival.getCity().getCityName() + " (" + arrival.getAirportName() + ")"); pdf.add(logoImg); pdf.add(new Paragraph(" ")); pdf.add(title); pdf.add(subTitle1); pdf.add(list); pdf.add(subTitle2); pdf.setMargins(72, 72, 72, 72); pdf.addAuthor("Merlion Airline"); pdf.addCreationDate(); sdf.applyPattern("dd/MM/yyyy_hh:mm:ss"); pdf.addTitle("Post-Flight Duty Report_" + selectedFlightSchedule.getFlight().getFlightNo() + "_" + sdf.format(selectedFlightSchedule.getDepartDate())); }
From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java
License:Apache License
Element createParagraphElement(String paragraphTitle, String iconName) throws DocumentException, IOException { final Paragraph paragraph = new Paragraph("", paragraphTitleFont); paragraph.setSpacingBefore(5); paragraph.setSpacingAfter(5);/*from w ww.jav a 2s .c o m*/ if (iconName != null) { paragraph.add(new Chunk(getParagraphImage(iconName), 0, -5)); } final Phrase element = new Phrase(' ' + paragraphTitle, paragraphTitleFont); element.setLeading(12); paragraph.add(element); // chapter pour avoir la liste des signets final ChapterAutoNumber chapter = new ChapterAutoNumber(paragraph); // sans numro de chapitre chapter.setNumberDepth(0); chapter.setBookmarkOpen(false); chapter.setTriggerNewPage(false); return chapter; }
From source file:net.scs.reader.virtualprinter.PdfPrinter.java
License:Open Source License
private void printCurrentPage() { // first create a new page pdfdoc.newPage();//from w ww . j a v a 2 s . c o m pdfdoc.setPageCount(currentPage++); boolean emptypage = true; // second write the content for (VirtualLine currentLine : getLinesOnCurrentPage()) { emptypage = false; Paragraph p = new Paragraph(); p.setSpacingAfter(0.0f); p.setSpacingBefore(0.0f); p.setExtraParagraphSpace(0.0f); p.setLeading(leading); currentLine.position(0); StringBuilder sb = new StringBuilder(); boolean isbold = false; if (!currentLine.hasNext()) { // empty lines need at least one character sb.append(printerConfig.NL); } while (currentLine.hasNext()) { final EnhancedCharacter echar = currentLine.next(); // Workaround, replace 'normal spaces' with 'non-breaking-spaces' // <a href="http://sourceforge.net/tracker/?func=detail&aid=2866002&group_id=15255&atid=315255"> // Multiline paragraph, leading spaces are ignored problem - ID: 2866002 // </a> char c = (echar.getChar() == SP) ? NBSP : echar.getChar(); if (isbold == echar.isBold()) { sb.append(c); } else { p.add(new Chunk(sb.toString(), (isbold) ? fontbold : font)); sb = new StringBuilder(); sb.append(c); isbold = !isbold; // flip it } } p.add(new Chunk(sb.toString(), (isbold) ? fontbold : font)); try { pdfdoc.add(p); } catch (DocumentException e) { // transform into RuntimeException throw new RuntimeException(e); } } if (emptypage) { try { pdfdoc.add(new Paragraph(Character.toString(NBSP))); } catch (DocumentException e) { // transform into RuntimeException throw new RuntimeException(e); } } }
From source file:optika.sql.java
public void eksportoNePdf(String id) { Document document = new Document() { };/* w ww . j a v a2s.c o m*/ try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("receta.pdf")); document.open(); document.setPageSize(PageSize.A3); Image img = Image.getInstance("receta.jpg"); img.setAbsolutePosition(450f, 10f); img.scaleToFit(600, 849); img.setAlignment(Image.LEFT | Image.ALIGN_BOTTOM | Image.ALIGN_BASELINE); img.setAbsolutePosition(0, 0); document.add(img); String[][] receta = merrReceten("select * from recetat where id=" + parseInt(id) + ";"); String[][] tabela = merrReceten("select * from tabela where recetat_id=" + parseInt(id) + ";"); int[] white = new int[tabela.length]; for (int i = 0; i < tabela.length; i++) { white[i] = 0; int bosh = 0; for (int j = 3; j < tabela[i].length; j++) { if (tabela[i][j] == tabela[i][6]) { continue; } if (!tabela[i][j].isEmpty()) { bosh = 1; } } if (bosh == 0) { white[i] = 1; } } Paragraph data = new Paragraph("Data: " + receta[0][7]); data.setSpacingBefore(38); data.setSpacingAfter(40); PdfPTable table = new PdfPTable(7); if (white[0] == 0) { table.addCell(getCellPadding("" + tabela[0][3], 1)); } else { table.addCell(getCellWhite("_", 1, 30)); } table.addCell(getCellPadding("" + tabela[0][4], 1)); table.addCell(getCellPadding("" + tabela[0][5], 1)); table.addCell(getCellPadding("", 1)); table.addCell(getCellPadding("" + tabela[0][7], 1)); table.addCell(getCellPadding("" + tabela[0][8], 1)); table.addCell(getCellPadding("" + tabela[0][9], 1)); table.setWidthPercentage(105); table.setHorizontalAlignment(-100); if (white[1] == 0) { table.addCell(getCellPadding("" + tabela[1][3], 1)); } else { table.addCell(getCellWhite("_", 1, 36)); } table.addCell(getCellPadding("" + tabela[1][4], 1)); table.addCell(getCellPadding("" + tabela[1][5], 1)); table.addCell(getCellPadding("", 1)); table.addCell(getCellPadding("" + tabela[1][7], 1)); table.addCell(getCellPadding("" + tabela[1][8], 1)); table.addCell(getCellPadding("" + tabela[1][9], 1)); table.setWidthPercentage(105); table.setHorizontalAlignment(-100); if (white[2] == 0) { if (white[1] == 0) { table.addCell(getCell("" + tabela[2][3], 1, 30)); } else { table.addCell(getCellWhite("_", 1, 23)); } } else { table.addCell(getCellWhite("_", 1, 28)); } table.addCell(getCell("" + tabela[2][4], 1, 0)); table.addCell(getCell("" + tabela[2][5], 1, 0)); table.addCell(getCell("", 1, 0)); table.addCell(getCell("" + tabela[2][7], 1, 0)); table.addCell(getCell("" + tabela[2][8], 1, 0)); table.addCell(getCell("" + tabela[2][9], 1, 0)); table.setWidthPercentage(105); table.setSpacingBefore(27); table.setHorizontalAlignment(-100); String[][] distanca = merrReceten("select * from distanca where recetat_id=" + parseInt(id) + ";"); PdfPTable largAfer = new PdfPTable(3); if (distanca[0][3].isEmpty()) { PdfPCell larg = getCellWhite("_", 2, 15); largAfer.addCell(larg); } else { PdfPCell larg = new PdfPCell(new Phrase("" + distanca[0][3])); larg.setPadding(0); larg.setHorizontalAlignment(2); larg.setBorder(PdfPCell.NO_BORDER); larg.setPaddingBottom(20); largAfer.addCell(larg); } largAfer.addCell(getCell("", PdfPCell.ALIGN_RIGHT, 25)); if (distanca[0][8].isEmpty()) { largAfer.addCell(getCellWhite("_", PdfPCell.ALIGN_RIGHT, 15)); } else { largAfer.addCell(getCell("" + distanca[0][8], PdfPCell.ALIGN_RIGHT, 25)); } largAfer.setWidthPercentage(75); largAfer.setHorizontalAlignment(350); PdfPTable od_os = new PdfPTable(5); od_os.addCell(getCell("OD= " + distanca[0][4], 0, 195)); od_os.addCell(getCell("OS= " + distanca[0][5], 2, 195)); od_os.addCell(getCell("", 0, 0)); od_os.addCell(getCell("OD= " + distanca[0][9], 0, 0)); od_os.addCell(getCell("OS= " + distanca[0][10], 1, 0)); od_os.setWidthPercentage(90); od_os.setHorizontalAlignment(150); PdfPTable visusi = new PdfPTable(2); if (distanca[0][6].isEmpty()) { PdfPCell od_pa = getCellWhite("_", 2, 17); od_pa.setPaddingRight(45); visusi.addCell(od_pa); } else { PdfPCell od_pa = getCell(distanca[0][6], 2, 17); od_pa.setPaddingRight(45); visusi.addCell(od_pa); } if (distanca[0][11].isEmpty()) { visusi.addCell(getCellWhite("_", 2, 17)); } else { visusi.addCell(getCell(distanca[0][11], 2, 17)); } if (distanca[0][7].isEmpty()) { PdfPCell os_pa = getCellWhite("_", 2, 17); os_pa.setPaddingRight(45); visusi.addCell(os_pa); } else { PdfPCell os_pa = getCell(distanca[0][7], 2, 17); os_pa.setPaddingRight(45); visusi.addCell(os_pa); } if (distanca[0][12].isEmpty()) { visusi.addCell(getCellWhite("_", 2, 17)); } else { visusi.addCell(getCell(distanca[0][12], 2, 0)); } visusi.setWidthPercentage(100); visusi.setHorizontalAlignment(50); String[][] admin = merrReceten("select * from admin where id=1;"); PdfPTable klienti = new PdfPTable(3); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("Emri: " + receta[0][2], 0, 0)); klienti.addCell(getCell("Celular: " + admin[0][4], 0, 0)); klienti.addCell(getCell("", 0, 0)); PdfPCell celReceta = getCell("Celular: " + receta[0][4], 0, 0); celReceta.setPaddingTop(5); klienti.addCell(celReceta); klienti.addCell(getCell("Email: " + admin[0][5], 0, 0)); klienti.addCell(getCell("", 0, 0)); PdfPCell emailReceta = getCell("Email: " + receta[0][5], 0, 0); emailReceta.setPaddingBottom(5); emailReceta.setPaddingTop(5); klienti.addCell(emailReceta); klienti.addCell(getCell("Adresa: " + admin[0][6], 0, 0)); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("Adresa: " + receta[0][6], 0, 0)); klienti.setSpacingBefore(50); PdfPTable kreu = new PdfPTable(1); kreu.addCell(getCell(" ", 0, 0)); document.add(kreu); document.add(klienti); document.add(data); document.add(table); document.add(largAfer); document.add(od_os); document.add(visusi); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:org.activityinfo.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph elementTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, HEADER2_FONT_SIZE, Font.BOLD, BLUE2)); para.setSpacingBefore(BODY_FONT_SIZE); return para;/*from w w w .java 2s .c o m*/ }
From source file:org.activityinfo.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph legendTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, BODY_FONT_SIZE, Font.BOLD, BLUE2)); para.setSpacingBefore(BODY_FONT_SIZE); return para;//from ww w .j a v a2 s.co m }
From source file:org.apache.poi.xwpf.converter.internal.itext.XWPFParagraphUtils.java
License:Open Source License
public static void processLayout(XWPFParagraph paragraph, Paragraph pdfParagraph, XWPFStyle style, CTDocDefaults defaults) {/*from w w w .j av a 2s . c om*/ float indentationLeft = -1; float indentationRight = -1; float firstLineIndent = -1; float spacingBefore = -1; float spacingAfter = -1; // 1) From style CTPPr ppr = getPPr(style); if (ppr != null) { // Indentation CTInd ind = ppr.getInd(); if (ind != null) { // Left Indentation BigInteger left = ind.getLeft(); if (left != null) { indentationLeft = dxa2points(left); } // Right Indentation BigInteger right = ind.getRight(); if (right != null) { indentationRight = dxa2points(right); } // First line Indentation BigInteger firstLine = ind.getFirstLine(); if (firstLine != null) { firstLineIndent = dxa2points(firstLine); } } // Spacing CTSpacing spacing = ppr.getSpacing(); if (spacing != null) { // Spacing before BigInteger before = spacing.getBefore(); if (before != null) { spacingBefore = dxa2points(before); } // Spacing after BigInteger after = spacing.getAfter(); if (after != null) { spacingAfter = dxa2points(after); } } // Text aligment CTTextAlignment textAligment = ppr.getTextAlignment(); if (textAligment != null) { // TODO } } // 2) From paragraph if (indentationLeft == -1 && paragraph.getIndentationLeft() != -1) { indentationLeft = dxa2points(paragraph.getIndentationLeft()); } if (indentationRight == -1 && paragraph.getIndentationRight() != -1) { indentationRight = dxa2points(paragraph.getIndentationRight()); } if (firstLineIndent == -1 && paragraph.getIndentationFirstLine() != -1) { firstLineIndent = dxa2points(paragraph.getIndentationFirstLine()); } if (spacingBefore == -1 && paragraph.getSpacingBefore() != -1) { spacingBefore = dxa2points(paragraph.getSpacingBefore()); } if (spacingAfter == -1 && paragraph.getSpacingAfter() != -1) { spacingAfter = dxa2points(paragraph.getSpacingAfter()); } // 3) From default // TODO // Apply if (indentationLeft != -1) { pdfParagraph.setIndentationLeft(indentationLeft); } if (indentationRight != -1) { pdfParagraph.setIndentationRight(indentationRight); } if (firstLineIndent != -1) { pdfParagraph.setFirstLineIndent(firstLineIndent); } if (spacingBefore != -1) { pdfParagraph.setSpacingBefore(spacingBefore); } if (spacingAfter != -1) { pdfParagraph.setSpacingAfter(spacingAfter); } // Aligment ParagraphAlignment alignment = paragraph.getAlignment(); switch (alignment) { case LEFT: pdfParagraph.setAlignment(Paragraph.ALIGN_LEFT); break; case RIGHT: pdfParagraph.setAlignment(Paragraph.ALIGN_RIGHT); break; case CENTER: pdfParagraph.setAlignment(Paragraph.ALIGN_CENTER); break; case BOTH: pdfParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED); break; } }
From source file:org.flightgear.clgen.backend.PdfVisitor.java
License:Open Source License
@Override public void enter(final Checklist checklist) { try {/*from w w w . ja v a 2 s. c o m*/ Paragraph p = new Paragraph(checklist.getTitle().toUpperCase(), H2); p.setSpacingBefore(24.0f); document.add(p); } catch (DocumentException e) { document.close(); throw new GeneratorException(e); } }
From source file:org.flightgear.clgen.backend.PdfVisitor.java
License:Open Source License
@Override public void enter(final Check check) { try {/* w w w . j a v a2s . com*/ String i = check.getItem() != null ? nvl(check.getItem().getName()) : ""; String s = check.getState() != null ? nvl(check.getState().getName()) : ""; String line = String.format("%s %s %s", i, dots(i, s, normalTextWidth() - 2), s); Paragraph p = new Paragraph(line, empty(s) ? B : P); p.setSpacingBefore(6.0f); document.add(p); for (String value : check.getAdditionalValues()) { p = new Paragraph(value, P); p.setSpacingBefore(6.0f); p.setAlignment(Element.ALIGN_RIGHT); document.add(p); } } catch (DocumentException e) { document.close(); throw new GeneratorException(e); } }