List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:ambit2.db.reporters.PDFReporter.java
protected void writeMolecule(IAtomContainer molecule) { Object value;//from w w w . j a va 2s. c o m try { Paragraph p = new Paragraph(""); String s; for (Property property : header) { StringBuffer b = new StringBuffer(); b.append(property.getLabel()); b.append(" = "); value = molecule.getProperty(property); if (value != null) { if (value instanceof Number) { s = value.toString(); } else { s = value.toString(); } b.append(s); Chunk chunk = new Chunk(b.toString()); chunk.setFont(font); p.add(new Paragraph(chunk)); } } BufferedImage image = depict.getImage(molecule); image.flush(); Image png_struc = Image.getInstance(image, Color.white); png_struc.setAlignment(Image.LEFT); png_struc.scalePercent(100); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(cell.height()); cell.addElement(png_struc); table.addCell(cell); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } catch (Exception x) { logger.log(java.util.logging.Level.FINE, x.getMessage(), x); } }
From source file:ambit2.io.PDFWriter.java
License:Open Source License
public void writeMolecule(IMolecule molecule) { Object value;/*w ww .ja v a 2 s. c o m*/ try { //give it a chance to create a header just before the first write if (!writingStarted) { if (header == null) setHeader(molecule.getProperties()); writeHeader(); writingStarted = true; } Paragraph p = new Paragraph(""); String s; for (int i = 0; i < header.size(); i++) { StringBuffer b = new StringBuffer(); b.append(header.get(i)); b.append(" = "); value = molecule.getProperty(header.get(i)); if (i == smilesIndex) { if (value == null) //no SMILES available try { value = ""; //sg.createSMILES(molecule); } catch (Exception x) { logger.error("Error while createSMILES\t", x.getMessage()); value = ""; } } if (value != null) { if (value instanceof Number) { s = value.toString(); } else { s = value.toString(); } b.append(s); p.add(new Paragraph(b.toString())); } } BufferedImage image = imageTools.getImage(molecule); image.flush(); Image png_struc = Image.getInstance(image, Color.white); png_struc.setAlignment(Image.LEFT); png_struc.scalePercent(100); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(cell.height()); cell.addElement(png_struc); table.addCell(cell); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } catch (Exception x) { logger.error("ERROR while writing Molecule: ", x.getMessage()); logger.debug(x); x.printStackTrace(); } }
From source file:at.htlpinkafeld.beans.AlleAbwesenheitenBean.java
/** * pdf post processing//from w w w . ja va2 s . co m * * @param document pdf document * @throws DocumentException */ public void postProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.add(new Paragraph("\n\nStand: " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))); pdf.close(); }
From source file:at.htlpinkafeld.beans.JahresuebersichtBean.java
/** * pre processes the PDF for creating/*from w w w . j a v a 2s. co m*/ * * @param document pdf-doc * @throws DocumentException may be thrown */ public void preProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.open(); pdf.setPageSize(PageSize.A4); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.addCell(getCell("Jahresbersicht - " + selectedYear.getYear(), PdfPCell.ALIGN_LEFT)); table.addCell(getCell("", PdfPCell.ALIGN_CENTER)); table.addCell(getCell("von " + selectedUser.getPersName(), PdfPCell.ALIGN_RIGHT)); pdf.add(table); pdf.add(new Paragraph("\n")); }
From source file:at.htlpinkafeld.beans.JahresuebersichtBean.java
/** * post processes the PDF for creating//w w w.j ava2 s . c o m * * @param document pdf-doc * @throws DocumentException may be thrown */ public void postProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.add(new Paragraph("\nStand: " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))); pdf.close(); }
From source file:at.htlpinkafeld.beans.UserDetailsBean.java
public void preProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.setPageSize(PageSize.A4.rotate()); pdf.open();//from w ww . j av a2 s .c om PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.addCell(getCell("Monatsbersicht - " + selectedDate.format(DateTimeFormatter.ofPattern("MM.yyyy")), PdfPCell.ALIGN_LEFT)); table.addCell(getCell("", PdfPCell.ALIGN_CENTER)); table.addCell(getCell("von " + selectedUser, PdfPCell.ALIGN_RIGHT)); pdf.add(table); pdf.add(new Paragraph("\n")); }
From source file:at.htlpinkafeld.beans.UserDetailsBean.java
public void postProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.add(new Paragraph("\nStand: " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))); User curr = BenutzerverwaltungService.getUserByUsername(selectedUser); UserHistoryService.getUserHistoryEntriesForUserBetweenDates(curr, selectedDate, selectedDate.plusDays(1)) .forEach((uhe) -> {/*from www . ja va 2 s . c om*/ monthOvertime = uhe.getOvertime(); }); pdf.add(new Paragraph("\nberstunden gesamt: " + monthOvertime)); pdf.close(); }
From source file:at.tugraz.sss.serv.SSFileU.java
License:Apache License
public static void writePDFFromText(final String pdfFilePath, final String textFilePath) throws Exception { OutputStream out = null;//from www.j ava2 s. c om BufferedReader br = null; try { out = openOrCreateFileWithPathForWrite(pdfFilePath); final Document document = new Document(); final PdfWriter writer = PdfWriter.getInstance(document, out); String line; document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); br = new BufferedReader(new FileReader(new File(textFilePath))); while ((line = br.readLine()) != null) { document.add(new Paragraph(line)); } document.close(); } catch (Exception error) { if (out != null) { out.close(); } if (br != null) { br.close(); } } }
From source file:at.tugraz.sss.serv.SSFileU.java
License:Apache License
public static void writePDFFromDoc(final String docFilePath, final String pdfFilePath) throws Exception { final Document document = new Document(); final POIFSFileSystem fs = new POIFSFileSystem(openFileForRead(docFilePath)); final HWPFDocument word = new HWPFDocument(fs); final WordExtractor we = new WordExtractor(word); final OutputStream out = openOrCreateFileWithPathForWrite(pdfFilePath); final PdfWriter writer = PdfWriter.getInstance(document, out); final Range range = word.getRange(); document.open();//from w ww . ja v a 2s . c o m writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); String[] paragraphs = we.getParagraphText(); for (int i = 0; i < paragraphs.length; i++) { org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i); // CharacterRun run = pr.getCharacterRun(i); // run.setBold(true); // run.setCapitalized(true); // run.setItalic(true); paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", ""); System.out.println("Length:" + paragraphs[i].length()); System.out.println("Paragraph" + i + ": " + paragraphs[i].toString()); // add the paragraph to the document document.add(new Paragraph(paragraphs[i])); } document.close(); }
From source file:at.tugraz.sss.serv.util.SSFileU.java
License:Apache License
public static void writePDFFromText(final String pdfFilePath, final String textFilePath) throws SSErr { OutputStream out = null;//w ww .ja v a2s . c om BufferedReader br = null; try { out = openOrCreateFileWithPathForWrite(pdfFilePath); final Document document = new Document(); final PdfWriter writer = PdfWriter.getInstance(document, out); String line; document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); br = new BufferedReader(new FileReader(new File(textFilePath))); while ((line = br.readLine()) != null) { document.add(new Paragraph(line)); } document.close(); } catch (Exception error) { SSServErrReg.regErrThrow(error); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { SSLogU.err(ex); } } if (br != null) { try { br.close(); } catch (IOException ex) { SSLogU.err(ex); } } } }