List of usage examples for com.itextpdf.text Chunk NEWLINE
Chunk NEWLINE
To view the source code for com.itextpdf.text Chunk NEWLINE.
Click Source Link
From source file:org.fossa.rolp.util.PdfStreamSource.java
License:Open Source License
private void insertDummyLineIfNecessary(PdfWriter writer) throws DocumentException { int countNewLines = 0; while (countNewLines < lebCreator.getDummyLineCount()) { countNewLines += 1;/*from w ww. ja v a2 s . c om*/ if (writer.getVerticalPosition(false) < getSchusterjungenCriticalDistance()) { break; } document.add(Chunk.NEWLINE); } }
From source file:org.jaqpot.core.service.data.ReportService.java
public void report2PDF(Report report, OutputStream os) { Document document = new Document(); document.setPageSize(PageSize.A4);/*ww w . j a v a 2 s . c o m*/ document.setMargins(50, 45, 80, 40); document.setMarginMirroring(false); try { PdfWriter writer = PdfWriter.getInstance(document, os); TableHeader event = new TableHeader(); writer.setPageEvent(event); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } document.open(); /** setup fonts for pdf */ Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC); Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC); Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); /** print link to jaqpot*/ Chunk chunk = new Chunk( "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage", ffont); chunk.setAnchor("http://www.jaqpot.org"); Paragraph paragraph = new Paragraph(chunk); paragraph.add(Chunk.NEWLINE); Chapter chapter = new Chapter(paragraph, 1); chapter.setNumberDepth(0); /** get title */ String title = null; if (report.getMeta() != null && report.getMeta().getTitles() != null && !report.getMeta().getTitles().isEmpty()) title = report.getMeta().getTitles().iterator().next(); /** print title aligned centered in page */ if (title == null) title = "Report"; chunk = new Chunk(title, chapterFont); paragraph = new Paragraph(chunk); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); chapter.add(paragraph); /** report Description */ if (report.getMeta() != null && report.getMeta().getDescriptions() != null && !report.getMeta().getDescriptions().isEmpty() && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) { paragraph = new Paragraph(); paragraph.add(new Chunk("Description: ", paragraphFontBold)); paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"), paragraphFont)); chapter.add(paragraph); chapter.add(Chunk.NEWLINE); } /** report model, algorithm and/or dataset id */ if (report.getMeta() != null && report.getMeta().getHasSources() != null && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty() && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) { Iterator<String> sources = report.getMeta().getHasSources().iterator(); sources.forEachRemaining(o -> { if (o != null) { String[] source = o.split("/"); if (source[source.length - 2].trim().equals("model") || source[source.length - 2].trim().equals("algorithm") || source[source.length - 2].trim().equals("dataset")) { Paragraph paragraph1 = new Paragraph(); paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase() + source[source.length - 2].substring(1) + ": ", paragraphFontBold)); paragraph1.add(new Chunk(source[source.length - 1], paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); } } }); } /** report single calculations */ report.getSingleCalculations().forEach((key, value) -> { Paragraph paragraph1 = new Paragraph(); paragraph1 = new Paragraph(); paragraph1.add(new Chunk(key + ": ", paragraphFontBold)); paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); }); /** report date of completion */ if (report.getMeta() != null && report.getMeta().getDate() != null) { Paragraph paragraph1 = new Paragraph(); paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold)); paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); } try { document.add(chapter); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } Integer chapterNumber = 0; /** report all_data */ for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) { String label = entry.getKey(); ArrayCalculation ac = entry.getValue(); PdfPTable table = new PdfPTable(ac.getColNames().size() + 1); for (Entry<String, List<Object>> row : ac.getValues().entrySet()) { try { XMLWorkerHelper.getInstance().parseXHtml(w -> { if (w instanceof WritableElement) { List<Element> elements = ((WritableElement) w).elements(); for (Element element : elements) { PdfPCell pdfCell = new PdfPCell(); pdfCell.addElement(element); table.addCell(pdfCell); } } }, new StringReader(row.getKey())); } catch (IOException e) { e.printStackTrace(); } for (Object o : row.getValue()) { table.addCell(o.toString()); } table.completeRow(); } try { Chunk tableChunk = new Chunk(label, tableFont); Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber); tableChapter.add(Chunk.NEWLINE); tableChapter.add(table); document.newPage(); document.add(tableChapter); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } } /** report plots */ for (Entry<String, String> entry : report.getFigures().entrySet()) { try { byte[] valueDecoded = Base64.decodeBase64(entry.getValue()); Image l = Image.getInstance(valueDecoded); document.newPage(); //image starts at the half's half of pdf page l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2)); l.scaleToFit(document.getPageSize()); Chunk tableChunk = new Chunk(entry.getKey(), tableFont); Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber); tableChapter.add(l); document.add(tableChapter); } catch (IOException | DocumentException e) { e.printStackTrace(); } } document.close(); }
From source file:org.openmrs.module.maternalsummary.pdf.impl.ITextRenderer.java
License:Open Source License
@Override public void addHeader1(String text) throws PDFRendererException { try {// w w w .j av a2 s . com Paragraph p = new Paragraph(text, FONT_HEADER1); doc.add(p); doc.add(Chunk.NEWLINE); } catch (DocumentException ex) { throw new PDFRendererException(ex); } }
From source file:org.openmrs.module.maternalsummary.pdf.impl.ITextRenderer.java
License:Open Source License
@Override public void addHeader2(String text) throws PDFRendererException { try {//from w w w .j a va2 s . c om Paragraph p = new Paragraph(text, FONT_HEADER2); doc.add(p); doc.add(Chunk.NEWLINE); } catch (DocumentException ex) { throw new PDFRendererException(ex); } }
From source file:org.openmrs.module.maternalsummary.pdf.impl.ITextRenderer.java
License:Open Source License
@Override public void addHeader3(String text) throws PDFRendererException { try {/*from w ww . j a v a 2s . c o m*/ Paragraph p = new Paragraph(text, FONT_HEADER3); doc.add(p); doc.add(Chunk.NEWLINE); } catch (DocumentException ex) { throw new PDFRendererException(ex); } }
From source file:org.openmrs.module.maternalsummary.pdf.impl.ITextRenderer.java
License:Open Source License
@Override public void tableEnd() throws PDFRendererException { try {//from w w w. ja v a 2s . c om doc.add(_table); doc.add(Chunk.NEWLINE); } catch (DocumentException ex) { throw new PDFRendererException(ex); } }
From source file:org.spinsuite.print.ReportPrintData.java
License:Open Source License
/** * Create a PDF File/*from ww w . j a va2 s. c om*/ * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com 02/04/2014, 22:52:09 * @param outFile * @throws FileNotFoundException * @throws DocumentException * @return void */ private void createPDF(File outFile) throws FileNotFoundException, DocumentException { Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile)); PDFHeaderAndFooter event = new PDFHeaderAndFooter(); writer.setPageEvent(event); document.open(); // document.addAuthor(ctx.getResources().getString(R.string.app_name)); document.addCreationDate(); // Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName()); // Set Font title.getFont().setStyle(Font.BOLD); // Set Alignment title.setAlignment(Paragraph.ALIGN_CENTER); // Add Title document.add(title); // Add New Line document.add(Chunk.NEWLINE); // Parameters ProcessInfoParameter[] param = m_pi.getParameter(); // Get Parameter if (param != null) { // boolean isFirst = true; // Iterate for (ProcessInfoParameter para : param) { // Get SQL Name String name = para.getInfo(); StringBuffer textParameter = new StringBuffer(); if (para.getParameter() == null && para.getParameter_To() == null) continue; else { // Add Parameters Title if (isFirst) { Paragraph titleParam = new Paragraph( ctx.getResources().getString(R.string.msg_ReportParameters)); // Set Font titleParam.getFont().setStyle(Font.BOLDITALIC); // Add to Document document.add(titleParam); isFirst = false; } // Add Parameters Name if (para.getParameter() != null && para.getParameter_To() != null) { // From and To is filled // textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ") .append(para.getDisplayValue_To()); } else if (para.getParameter() != null) { // Only From // textParameter.append(name).append(" = ").append(para.getDisplayValue()); } else if (para.getParameter_To() != null) { // Only To // textParameter.append(name).append(" <= ").append(para.getDisplayValue_To()); } } // Add to Document Paragraph viewParam = new Paragraph(textParameter.toString()); document.add(viewParam); } } document.add(Chunk.NEWLINE); // InfoReportField[] columns = m_reportQuery.getColumns(); // Add Table PdfPTable table = new PdfPTable(columns.length); table.setSpacingBefore(4); // Add Header PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName())); headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerCell.setColspan(columns.length); // Add to Table table.addCell(headerCell); // Add Header // Decimal and Date Format DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length]; SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length]; for (int i = 0; i < columns.length; i++) { InfoReportField column = columns[i]; // Only Numeric if (DisplayType.isNumeric(column.DisplayType)) cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern); // Only Date else if (DisplayType.isDate(column.DisplayType)) cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern); // Phrase phrase = new Phrase(column.PrintName); PdfPCell cell = new PdfPCell(phrase); if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT)) cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER)) cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); else cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED); // table.addCell(cell); } // Add Detail for (int row = 0; row < m_data.size(); row++) { // Get Row RowPrintData rPrintData = m_data.get(row); // Iterate for (int col = 0; col < columns.length; col++) { InfoReportField column = columns[col]; ColumnPrintData cPrintData = rPrintData.get(col); Phrase phrase = null; PdfPCell cell = new PdfPCell(); // String value = cPrintData.getValue(); // Only Values if (value != null) { if (DisplayType.isNumeric(column.DisplayType)) { // Number // Format DecimalFormat decimalFormat = cDecimalFormat[col]; // Format if (decimalFormat != null) value = decimalFormat.format(DisplayType.getNumber(value)); // Set Value cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } else if (DisplayType.isDate(column.DisplayType)) { // Is Date SimpleDateFormat dateFormat = cDateFormat[col]; if (dateFormat != null && value.trim().length() > 0) { long date = Long.parseLong(value); value = dateFormat.format(new Date(date)); } } } // Set Value phrase = new Phrase(value); // if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT)) cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER)) cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); else cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED); // Set Font if (rPrintData.isFunctionRow()) { // Set Function Value if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0) phrase = new Phrase(cPrintData.getFunctionValue()); // Set Font phrase.getFont().setStyle(Font.BOLDITALIC); } // Add to Table cell.setPhrase(phrase); table.addCell(cell); } } // Add Table to Document document.add(table); // New Line document.add(Chunk.NEWLINE); // Add Footer StringBuffer footerText = new StringBuffer(Env.getContext("#SUser")); footerText.append("("); footerText.append(Env.getContext("#AD_Role_Name")); footerText.append("@"); footerText.append(Env.getContext("#AD_Client_Name")); footerText.append("."); footerText.append(Env.getContext("#AD_Org_Name")); footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) "); // Date SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME); footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = "); footerText.append(pattern.format(new Date())); // Paragraph footer = new Paragraph(footerText.toString()); footer.setAlignment(Paragraph.ALIGN_CENTER); // Set Font footer.getFont().setSize(8); // Add Footer document.add(footer); // Close Document document.close(); }
From source file:org.spinsuite.view.report.ReportPrintData.java
License:Open Source License
/** * Create a PDF File// w w w . jav a2 s. c o m * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 02/04/2014, 22:52:09 * @param outFile * @throws FileNotFoundException * @throws DocumentException * @return void */ private void createPDF(File outFile) throws FileNotFoundException, DocumentException { Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile)); PDFHeaderAndFooter event = new PDFHeaderAndFooter(); writer.setPageEvent(event); document.open(); // document.addAuthor(ctx.getResources().getString(R.string.app_name)); document.addCreationDate(); // Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName()); // Set Font title.getFont().setStyle(Font.BOLD); // Set Alignment title.setAlignment(Paragraph.ALIGN_CENTER); // Add Title document.add(title); // Add New Line document.add(Chunk.NEWLINE); // Parameters ProcessInfoParameter[] param = m_pi.getParameter(); // Get Parameter if (param != null) { // boolean isFirst = true; // Iterate for (ProcessInfoParameter para : param) { // Get SQL Name String name = para.getInfo(); StringBuffer textParameter = new StringBuffer(); if (para.getParameter() == null && para.getParameter_To() == null) continue; else { // Add Parameters Title if (isFirst) { Paragraph titleParam = new Paragraph( ctx.getResources().getString(R.string.msg_ReportParameters)); // Set Font titleParam.getFont().setStyle(Font.BOLDITALIC); // Add to Document document.add(titleParam); isFirst = false; } // Add Parameters Name if (para.getParameter() != null && para.getParameter_To() != null) { // From and To is filled // textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ") .append(para.getDisplayValue_To()); } else if (para.getParameter() != null) { // Only From // textParameter.append(name).append(" = ").append(para.getDisplayValue()); } else if (para.getParameter_To() != null) { // Only To // textParameter.append(name).append(" <= ").append(para.getDisplayValue_To()); } } // Add to Document Paragraph viewParam = new Paragraph(textParameter.toString()); document.add(viewParam); } } document.add(Chunk.NEWLINE); // InfoReportField[] columns = m_reportQuery.getColumns(); // Add Table PdfPTable table = new PdfPTable(columns.length); table.setSpacingBefore(4); // Add Header PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName())); headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerCell.setColspan(columns.length); // Add to Table table.addCell(headerCell); // Add Header // Decimal and Date Format DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length]; SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length]; for (int i = 0; i < columns.length; i++) { InfoReportField column = columns[i]; // Only Numeric if (DisplayType.isNumeric(column.DisplayType)) cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern); // Only Date else if (DisplayType.isDate(column.DisplayType)) cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern); // Phrase phrase = new Phrase(column.PrintName); PdfPCell cell = new PdfPCell(phrase); if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT)) cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER)) cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); else cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED); // table.addCell(cell); } // Add Detail for (int row = 0; row < m_data.size(); row++) { // Get Row RowPrintData rPrintData = m_data.get(row); // Iterate for (int col = 0; col < columns.length; col++) { InfoReportField column = columns[col]; ColumnPrintData cPrintData = rPrintData.get(col); Phrase phrase = null; PdfPCell cell = new PdfPCell(); // String value = cPrintData.getValue(); if (DisplayType.isNumeric(column.DisplayType)) { // Number // Format DecimalFormat decimalFormat = cDecimalFormat[col]; // Format if (decimalFormat != null) value = decimalFormat.format(DisplayType.getNumber(value)); // Set Value cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } else if (DisplayType.isDate(column.DisplayType)) { // Is Date SimpleDateFormat dateFormat = cDateFormat[col]; if (dateFormat != null) { long date = Long.getLong(value, 0); value = dateFormat.format(new Date(date)); } } // Set Value phrase = new Phrase(value); // if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT)) cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER)) cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); else cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED); // Set Font if (rPrintData.isFunctionRow()) { // Set Function Value if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0) phrase = new Phrase(cPrintData.getFunctionValue()); // Set Font phrase.getFont().setStyle(Font.BOLDITALIC); } // Add to Table cell.setPhrase(phrase); table.addCell(cell); } } // Add Table to Document document.add(table); // New Line document.add(Chunk.NEWLINE); // Add Footer StringBuffer footerText = new StringBuffer(Env.getContext(ctx, "#SUser")); footerText.append("("); footerText.append(Env.getContext(ctx, "#AD_Role_Name")); footerText.append("@"); footerText.append(Env.getContext(ctx, "#AD_Client_Name")); footerText.append("."); footerText.append(Env.getContext(ctx, "#AD_Org_Name")); footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) "); // Date SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME); footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = "); footerText.append(pattern.format(new Date())); // Paragraph footer = new Paragraph(footerText.toString()); footer.setAlignment(Paragraph.ALIGN_CENTER); // Set Font footer.getFont().setSize(8); // Add Footer document.add(footer); // Close Document document.close(); }
From source file:pdf.CoverLetterUtility.java
License:Apache License
private void addTitle(Document document) { Paragraph titleParagraph = new Paragraph(); titleParagraph.setAlignment(Paragraph.ALIGN_CENTER); TitlePhrase name = new TitlePhrase(getUserFullname(), LifetimeFonts.FONT_HEADER); TitlePhrase email = new TitlePhrase(getUserEmail(), LifetimeFonts.FONT_KEY); titleParagraph.add(name);/*from www . j a v a 2s.c o m*/ titleParagraph.add(Chunk.NEWLINE); titleParagraph.add(email); titleParagraph.add(Chunk.NEWLINE); try { document.add(titleParagraph); } catch (DocumentException ex) { Logger.getLogger(CoverLetterUtility.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pdf.CoverLetterUtility.java
License:Apache License
private void addReference(Document document) { ValuePhrase position = new ValuePhrase("Position:" + jobOffer.getPosition(), LifetimeFonts.FONT_ORG); ValuePhrase reference = new ValuePhrase("Reference:" + jobOffer.getReference(), LifetimeFonts.FONT_DEFAULT); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(Paragraph.ALIGN_RIGHT); //current.setSpacingBefore(10f); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE);/* w w w .ja v a 2 s . co m*/ paragraph.add(position); paragraph.add(Chunk.NEWLINE); paragraph.add(reference); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); try { document.add(paragraph); } catch (DocumentException ex) { Logger.getLogger(CoverLetterUtility.class.getName()).log(Level.SEVERE, null, ex); } }