List of usage examples for com.itextpdf.text Paragraph setAlignment
public void setAlignment(int alignment)
From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java
License:Apache License
/** * Adds a page for a given week./*from w w w.ja v a 2 s .c o m*/ * @param i the week number * @param doc the document to update * @param bean a generation bean (not null) * @throws DocumentException */ private void addPageForWeek(int weekNumber, Document doc, GenerationDataBean bean) throws DocumentException { doc.newPage(); final Font boldFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD); final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA); Calendar calendar = Utils.findCalendar(weekNumber); // Title Paragraph paragraph = new Paragraph("Bordereau de Dclaration des Temps", boldFont); paragraph.setAlignment(Element.ALIGN_CENTER); doc.add(paragraph); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); // Meta: week final PdfPTable metaTable = new PdfPTable(1); paragraph = new Paragraph(); paragraph.add(new Chunk("Semaine : ", boldFont)); paragraph.add(new Chunk(String.valueOf(weekNumber), normalFont)); PdfPCell c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); metaTable.addCell(c); // Meta: date Calendar endOfWeekCalendar = ((Calendar) calendar.clone()); endOfWeekCalendar.add(Calendar.DATE, 4); String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(endOfWeekCalendar.getTime()); paragraph = new Paragraph(); paragraph.add(new Chunk("Date : ", boldFont)); paragraph.add(new Chunk(formattedDate, normalFont)); c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); metaTable.addCell(c); doc.add(metaTable); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); // Signatures final PdfPTable signaturesTable = new PdfPTable(2); paragraph = new Paragraph(); paragraph.add(new Chunk("Nom : ", boldFont)); paragraph.add(new Chunk(bean.getName(), normalFont)); c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); paragraph = new Paragraph(); paragraph.add(new Chunk("Responsable : ", boldFont)); paragraph.add(new Chunk(bean.getManagerName(), normalFont)); c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); c = new PdfPCell(new Paragraph("Signature : ", boldFont)); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); c = new PdfPCell(new Paragraph("Signature : ", boldFont)); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); doc.add(signaturesTable); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); // Calendar final PdfPTable timeTable = new PdfPTable(7); timeTable.addCell(new PdfPCell()); for (int i = 0; i < 5; i++) { final String date = this.sdf.format(calendar.getTime()); timeTable.addCell(newCell(date, 10)); calendar.add(Calendar.DATE, 1); } timeTable.addCell(newCell("Total", 10)); timeTable.addCell(newCell("Heures Effectues", 20)); for (int i = 0; i < 5; i++) timeTable.addCell(newCell("", 20)); if (bean.getTotalHours() > 0) timeTable.addCell(newCell(bean.getTotalHours() + " h", 20)); timeTable.completeRow(); doc.add(timeTable); }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java
License:Apache License
/** * Export a report to a pdf file./* ww w .j a v a2 s . c o m*/ * * @param allMetricsMap map of all QC metrics - keys and description. * @param selectedReports the report units to be exported in PDF format. * @param preferredPDFDirectory the directory the pdf document should be exported to. * @return Path of the created PDF document if it is successfully created - otherwise return empty string. */ public static String exportReportUnitInPDFFormat(final Map<String, String> allMetricsMap, final ArrayList<ReportUnit> selectedReports, final String preferredPDFDirectory) { //Obtain current timestamp. final java.util.Date date = new java.util.Date(); final String timestampString = CREATION_DATE_TIME_FORMAT.format(date); //Replace all occurrences of special character ':' from time stamp since ':' is not allowed in filename. final String filenameTimestamp = timestampString.replace(':', '-'); //Instantiation of document object - landscape format using the rotate() method final Document document = new Document(PageSize.A4.rotate(), PDF_PAGE_MARGIN, PDF_PAGE_MARGIN, PDF_PAGE_MARGIN, PDF_PAGE_MARGIN); final String pdfFileName = preferredPDFDirectory + "\\QCReports-" + filenameTimestamp + FILE_TYPE_EXTENSION; try { //Creation of PdfWriter object // PdfWriter writer; // writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName)); document.open(); for (ReportUnit reportUnit : selectedReports) { //New page for each report. document.newPage(); //Creation of chapter object final Paragraph pageTitle = new Paragraph( String.format(PDF_PAGE_TITLE, reportUnit.getMsrunName(), timestampString), Constants.PDF_TITLE_FONT); pageTitle.setAlignment(Element.ALIGN_CENTER); final Chapter chapter1 = new Chapter(pageTitle, 1); chapter1.setNumberDepth(0); //Creation of TIC graph section object final String graphTitle = String.format(TIC_GRAPH_SECTION_TITLE, reportUnit.getMsrunName()); final Paragraph ticGraphSection = new Paragraph(graphTitle, Constants.PDF_SECTION_FONT); ticGraphSection.setSpacingBefore(PDF_PARAGRAPH_SPACING); ticGraphSection.add(Chunk.NEWLINE); //Insert TIC Graph in ticGraphSection. ticGraphSection.add(createTICChartImage(reportUnit)); chapter1.addSection(ticGraphSection); final String metricsTitle = String.format(METRICS_VALUES_SECTION_TITLE, reportUnit.getMsrunName()); final Paragraph metricsValuesSection = new Paragraph(metricsTitle, Constants.PDF_SECTION_FONT); metricsValuesSection.setSpacingBefore(PDF_PARAGRAPH_SPACING); //Reference: http://www.java-connect.com/itext/add-table-in-PDF-document-using-java-iText-library.html //TODO: Insert metrics values table in metricsValuesSection metricsValuesSection.add(createMetricsValuesTable(allMetricsMap, reportUnit)); chapter1.addSection(metricsValuesSection); //Addition of a chapter to the main document document.add(chapter1); } document.close(); return pdfFileName; } catch (final DocumentException e) { // TODO Explain when these exception can occur. /* FileNotFoundException will be thrown by the FileInputStream, FileOutputStream, and * RandomAccessFile constructors when a file with the specified path name does not exist. * It will also be thrown by these constructors if the file does exist but for some reason * is inaccessible, for example when an attempt is made to open a read-only file for writing. * DocumentException Signals that an error has occurred in a Document. */ logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e); return ""; } }
From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java
/** * Create the header for the PDF//from w w w.j a v a 2 s . c o m * * @return header */ private Paragraph header() { Paragraph par = new Paragraph("Eetcafe de hartige hap", FontFactory.getFont("Times-Roman", 20, Font.BOLD)); par.setAlignment(Element.ALIGN_CENTER); return par; }
From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java
private Paragraph header() { Paragraph par = new Paragraph("Eetcafe de hartige hap", FontFactory.getFont("Times-Roman", 20, Font.BOLD)); par.setAlignment(Element.ALIGN_CENTER); return par;/*from w ww. j a v a 2 s .c o m*/ }
From source file:nwk.com.br.documents.ClienteMaisComprouPdf.java
public void getClienteMaisComprou() throws Exception { Document doc = null;//from w ww. j ava2 s . c o m OutputStream os = null; try { //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4, 35, 35, 35, 35); //cria a stream de sada os = new FileOutputStream("C:\\PoolOrc\\Consultas\\ClienteMaisComprou.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //Definindo a font coamily.COURIER, 20, Font.BOLD);mo Courier, tamanho 20 em negrito //Font f = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Paragraph orc = new Paragraph("CLIENTE QUE MAIS COMPROU", f); orc.setAlignment(Element.ALIGN_CENTER); /*AREA DE TESTES**************************************************/ /*AREA DE TESTES**************************************************/ doc.add(cabecalho());//adiciona o cabecalho com informaes da empresa doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(orc);//esreve oramento doc.add(new Paragraph(" ")); doc.add(getCliente());//adiciona os produtos //doc.add(new Paragraph(" ")); doc.add(new Paragraph( "______________________________________________________________________________")); //doc.add(new Paragraph(" ")); /*doc.add(dadosPagamento(orcamento));//adiciona os dados de valores e forma de pagamento doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosRodape(orcamento));//adiciona o rodape ao oramento*/ //abrindo o arquivo File arquivo = new File("C:\\PoolOrc\\Consultas\\ClienteMaisComprou.pdf"); Desktop.getDesktop().open(arquivo); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } System.out.println("done"); }
From source file:nwk.com.br.documents.OrcamentoPdf.java
public void gerarPdf(Orcamento orcamento) throws Exception { Document doc = null;//from w w w . j a v a2 s . co m OutputStream os = null; cliente = clientedao.select(orcamento.getIdCliente()); try { //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4, 35, 35, 35, 35); //cria a stream de sada String caminho = "C:\\PoolOrc\\OrcPdf\\ORC" + orcamento.getId() + " " + cliente.getNome() + ".pdf"; os = new FileOutputStream(caminho); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //Definindo a font coamily.COURIER, 20, Font.BOLD);mo Courier, tamanho 20 em negrito //Font f = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Paragraph orc = new Paragraph("ORAMENTO", f); orc.setAlignment(Element.ALIGN_CENTER); /*AREA DE TESTES**************************************************/ /*AREA DE TESTES**************************************************/ doc.add(numPed(orcamento));//adiciona numero do pedido doc.add(new Paragraph(" ")); doc.add(cabecalho(orcamento));//adiciona o cabecalho com informaes da empresa doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosCliente(orcamento));//adiciona os dados do cliente doc.add(new Paragraph(" ")); doc.add(orc);//esreve oramento doc.add(new Paragraph(" ")); doc.add(dadosProdutos(orcamento));//adiciona os produtos //doc.add(new Paragraph(" ")); doc.add(new Paragraph( "______________________________________________________________________________")); //doc.add(new Paragraph(" ")); doc.add(dadosPagamento(orcamento));//adiciona os dados de valores e forma de pagamento doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosRodape(orcamento));//adiciona o rodape ao oramento //abrindo o arquivo File arquivo = new File(caminho); Desktop.getDesktop().open(arquivo); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } System.out.println("done"); }
From source file:nwk.com.br.documents.OrcamentoPdf.java
private Paragraph numPed(Orcamento orcamento) throws Exception { //cria uma linha com o numero do pedido Paragraph cod = new Paragraph("Oramento: " + orcamento.getId(), f); cod.setAlignment(Element.ALIGN_RIGHT); return cod;/*from w w w . java 2 s.c o m*/ }
From source file:nwk.com.br.documents.ProdutoMaisVendidoPdf.java
public void getProdutoMaisVendido() throws Exception { Document doc = null;//from ww w . j a v a 2 s .c o m OutputStream os = null; try { //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4, 35, 35, 35, 35); //cria a stream de sada os = new FileOutputStream("C:\\PoolOrc\\Consultas\\ProdutoMaisVendido.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //Definindo a font coamily.COURIER, 20, Font.BOLD);mo Courier, tamanho 20 em negrito //Font f = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Paragraph orc = new Paragraph("PRODUTO MAIS VENDIDO", f); orc.setAlignment(Element.ALIGN_CENTER); /*AREA DE TESTES**************************************************/ /*AREA DE TESTES**************************************************/ doc.add(cabecalho());//adiciona o cabecalho com informaes da empresa doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(orc);//esreve oramento doc.add(new Paragraph(" ")); doc.add(getProduto());//adiciona os produtos //doc.add(new Paragraph(" ")); doc.add(new Paragraph( "______________________________________________________________________________")); //doc.add(new Paragraph(" ")); /*doc.add(dadosPagamento(orcamento));//adiciona os dados de valores e forma de pagamento doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosRodape(orcamento));//adiciona o rodape ao oramento*/ //abrindo o arquivo File arquivo = new File("C:\\PoolOrc\\Consultas\\ProdutoMaisVendido.pdf"); Desktop.getDesktop().open(arquivo); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } System.out.println("done"); }
From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java
private void addParagraphToTable(PdfPTable table, String str) { Paragraph p = new Paragraph(str, BLUE_NORMAL); p.setAlignment(Element.ALIGN_CENTER); PdfPCell c = new PdfPCell(); c.addElement(p);/*from www. jav a 2s. c o m*/ c.setBorder(0); table.addCell(c); }
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
public void createPdf(String filename, Document document2) throws IOException, DocumentException { // step 1/*from w w w . ja v a2s . c o m*/ Document document = new Document(); // step 2 // OutputStream outputStream = new OutputStream(new FileOutputStream(filename)); PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 Font titleFont = new Font(Font.FontFamily.HELVETICA, 30, Font.BOLD, clr);//BaseColor.Color.getHSBColor(258, 100, 13)); Paragraph emptyLine = new Paragraph(); addEmptyLine(emptyLine, 2); Paragraph title = new Paragraph("Test Report", titleFont); title.setAlignment(Element.ALIGN_CENTER); BaseColor BC = new BaseColor(164, 188, 196); document.add(title); document.add(emptyLine); emptyLine = new Paragraph(" "); Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); // addEmptyLine(emptyLine, 0); document.add(new Paragraph("Report created on : " + ft.format(dNow), small)); document.add(emptyLine); document.add(emptyLine); document.add(emptyLine); document.add(new Paragraph("Test Summary Report", subFont)); // document.add(emptyLine); PdfPTable table = createTable1(); PdfPTable table2 = createTable2(); document.add(new Paragraph(" ")); document.add(emptyLine); document.add(table); document.add(emptyLine); document.add(emptyLine); document.add(emptyLine); document.add(new Paragraph("Test Error Report", subFont)); document.add(emptyLine); document.add(emptyLine); document.add(table2); table.setSpacingBefore(5); table.setSpacingAfter(5); table2.setSpacingBefore(5); table2.setSpacingAfter(5); // step 5 //adding graphs //PdfWriter writer ; // writer = PdfWriter.getInstance(document, outputStream); Image[] img = new Image[5]; img[0] = createGraphs("Average Response Time of samples for each Request", "Average(ms)", 2); // df *add 90%line and no of samples to csv summary model table img[1] = createGraphs("Number of samples processed for each Request", "Number of Samples", 2); img[2] = createGraphs("Error % of samples for each Request", "Error %", 6); img[3] = createGraphs("Throughput of samples for each Request", "Throughput(ms)", 7); img[4] = createGraphs("90 % Line of samples for each Request", "90% line(ms)", 2); // document.add(image1); document.add(img[0]); // document. //release resources document.close(); document = null; }