use of com.lowagie.text.Paragraph in project Openfire by igniterealtime.
the class GraphServlet method writePDFContent.
private void writePDFContent(HttpServletRequest request, HttpServletResponse response, JFreeChart[] charts, Statistic[] stats, long starttime, long endtime, int width, int height) throws IOException {
try {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
writer.setPageEvent(new PDFEventListener(request));
document.open();
int index = 0;
int chapIndex = 0;
for (Statistic stat : stats) {
String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
String dateName = JiveGlobals.formatDate(new Date(starttime)) + " - " + JiveGlobals.formatDate(new Date(endtime));
Paragraph paragraph = new Paragraph(serverName, FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
document.add(paragraph);
paragraph = new Paragraph(dateName, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.PLAIN));
document.add(paragraph);
document.add(Chunk.NEWLINE);
document.add(Chunk.NEWLINE);
Paragraph chapterTitle = new Paragraph(++chapIndex + ". " + stat.getName(), FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD));
document.add(chapterTitle);
// total hack: no idea what tags people are going to use in the description
// possibly recommend that we only use a <p> tag?
String[] paragraphs = stat.getDescription().split("<p>");
for (String s : paragraphs) {
Paragraph p = new Paragraph(s);
document.add(p);
}
document.add(Chunk.NEWLINE);
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(width, height);
Graphics2D graphs2D = template.createGraphics(width, height, new DefaultFontMapper());
Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);
charts[index++].draw(graphs2D, rectangle2D);
graphs2D.dispose();
float x = (document.getPageSize().width() / 2) - (width / 2);
contentByte.addTemplate(template, x, writer.getVerticalPosition(true) - height);
document.newPage();
}
document.close();
// setting some response headers
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
// setting the content type
response.setContentType("application/pdf");
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
} catch (DocumentException e) {
Log.error("error creating PDF document: " + e.getMessage());
}
}
use of com.lowagie.text.Paragraph in project Openfire by igniterealtime.
the class ConversationUtils method buildPDFContent.
private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<String, Font> colorMap) {
Font roomEvent = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.ITALIC, new Color(0xFF, 0x00, 0xFF));
try {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
writer.setPageEvent(new PDFEventListener());
document.open();
Paragraph p = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.title", MonitoringConstants.NAME), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
document.add(p);
document.add(Chunk.NEWLINE);
ConversationInfo coninfo = new ConversationUtils().getConversationInfo(conversation.getConversationID(), false);
String participantsDetail;
if (coninfo.getAllParticipants() == null) {
participantsDetail = coninfo.getParticipant1() + ", " + coninfo.getParticipant2();
} else {
participantsDetail = String.valueOf(coninfo.getAllParticipants().length);
}
Paragraph chapterTitle = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.participants", MonitoringConstants.NAME) + " " + participantsDetail, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(chapterTitle);
Paragraph startDate = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.startdate", MonitoringConstants.NAME) + " " + coninfo.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(startDate);
Paragraph duration = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.duration", MonitoringConstants.NAME) + " " + coninfo.getDuration(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(duration);
Paragraph messageCount = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.messagecount", MonitoringConstants.NAME) + " " + conversation.getMessageCount(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(messageCount);
document.add(Chunk.NEWLINE);
Paragraph messageParagraph;
for (ArchivedMessage message : conversation.getMessages()) {
String time = JiveGlobals.formatTime(message.getSentDate());
String from = message.getFromJID().getNode();
if (conversation.getRoom() != null) {
from = message.getToJID().getResource();
}
String body = message.getBody();
String prefix;
if (!message.isRoomEvent()) {
prefix = "[" + time + "] " + from + ": ";
Font font = colorMap.get(message.getFromJID().toString());
if (font == null) {
font = colorMap.get(message.getFromJID().toBareJID());
}
if (font == null) {
font = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);
}
messageParagraph = new Paragraph(new Chunk(prefix, font));
} else {
prefix = "[" + time + "] ";
messageParagraph = new Paragraph(new Chunk(prefix, roomEvent));
}
messageParagraph.add(body);
messageParagraph.add(" ");
document.add(messageParagraph);
}
document.close();
return baos;
} catch (DocumentException e) {
Log.error("error creating PDF document: " + e.getMessage(), e);
return null;
}
}
use of com.lowagie.text.Paragraph in project adempiere by adempiere.
the class SmjPdfReport method generate.
/**
* genera el PDF en un ByteArrayOutputStream ** Generate PDF Report into
* ByteArrayOutputStream
*
* @return ByteArrayOutputStream
*/
public ByteArrayOutputStream generate(LinkedList<ReportTO> dataReport, String nameTrx, String[] generalTitle, String clientName, String clientNIT, String periodName, String currencyName, MReportColumn[] m_columns, String codeFont, String city, Integer logoId) {
baosPDF = new ByteArrayOutputStream();
data = dataReport;
String[] fontPar = codeFont.split("-");
Integer lFont = Integer.parseInt(fontPar[2]);
titleFont = FontFactory.getFont(fontPar[0], lFont + 5, Font.BOLDITALIC);
titleTableFont = FontFactory.getFont(fontPar[0], lFont + 2, Font.BOLDITALIC);
catFont = FontFactory.getFont(fontPar[0], lFont + 2, Font.BOLD);
subFont = FontFactory.getFont(fontPar[0], lFont, Font.NORMAL);
try {
// izq-der-arrib
document = new Document(PageSize.LETTER, 20, 20, 20, 40);
writer = PdfWriter.getInstance(document, baosPDF);
document.open();
// metadata del documento
document.addTitle(generalTitle[0]);
document.addAuthor("SmartJSP S.A.S.");
document.addCreator("SmartJSP S.A.S.");
onOpenDocument(writer, document);
onEndPage(writer, document);
// //////////////////////////////////////////////////////////////////////////////////////
// agrega el logo
// add logo
java.awt.Image img;
if (logoId > 0) {
MImage mimage = MImage.get(Env.getCtx(), logoId);
byte[] imageData = mimage.getData();
img = Toolkit.getDefaultToolkit().createImage(imageData);
} else {
// 48x15
img = org.compiere.Adempiere.getImageLogoSmall(true);
}
com.lowagie.text.Image logo = com.lowagie.text.Image.getInstance(img, null);
logo.scaleToFit(100, 30);
document.add(logo);
// Titulo General - general Title
Paragraph genTitle = new Paragraph(dataNull(generalTitle[0]).toUpperCase(), titleFont);
genTitle.setAlignment(Paragraph.ALIGN_CENTER);
document.add(genTitle);
// empresa - Company
Paragraph clitName = new Paragraph(dataNull(clientName).toUpperCase(), titleFont);
clitName.setAlignment(Paragraph.ALIGN_CENTER);
document.add(clitName);
// Ciudad - City
Paragraph cliCity = new Paragraph(dataNull(city).toUpperCase(), titleFont);
cliCity.setAlignment(Paragraph.ALIGN_CENTER);
document.add(cliCity);
// NIT
Paragraph cliNIT = new Paragraph(dataNull(clientNIT).toUpperCase(), titleFont);
cliNIT.setAlignment(Paragraph.ALIGN_CENTER);
document.add(cliNIT);
// periodo - Period
String pn = "";
if (generalTitle[1] != null && generalTitle[1].length() > 0) {
pn = generalTitle[1] + " " + periodName;
} else {
pn = periodName;
}
if (generalTitle[2] != null && generalTitle[2].length() > 0) {
pn = pn + " " + generalTitle[2];
}
Paragraph perName = new Paragraph(dataNull(pn).toUpperCase(), titleTableFont);
perName.setAlignment(Paragraph.ALIGN_CENTER);
document.add(perName);
// tipo moneda - currency
Paragraph currency = new Paragraph(dataNull(currencyName), titleTableFont);
currency.setAlignment(Paragraph.ALIGN_CENTER);
addEmptyLine(currency, 2);
document.add(currency);
cols = m_columns.length + 2;
float[] columnWidths = new float[cols];
columnWidths[0] = 1f;
columnWidths[1] = 3f;
for (int i = 2; i < cols; i++) {
columnWidths[i] = 1f;
}
table = new PdfPTable(columnWidths);
// //Titulos de la tabla - Table titles
// Nombre - name
PdfPCell cellTitle = new PdfPCell(new Paragraph(Msg.translate(Env.getCtx(), "name").toUpperCase(), catFont));
cellTitle.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
table.addCell(cellTitle);
// Desripcion - description
cellTitle = new PdfPCell(new Paragraph(Msg.translate(Env.getCtx(), "description").toUpperCase(), catFont));
cellTitle.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
table.addCell(cellTitle);
// columnas de valores - Value Columns
for (MReportColumn mcol : m_columns) {
String colName = mcol.getName();
cellTitle = new PdfPCell(new Paragraph(colName.toUpperCase(), catFont));
cellTitle.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
table.addCell(cellTitle);
}
//for columnas
// TABLA DEL REPORTE - REPORT TABLE
reportTable();
document.add(table);
// funciones que ponen el pie del porte - put footer
onEndPage(writer, document);
onCloseDocument(writer, document);
document.close();
} catch (Exception e) {
System.out.println("SMpdfReport(generar)ERROR:: al crear el documento PDF");
System.out.println(e.getMessage());
e.printStackTrace();
}
return baosPDF;
}
use of com.lowagie.text.Paragraph in project adempiere by adempiere.
the class SmjPdfReport method reportTable.
// generar
/**
* coloca la tabla en el reporte ** Put table in report
*/
public void reportTable() {
PdfPCell tableCell;
Iterator<ReportTO> itRep = data.iterator();
while (itRep.hasNext()) {
ReportTO rpt = itRep.next();
if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("T")) {
// Coloca titulo - put title
PdfPCell title = new PdfPCell(new Paragraph(dataNull(rpt.getDescription()), titleTableFont));
title.setColspan(cols);
title.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
title.setBorder(0);
table.addCell(title);
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("L")) {
// coloca linea en el reporte - Put under line in the report
PdfPCell line = new PdfPCell(new Paragraph("", subFont));
line.setColspan(cols);
line.setBorderWidthLeft(0);
line.setBorderWidthRight(0);
line.setBorderWidthTop(0);
line.setBorderColorBottom(Color.BLACK);
table.addCell(line);
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("X")) {
// coloca linea de total - Put total line
simpleLine();
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("Z")) {
// coloca linea doble de total - Put total line doble
for (int j = 0; j < 2; j++) {
simpleLine();
}
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("D")) {
// coloca liena de descripcion - put description line
tableCell = new PdfPCell(new Phrase(""));
tableCell.setBorder(0);
table.addCell(tableCell);
tableCell = new PdfPCell(new Phrase(""));
tableCell.setBorderWidthLeft(0);
tableCell.setBorderWidthRight(0);
tableCell.setBorderWidthTop(0);
tableCell.setBorderColorBottom(Color.BLACK);
table.addCell(tableCell);
for (int i = 0; i < (cols - 2); i++) {
tableCell = new PdfPCell(new Phrase(""));
tableCell.setBorder(0);
table.addCell(tableCell);
}
// for
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("S")) {
// coloca linea en blanco - put empty line
PdfPCell line = new PdfPCell(new Paragraph(" "));
line.setColspan(cols);
line.setBorder(0);
table.addCell(line);
} else if (rpt.getTablevel() != null && rpt.getTablevel() > 0) {
// coloca espacios a la izquierda para simular jeraquia - put
// left spaces to simulate hierarchy
String jerarchy = "";
for (int i = 1; i <= rpt.getTablevel(); i++) {
jerarchy = jerarchy + " ";
}
PdfPCell line = new PdfPCell(new Paragraph(jerarchy + dataNull(rpt.getDescription()), catFont));
line.setColspan(cols);
line.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
line.setBorder(0);
table.addCell(line);
} else {
if (rpt.getDescription() != null) {
// nombre - name
tableCell = new PdfPCell(new Phrase(dataNull(rpt.getName()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
table.addCell(tableCell);
// descripcion - description
tableCell = new PdfPCell(new Phrase(dataNull(rpt.getDescription()), subFont));
tableCell.setBorder(0);
table.addCell(tableCell);
// columnas 0 a 20 - cols 0 to 20
if (cols >= 3) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_0()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 4) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_1()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 5) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_2()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 6) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_3()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 7) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_4()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 8) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_5()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 9) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_6()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 10) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_7()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 11) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_8()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 12) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_9()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 13) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_10()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 14) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_11()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 15) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_12()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 16) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_13()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 17) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_14()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 18) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_15()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 19) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_16()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 20) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_17()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 21) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_18()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 22) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_19()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
if (cols >= 23) {
tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_20()), subFont));
tableCell.setBorder(0);
tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
table.addCell(tableCell);
}
}
// if description NO null
}
// final else
}
// while
}
use of com.lowagie.text.Paragraph in project activityinfo by bedatadriven.
the class ThemeHelper method elementTitle.
public static Paragraph elementTitle(String title) {
Paragraph para = new Paragraph(title);
para.setFont(new Font(Font.TIMES_ROMAN, HEADER2_FONT_SIZE, Font.BOLD, BLUE2));
para.setSpacingBefore(BODY_FONT_SIZE);
return para;
}
Aggregations