List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:de.unisiegen.informatik.bs.alvis.export.PdfExport.java
License:Open Source License
/** * adds organized, structured, highlighted source code to new paragraph and * returns it//from ww w.ja va 2s .c om * * @author Sebastian Schmitz & Frank Weiler * @param sourceCode * the source code as string including html tags for highlighting * etc * @return a paragraph including the source code * @throws DocumentException * will be thrown when new paragraph could not have been added */ private Paragraph toParagraph(StyledText sourceCode) throws DocumentException { if (sourceCode == null) return null; String content = highlightStyleTextinHTML(sourceCode); // returnt den // nicht // eingerckten, // aber // gehighlighteten // Code Paragraph paragraph = new Paragraph(); if (content != null) { content = indentCode(content); // rckt den Code ein List<Element> bodyText; StyleSheet styles = new StyleSheet(); styles.loadTagStyle("ol", "leading", "16,0"); try { bodyText = HTMLWorker.parseToList(new StringReader(content), styles); paragraph.setFont(FontFactory.getFont("Courier", 10, Font.NORMAL)); for (Element elem : bodyText) { paragraph.add(elem); } } catch (IOException e) { paragraph.add(Messages.noSourceCodeAdded); } } return paragraph; }
From source file:de.unisiegen.informatik.bs.alvis.export.PdfExport.java
License:Open Source License
/** * adds one line of organized, structured, highlighted source code to new * paragraph and returns it//from w w w. j a va 2 s.co m * * @author Sebastian Schmitz & Frank Weiler * @param sourceCode * the source code as string including html tags for highlighting * etc * @param wantedLineIndex * the wanted line number * @return a paragraph including the source code line * @throws DocumentException * will be thrown when new paragraph could not have been added */ private Paragraph toParagraph(StyledText sourceCode, int wantedLineIndex) throws DocumentException { if (sourceCode == null) return null; if (wantedLineIndex < 0 || wantedLineIndex >= sourceCode.getLineCount()) return null; String content = highlightStyleTextinHTML(sourceCode, wantedLineIndex); Paragraph paragraph = new Paragraph(); if (content != null) { List<Element> bodyText; StyleSheet styles = new StyleSheet(); styles.loadTagStyle("ol", "leading", "16,0"); try { bodyText = HTMLWorker.parseToList(new StringReader(content), styles); paragraph.setFont(FontFactory.getFont("Courier", 10, Font.NORMAL)); for (Element elem : bodyText) { paragraph.add(elem); } } catch (IOException e) { paragraph.add(Messages.noSourceCodeAdded); } } return paragraph; }
From source file:de.unisiegen.informatik.bs.alvis.export.PdfExport.java
License:Open Source License
/** * adds image to new paragraph and returns it * /*from w w w .j a v a 2 s . c o m*/ * @param image * the image which will be parsed to a pdf-valid format * @return paragraph a paragraph including the image * @throws DocumentException * will be thrown when new paragraph could not have been added */ private Paragraph toParagraph(Image image) throws DocumentException { if (image == null) return null; String path = Messages.tmpAlvisImage + ".png"; com.itextpdf.text.Image pdfImage; Paragraph paragraph = new Paragraph(); ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image.getImageData() }; loader.save(path, SWT.IMAGE_PNG); addEmptyLine(paragraph, 2); try { pdfImage = com.itextpdf.text.Image.getInstance(path); float height, width; width = Math.min(530, pdfImage.getScaledWidth()); height = pdfImage.getScaledHeight() / pdfImage.getScaledWidth() * width; if (height > 500.0f) { height = 500.0f; width = pdfImage.getScaledWidth() / pdfImage.getScaledHeight() * height; } pdfImage.scaleAbsolute(width, height); paragraph.add(pdfImage); } catch (Exception e) { e.printStackTrace(); System.err.println(Messages.errorAddingImage); } addEmptyLine(paragraph, 2); // image.dispose(); return paragraph; }
From source file:de.unisiegen.informatik.bs.alvis.export.PdfExport.java
License:Open Source License
/** * adds empty lines (i.e. line breaks) to given paragraph * /*from w w w. ja va 2 s .c o m*/ * @param paragraph * the paragraph to add empty lines to * @param amount * the amount of empty lines */ private void addEmptyLine(Paragraph paragraph, int amount) { for (int i = 0; i < amount; i++) { paragraph.add(new Paragraph(" ")); } }
From source file:digilib.pdf.PDFTitlePage.java
License:Open Source License
/** * generate iText-PDF-Contents for the title page * //w w w. j av a 2 s.c o m * @return */ public Element getPageContents() { Paragraph content = new Paragraph(); content.setAlignment(Element.ALIGN_CENTER); // add vertical whitespace for (int i = 0; i < 8; i++) { content.add(Chunk.NEWLINE); } // add logo content.add(getLogo()); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); // add title Anchor title = new Anchor(new Paragraph(getTitle(), FontFactory.getFont(FontFactory.HELVETICA, 16))); String burl = job_info.getImageJobInformation().getAsString("base.url"); title.setReference(burl + "digilib.jsp?fn=" + job_info.getImageJobInformation().getAsString("fn")); content.add(title); content.add(Chunk.NEWLINE); // add author if (getDate() != " ") content.add(new Paragraph(getAuthor() + " (" + getDate() + ")", FontFactory.getFont(FontFactory.HELVETICA, 14))); else content.add(new Paragraph(getAuthor(), FontFactory.getFont(FontFactory.HELVETICA, 14))); content.add(Chunk.NEWLINE); // add page numbers content.add(new Paragraph(getPages(), FontFactory.getFont(FontFactory.HELVETICA, 12))); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); // add digilib version content.add(new Paragraph(getDigilibVersion(), FontFactory.getFont(FontFactory.HELVETICA, 10))); for (int i = 0; i < 8; i++) { content.add(Chunk.NEWLINE); } Anchor address = new Anchor( new Paragraph(burl + "digilib.jsp?fn=" + job_info.getImageJobInformation().getAsString("fn"), FontFactory.getFont(FontFactory.COURIER, 9))); address.setReference(burl + "digilib.jsp?fn=" + job_info.getImageJobInformation().getAsString("fn")); content.add(address); return content; }
From source file:Documentos.ReportesPDF.java
private void agregarContenido(Document document) { Paragraph ParrafoHoja = new Paragraph(); // AGREGAMOS LA IMAGEN try {/* w w w. j a v a 2s . c om*/ Image foto = Image.getInstance(getClass().getResource("/Image/logoAnaIS_1.png")); foto.scaleToFit(40, 40); ParrafoHoja.add(foto); } catch (BadElementException | IOException e) { e.getMessage(); } //Agregar lineas en blanco agregarLineasEnBlanco(ParrafoHoja, 1); agregarTabla(ParrafoHoja); try { document.add(ParrafoHoja); } catch (DocumentException ex) { Logger.getLogger(ReportesPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Documentos.ReportesPDF.java
public void agregarTabla(Paragraph parrafo) { //Anchos de las columnas PdfPTable tabla = new PdfPTable(anchosFilas); // Porcentaje que ocupa a lo ancho de la pagina del PDF tabla.setWidthPercentage(90);// www . j ava 2 s . c om //Alineacion horizontal centrada tabla.setHorizontalAlignment(Element.ALIGN_CENTER); //agregar celda que ocupa las columnas de los rotulos PdfPCell cell0 = new PdfPCell(new Paragraph("Repostera AnaIs")); cell0.setColspan(anchosFilas.length); cell0.setBackgroundColor(new BaseColor(66, 139, 202)); //Centrar contenido de celda cell0.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(new Paragraph(tituloReporte())); cell.setColspan(anchosFilas.length); cell.setBackgroundColor(new BaseColor(49, 176, 213)); //Centrar contenido de celda cell.setHorizontalAlignment(Element.ALIGN_CENTER); //Color de fondo de la celda tabla.addCell(cell0); tabla.addCell(cell); // Mostrar los rotulos de las columnas for (int i = 0; i < rotulosColumnas.length; i++) { cell = new PdfPCell(new Paragraph(rotulosColumnas[i])); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(248, 248, 248)); tabla.addCell(cell); } switch (numReport) { case 1: DataBase.DataBasePDF.pdfVendedores(cell, tabla); break; case 2: DataBase.DataBasePDF.pdfProveedores(cell, tabla); break; case 3: DataBase.DataBasePDF.pdfClientes(cell, tabla); break; case 4: DataBase.DataBasePDF.pdfVentas(cell, tabla); break; case 5: DataBase.DataBasePDF.pdfProductos(cell, tabla); break; case 6: DataBase.DataBasePDF.pdfPedidos(cell, tabla); break; } //Agregar la tabla con los datos al parrafo que nos llego como entrada parrafo.add(tabla); }
From source file:Documentos.ReportesPDF.java
private static void agregarLineasEnBlanco(Paragraph parrafo, int nLineas) { for (int i = 0; i < nLineas; i++) { parrafo.add(new Paragraph(" ")); }// w w w .j av a2 s . c om }
From source file:domain.Pdfmaker.java
public void makePdf() { Document doc = new Document(); doc.setPageSize(PageSize.A4);/* w ww.j a va2s. co m*/ try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(test.getTitle() + ".pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_7); doc.open(); Font f = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, new BaseColor(0, 0, 0)); Paragraph title = new Paragraph("TEST TITLE", f); title.setAlignment(Element.ALIGN_CENTER); doc.addCreator("Arne De Bremme"); //make table PdfPTable table = new PdfPTable(4); table.setTotalWidth(550f); table.setLockedWidth(true); table.setHeaderRows(1); Paragraph p = new Paragraph(test.getTitle()); p.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(p); cell.setGrayFill(0.7f); cell.setColspan(4); table.addCell(cell); table.addCell(test.getClassGroup().getGroupName()); PdfPCell cell2 = new PdfPCell(new Paragraph(test.getDescription())); cell2.setColspan(2); cell2.setRowspan(2); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("DD " + test.getStartDate().getDay() + "/" + test.getStartDate().getMonth() + "/" + test.getStartDate().getYear())); cell3.setRowspan(2); table.addCell(cell3); table.addCell(new Paragraph("Test " + test.getTestId())); doc.add(table); doc.add(Chunk.NEWLINE); for (Exercise e : ex) { Paragraph par = new Paragraph(); par.add("Vraag " + counter); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(e.getPunten() + "/"); doc.add(par); doc.add(new Paragraph("Klimatogram " + e.getClimateChart().getLocation() + " " + e.getPunten())); Robot r = new Robot(); Desktop.getDesktop().browse(new URI( "http://climatechart.azurewebsites.net/ClimateChart/ShowExercises?selectedYear=1&continentId=" + e.getClimateChart().getCountry().getContinent().getId() + "&countryId=" + e.getClimateChart().getCountry().getContinent().getId() + "&climateId=" + e.getClimateChart().getId())); TimeUnit.SECONDS.sleep(6); BufferedImage bi = r.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize().width * 7 / 10, Toolkit.getDefaultToolkit().getScreenSize().width * 8 / 14)); File file = new File("screenCapture" + counter + ".jpg"); ImageIO.write(bi, "jpg", file); Image img = Image.getInstance("screenCapture.jpg"); img.scaleAbsolute(400, 300); doc.add(img); doc.add(Chunk.NEWLINE); doc.add(new Paragraph(e.getNaam())); doc.add(Chunk.NEXTPAGE); counter++; } doc.close(); File filz = new File(test.getTitle() + ".pdf"); Desktop.getDesktop().open(filz); } catch (Exception e) { } }
From source file:DomainToolCore.Report.PDFSubDomains.java
License:Open Source License
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); addEmptyLine(preface, 1);//www. ja v a 2 s . c o m preface.add(new Paragraph("Doman Tool Report", catFont)); addEmptyLine(preface, 2); preface.add(new Paragraph("Report generated on: " + new Date(), smallBold)); addEmptyLine(preface, 2); preface.add(new Paragraph("Domain: " + domain, smallBold)); preface.add(new Paragraph("Domain IP: " + ip_domain, smallBold)); addEmptyLine(preface, 2); document.add(preface); }