List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
public PDFDocument(String authorName, Map<String, Integer> yearToPublicationCount, Document document, PdfWriter pdfWriter) {//from w w w .jav a2s .c o m // setPreferredSize(new Dimension(600,400)); try { document.addTitle("PDF Pipeline iText Prototype"); document.addAuthor(authorName); document.addSubject("This example tests text, color, image, transparency & table functionality."); document.addKeywords("text, color, image, transparency, table"); document.addCreator("Standalone PDF Renderer using iText"); Paragraph header = new Paragraph(); Font pageHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLDITALIC | Font.UNDERLINE); Font featureHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, new BaseColor(Color.red)); header.add(new Chunk("PDF Pipeline Prototype v2 using iText\n", pageHeaderStyle)); header.setSpacingAfter(15f); document.add(header); Paragraph content = new Paragraph(); content.add(new Chunk("Publication Count - Author Name - " + authorName, featureHeaderStyle)); content.setSpacingAfter(15f); document.add(content); // step4 PdfPTable publicationCount = createTable(yearToPublicationCount); document.add(publicationCount); content = new Paragraph(); content.add(new Chunk("Transparency of Shapes", featureHeaderStyle)); content.setSpacingAfter(15f); document.add(content); createTransparencyShapes(document, pdfWriter); createImage(document, pdfWriter, featureHeaderStyle); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:edu.esprit.pi.gui.internalframes.PDFwithItextInternalFrame.java
public void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // On ajoute une seule ligne vide. addEmptyLine(preface, 1);/*www . j ava2 s . c o m*/ // Ecrire un titre avec un grand caractre. preface.add(new Paragraph(titreDocumentTextField.getText(), catFont)); addEmptyLine(preface, 1); // Va ajouter une ligne Rapport gnr par : Nom, date preface.add(new Paragraph("Rapport gnr par : " + System.getProperty("user.name") + ", " + new Date(), smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph(sousTitrejTextField.getText(), smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph(descriptionTitlejTextArea.getText(), redFont)); document.add(preface); // Commencer une nouvelle page document.newPage(); }
From source file:edu.harvard.mcz.precapture.ui.ContainerLabel.java
License:Open Source License
/** * /*from w w w .j ava 2 s .c om*/ * @return a PDF paragraph cell containing a text encoding of the fields in this set. */ public PdfPCell toPDFCell(LabelDefinitionType printDefinition) { PdfPCell cell = new PdfPCell(); ; if (printDefinition.getTextOrentation().toString().toLowerCase() .equals(TextOrentationType.VERTICAL.toString().toLowerCase())) { log.debug("Print orientation of text is Vertical"); cell.setRotation(90); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); cell.setNoWrap(false); int leading = (int) (fields.get(0).getField().getFontSize() + printDefinition.getFontDelta()) - 1; Paragraph higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(0).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); boolean added = false; boolean hasContent = false; for (int i = 0; i < fields.size(); i++) { log.debug(i); if (fields.get(i).getField().isNewLine() || (i == fields.size() - 1)) { if (!higher.isEmpty()) { log.debug(higher.getContent()); cell.addElement(higher); } leading = (int) (fields.get(i).getField().getFontSize() + printDefinition.getFontDelta()) - 1; higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); added = false; hasContent = false; } log.debug(fields.get(i).getTextField().getText().trim()); Chunk chunk = new Chunk(fields.get(i).getTextField().getText().trim()); if (fields.get(i).getField().isUseItalic()) { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.ITALIC)); } else { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); } if (!chunk.isEmpty()) { hasContent = true; higher.add(chunk); log.debug(fields.get(i).getField().getSuffix()); if (fields.get(i).getField().getSuffix() != null && fields.get(i).getField().getSuffix().length() > 0) { higher.add(new Chunk(fields.get(i).getField().getSuffix())); } if (fields.get(i).getTextField().getText().trim().length() > 0) { // add a trailing space as a separator if there was something to separate. higher.add(new Chunk(" ")); } } } if (!added) { log.debug(higher.getContent()); cell.addElement(higher); } String extraText = PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_EXTRAHUMANTEXT); if (extraText != null && extraText.length() > 0) { log.debug(extraText); cell.addElement(new Chunk(extraText)); } return cell; }
From source file:edu.ucue.jparking.srv.ExportOrdenPagoService.java
private void addContent(Document document, String cedula) throws DocumentException, UsuarioNoExistenteException, CedulaNoValidaException, ContratoNoEstablecidoException, FueraDelDiaDePagoException, BadElementException, IOException, UsuarioNoRegistradoEnUnParqueaderoException, ClassNotFoundException, FileNotFoundException, ObjectSizeException {//from w w w . j av a 2s . c o m document.addTitle("Orden de pago del Parqueadero"); Paragraph preface = new Paragraph(); // Lets write a big header Paragraph tituloUniversidad = new Paragraph("UNIVERSIDAD DE CUENCA", catFont); Paragraph subtituloOrdenPago = new Paragraph("ORDEN DE PAGO", subFont); tituloUniversidad.setAlignment(Paragraph.ALIGN_CENTER); subtituloOrdenPago.setAlignment(Paragraph.ALIGN_CENTER); Image logoU = null; logoU = Image.getInstance(getClass().getResource("/edu/ucue/jparking/img/logo_u.png")); logoU.scalePercent(10); logoU.setAlignment(Image.ALIGN_CENTER); OrdenPagoService ops = new OrdenPagoService(); UsuarioService service = new UsuarioService(); Usuario u = service.get(cedula); OrdenPago orden = ops.getOrdenPago(cedula); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); preface.add(tituloUniversidad); addEmptyLine(preface, 1); preface.add(logoU); addEmptyLine(preface, 1); preface.add(subtituloOrdenPago); addEmptyLine(preface, 2); preface.add(new Paragraph(String.format("%s %s", "Fecha:", df.format(Calendar.getInstance().getTime())), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Cdula:", u.getCedula()), smallBody)); preface.add( new Paragraph(String.format("%s %s %s", "Nombre:", u.getNombres(), u.getApellidos()), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Direccin:", u.getDireccion()), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Telfono:", u.getTelefono()), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Tipo de Usuario:", u.getTipoUsuarioString()), smallBody)); //preface.add(new Paragraph(String.format("%s %s", "Fecha de contrato:", df.format(orden.getFechaEmision().getTime())), smallBody)); preface.add(new Paragraph(String.format("%s $%.2f", "Valor a pagar:", orden.getCosto()), smallBody)); /*if(u.estaDebiendo()){ preface.add(new Paragraph("Estado: Debe")); }else{ preface.add(new Paragraph("Estado: Cancelado")); }*/ addEmptyLine(preface, 2); preface.add(new Paragraph(String.format("%s ...............................", "Firma:"), smallBody)); addEmptyLine(preface, 1); preface.add(new Paragraph(String.format("%s ..........................", "Autorizado:"), smallBody)); addEmptyLine(preface, 2); preface.add(new Paragraph("Documento generado automticamente por la aplicacin JParking.", footPage)); document.add(preface); }
From source file:engine.Pdf.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);/*from ww w . java 2 s . c om*/ // Lets write a big header preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement.", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java
private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);/*w w w . jav a 2s .c o m*/ // Lets write a big header String fecha = new SimpleDateFormat("dd / MM / yyyy").format(venta.getFecha()); preface.add(new Paragraph("ALBAR?N N " + venta.getId() + " " + fecha, catFont)); addEmptyLine(preface, 2); document.add(preface); // Will create: Report generated by: _name, _date //preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // smallBold)); //addEmptyLine(preface, 3); //preface.add(new Paragraph("This document describes something which is very important ", smallBold)); preface = new Paragraph("SERVICIOS MDICOS-VETERINARIOS"); preface.setAlignment(Element.ALIGN_CENTER); addEmptyLine(preface, 2); document.add(preface); preface = new Paragraph("Cliente: " + venta.getCliente().getFullname() + "\nTelfono: " + venta.getCliente().getTelefono()); preface.setAlignment(Element.ALIGN_LEFT); addEmptyLine(preface, 2); document.add(preface); //preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", // redFont)); //document.add(preface); // Start a new page // document.newPage(); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected Paragraph createParagraph(String s) { Paragraph result = getDefaultParagraph(); StringBuilder sb = new StringBuilder(); Font f = CONTENT_NORMAL;//from ww w .ja va 2s. c o m boolean customStyle = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!customStyle) { if (c == '%') { if (i + 1 < s.length()) { i++; c = s.charAt(i); if (c == 'b') {//bold f = CONTENT_BOLD; customStyle = true; } else if (c == 'i') {//italic f = CONTENT_ITALIC; customStyle = true; } else if (c == 'u') {//underlined f = CONTENT_UNDERLINE; customStyle = true; } else if (c == 'e') {//emphasized (bold/italic) f = CONTENT_BOLDITALIC; customStyle = true; } else { sb.append("%" + c); } if (customStyle) { result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, CONTENT_NORMAL)); sb = new StringBuilder(); } } else { sb.append(c); } } else { sb.append(c); } } else { if (c == '%') { result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, f)); sb = new StringBuilder(); customStyle = false; } else { sb.append(c); } } } if (sb.length() > 0 && customStyle) { result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, f)); } else if (sb.length() > 0 && !customStyle) { result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, CONTENT_NORMAL)); } return result; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected Paragraph decorateImage(Image i, String caption) { Paragraph p = new Paragraph("", IMAGE_CAPTION); p.setAlignment(Element.ALIGN_CENTER); i.setAlignment(Element.ALIGN_CENTER); i.setBorder(Image.BOX);/* ww w.ja va 2 s . c o m*/ i.setBorderWidth(3f); i.setBorderColor(new BaseColor(52, 90, 138)); p.add(i); Paragraph captionP = new Paragraph(caption, IMAGE_CAPTION); captionP.setAlignment(Element.ALIGN_CENTER); //p.add(Chunk.NEWLINE); p.add(captionP); //p.setKeepTogether(true); return p; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected Paragraph listParagraphs(List<Paragraph> paragraphs) { Paragraph pList = getDefaultParagraph(); com.itextpdf.text.List list = new com.itextpdf.text.List(com.itextpdf.text.List.UNORDERED); list.setListSymbol("\u2022" + " "); list.setSymbolIndent(30f);/* w w w .ja va 2s .co m*/ pList.add(list); pList.setSpacingBefore(0f); pList.setSpacingAfter(0f); for (Paragraph p : paragraphs) { list.add(new ListItem(p)); } return pList; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildFirstPage(PdfWriter writer, Document document) throws DocumentException { Paragraph firstPageTitleParagraph = new Paragraph(getDocumentTitle(), FIRST_PAGE_TITLE); firstPageTitleParagraph.setAlignment(Element.ALIGN_CENTER); firstPageTitleParagraph.setSpacingAfter(Utilities.millimetersToPoints(50)); document.add(firstPageTitleParagraph); Paragraph firstPageProjectNameParagraph = new Paragraph(getProjectName(), FIRST_PAGE_PRJ_NAME); firstPageProjectNameParagraph.setAlignment(Element.ALIGN_CENTER); firstPageProjectNameParagraph.setSpacingAfter(Utilities.millimetersToPoints(20)); document.add(firstPageProjectNameParagraph); Paragraph firstPageAuthorNameParagraph = new Paragraph(getReportAuthor(), FIRST_PAGE_AUTHOR); firstPageAuthorNameParagraph.setAlignment(Element.ALIGN_CENTER); firstPageAuthorNameParagraph.setSpacingAfter(Utilities.millimetersToPoints(20)); document.add(firstPageAuthorNameParagraph); Paragraph firstPageOrganizationParagraph = new Paragraph(getReportIstitution(), FIRST_PAGE_ORGANIZ); firstPageOrganizationParagraph.setAlignment(Element.ALIGN_CENTER); firstPageOrganizationParagraph.setSpacingAfter(Utilities.millimetersToPoints(20)); document.add(firstPageOrganizationParagraph); Paragraph firstPageDateParagraph = new Paragraph(getDate(), FIRST_PAGE_DATE); firstPageDateParagraph.setAlignment(Element.ALIGN_CENTER); firstPageDateParagraph.setSpacingAfter(Utilities.millimetersToPoints(40)); document.add(firstPageDateParagraph); String[] phrases = { "This document has been generated by STS-Tool", "http://www.sts-tool.eu" }; Paragraph firstPageLastLineParagraph = new Paragraph(phrases[0], FIRST_PAGE_LAST_LINE); for (int i = 1; i < phrases.length; i++) { firstPageLastLineParagraph.add(Chunk.NEWLINE); firstPageLastLineParagraph.add(new Phrase(phrases[i], FIRST_PAGE_LAST_LINE)); }//from w w w. j a v a2 s .com firstPageLastLineParagraph.setAlignment(Element.ALIGN_CENTER); document.add(firstPageLastLineParagraph); if (footerImage != null) { footerImage.setAbsolutePosition((PageSize.A4.getWidth() / 2) - (footerImage.getPlainWidth() / 2), 50); document.add(footerImage); } }