List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.PDFUtils.java
License:Apache License
public Paragraph setHeader(Document document, String title) throws IOException, BadElementException { Paragraph paragraph = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, BaseColor.BLACK)); paragraph.setAlignment(Element.ALIGN_CENTER); Image img = GetResizedAndCenteredImage(path + convertPath("/files/images/" + HEADERIMG)); float topMargin = img.getHeight() + 2 * PADDING[0]; img.setAbsolutePosition(PADDING[3], (PageSize.A4.getHeight() - img.getHeight()) - PADDING[0]); paragraph.add(img);/*from ww w. ja va 2 s . c o m*/ img = GetResizedAndCenteredImage(path + convertPath("/files/images/" + FOOTERIMG)); img.setAbsolutePosition((PageSize.A4.getWidth() - img.getWidth()) / 2, PADDING[2]); paragraph.add(img); float bottomMargin = img.getHeight() + 2 * PADDING[2]; document.setMargins(topMargin, PADDING[1], bottomMargin, PADDING[3]); paragraph.setSpacingAfter(1.5f * PADDING[0]); return paragraph; }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java
License:Apache License
public static PdfPTable formatReservation(Reservation reservation) { int padding = 5; GregorianCalendar created = new GregorianCalendar(); created.setTime(reservation.getCreationTime()); GregorianCalendar startTime = new GregorianCalendar(); startTime.setTime(reservation.getStartTime()); GregorianCalendar endTime = new GregorianCalendar(); endTime.setTime(reservation.getEndTime()); String personName = BookingRoomUtils.formatPersonName(reservation.getPerson()); Font title = FontFactory.getFont("Trebuchet MS", "utf-8", 15, Font.BOLD, new BaseColor(59, 70, 00)); Font header = FontFactory.getFont(FontFactory.TIMES_BOLD, 13, Font.BOLD, BaseColor.BLACK); Font value = FontFactory.getFont(FontFactory.TIMES, 13); PdfPTable table = new PdfPTable(2); PdfPCell cell;//from ww w. j a va 2s . com Phrase phrase; phrase = new Phrase("Reservation by " + personName); phrase.setFont(title); cell = new PdfPCell(phrase); cell.setColspan(2); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPadding(padding); cell.setPaddingBottom(5); table.addCell(cell); phrase = new Phrase("Date: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getDate(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("Start: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("End: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(endTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); table.setSpacingBefore(10); table.setSpacingAfter(10); return table; }
From source file:dbms_prj.Display.java
public void create_pdf() throws Exception { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf")); Image image = Image.getInstance("src/Travel partners.png"); image.scaleAbsolute(500f, 200f);//from ww w . j a v a 2 s . co m Image ima = Image.getInstance("src/images.jpg"); ima.scaleAbsolute(100f, 100f); ima.setAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(9); PdfPCell cell = new PdfPCell(new Paragraph("Ticket")); cell.setColspan(9); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("PNR"); table.addCell("BOOK_ID"); table.addCell("FLIGHT_NO"); table.addCell("NAME"); table.addCell("SOURCE"); table.addCell("DESTINATION"); table.addCell("STATUS"); table.addCell("FARE"); table.addCell("Date"); table.addCell(S1); table.addCell(S11); table.addCell(S4); table.addCell(S6 + " " + S7); table.addCell(S8); table.addCell(S9); table.addCell(S5); table.addCell(S10); table.addCell(S12); table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(30.0f); doc.open(); //doc.add(new Paragraph("Hello!! Yo this is my first pdf!")); doc.add(image); doc.add(new Paragraph("Ticket created on " + new Date().toString())); doc.add(table); //doc.add(list); doc.add(ima); doc.close(); }
From source file:dbms_prj.Status.java
public void create_pdf() throws Exception { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf")); Image image = Image.getInstance("src/Travel partners.png"); image.scaleAbsolute(500f, 200f);//from ww w . ja v a 2 s. co m Image ima = Image.getInstance("src/images.jpg"); ima.scaleAbsolute(100f, 100f); ima.setAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(9); PdfPCell cell = new PdfPCell(new Paragraph("Ticket")); cell.setColspan(9); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); table.setTotalWidth(300.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("PNR"); table.addCell("BOOK_ID"); table.addCell("FLIGHT_NO"); table.addCell("NAME"); table.addCell("SOURCE"); table.addCell("DESTINATION"); table.addCell("STATUS"); table.addCell("FARE"); table.addCell("Date"); table.addCell(S1); table.addCell(S11); table.addCell(S4); table.addCell(S6 + S7); table.addCell(S8); table.addCell(S9); table.addCell(S5); table.addCell(S10); table.addCell(S2); table.setSpacingBefore(50.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(50.0f); doc.open(); //doc.add(new Paragraph("Hello!! Yo this is my first pdf!")); doc.add(image); //doc.add(new Paragraph("Ticket created on " + new Date().toString())); doc.add(table); //doc.add(list); doc.add(ima); doc.close(); }
From source file:de.aw.awlib.pdf.PDFDocument.java
License:Open Source License
/** * Erstellt eine Tabelle im pdf/*from w w w. j ava 2s . c om*/ * * @param columnHeaders * Header der Tabellenspalten * @param rowCount * Anzahl der Tabellenzeilen * @throws DocumentException * wenn das Document nicht erstellt werden kann. */ public void createTable(@NonNull String[] columnHeaders, @Nullable String summary, int rowCount, CellCreator creator) throws DocumentException { if (summary != null) { addTableTitle(summary); } PdfPTable table = new PdfPTable(columnHeaders.length); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); for (String columnHeader : columnHeaders) { PdfPCell c1 = new PdfPCell(new Phrase(columnHeader)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnHeaders.length; column++) { table.addCell(creator.getCellContent(row, column)); } } mDocument.add(table); }
From source file:de.aw.awlib.pdf.PDFDocument.java
License:Open Source License
/** * Erstellt eine Tabelle im pdf//from ww w .ja v a 2s. c o m * * @param columnHeaders * Header der Tabellenspalten * @param cellcontent * Inhalte der Tabellenzeilen * @throws DocumentException * wenn das Document nicht erstellt werden kann. */ public void createTable(@NonNull String[] columnHeaders, @NonNull List<List<String>> cellcontent) throws DocumentException { PdfPTable table = new PdfPTable(columnHeaders.length); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); for (String columnHeader : columnHeaders) { PdfPCell c1 = new PdfPCell(new Phrase(columnHeader)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); for (List<String> cells : cellcontent) { for (String cell : cells) { table.addCell(cell); } } mDocument.add(table); }
From source file:de.aw.awlib.pdf.PDFDocument.java
License:Open Source License
/** * Erstellt eine Tabelle im pdf/*from ww w .j av a 2 s . co m*/ * * @param columnHeaders * Header der Tabellenspalten * @param cellcontent * Inhalte der Tabellenzeilen * @throws DocumentException * wenn das Document nicht erstellt werden kann. */ public void createTable(@NonNull String[] columnHeaders, @Nullable String summary, @NonNull String[][] cellcontent) throws DocumentException { if (summary != null) { addTableTitle(summary); } PdfPTable table = new PdfPTable(columnHeaders.length); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); for (String columnHeader : columnHeaders) { PdfPCell c1 = new PdfPCell(new Phrase(columnHeader)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); for (String[] cells : cellcontent) { for (String cell : cells) { table.addCell(cell); } } mDocument.add(table); }
From source file:de.beimax.talenttree.PageGeneratorSimple.java
License:Open Source License
/** * Add single talent in box/*from w w w . j av a 2 s.c om*/ * @param row row to print talent in * @param col column to print talent in * @param key key for talent information * @param multiCols span multiple columns or 1 * @param customCost custom cost of talent (instead of default) - 0 means box will not be printed */ protected void addTalent(int row, int col, String key, int multiCols, int customCost) throws Exception { // get data HeaderProperties headerProperties = parseHeaderProperty(key); // define color BaseColor bgColor = headerProperties.active ? PDFGenerator.activeColor : PDFGenerator.passiveColor; boolean headerTwoLine = headerProperties.title.contains("\n"); // calculate offsets float x = calculateColOffset(col); float y = calculateRowOffset(row); // sanity check for multiple columns if (multiCols < 1) multiCols = 1; else if (multiCols > 4) multiCols = 4; // box width and height float talentBoxWidth = PDFGenerator.talentBoxWidth * multiCols + calculateHorizontalSpacing() * (multiCols - 1); float talentBoxHeight = PDFGenerator.talentBoxHeight; // draw shapes canvas.saveState(); // draw outer rectangle drawTalentRectangle(bgColor, x, y, talentBoxWidth, talentBoxHeight); // draw left footer shape float yFooterBoxOffset = y - talentBoxHeight + PDFGenerator.talentBoxStroke; if (customCost != 0) { drawFooterShape(bgColor, x + PDFGenerator.wedgeOffset + PDFGenerator.talentBoxStroke, y - talentBoxHeight + PDFGenerator.talentBoxStroke, 25); } // draw right footer shape drawFooterShape(bgColor, x + talentBoxWidth - PDFGenerator.wedgeOffset - PDFGenerator.talentBoxStroke - 50, y - talentBoxHeight + PDFGenerator.talentBoxStroke, 50); // draw header shape drawHeaderShape(bgColor, x + PDFGenerator.talentBoxStroke * 2.5f, y - PDFGenerator.talentBoxStroke * 2.5f, talentBoxWidth - PDFGenerator.talentBoxStroke * 5, headerTwoLine, headerProperties.status); canvas.restoreState(); // draw text canvas.beginText(); canvas.setColorFill(BaseColor.WHITE); // title canvas.setFontAndSize(generator.getFontHeader(), 13); float offSetYTalentText; if (headerTwoLine) { String[] parts = headerProperties.title.split("\\n"); canvas.showTextAligned(Element.ALIGN_LEFT, parts[0], x + PDFGenerator.talentBoxStroke * 3.5f, y - PDFGenerator.talentBoxStroke * 2 - 14f, 0); canvas.showTextAligned(Element.ALIGN_LEFT, parts[1], x + PDFGenerator.talentBoxStroke * 3.5f, y - PDFGenerator.talentBoxStroke * 2 - 27f, 0); offSetYTalentText = y - PDFGenerator.talentBoxStroke * 2 - 28f; } else { canvas.showTextAligned(Element.ALIGN_LEFT, headerProperties.title, x + PDFGenerator.talentBoxStroke * 3.5f, y - PDFGenerator.talentBoxStroke * 2 - 14f, 0); offSetYTalentText = y - PDFGenerator.talentBoxStroke * 2 - 15f; } // mini text canvas.setFontAndSize(generator.getFontBold(), 6.25f); float textOffsetY = yFooterBoxOffset + 8 - 6.25f / 2 + 0.5f; // draw page canvas.showTextAligned(Element.ALIGN_CENTER, headerProperties.page, x + PDFGenerator.wedgeOffset + PDFGenerator.talentBoxStroke + 25f / 2, textOffsetY, 0); // draw costs if (customCost != 0) { if (customCost == -1) customCost = (row + 1) * 5; canvas.showTextAligned(Element.ALIGN_LEFT, getLocalizedString("Cost") + " " + customCost, x + talentBoxWidth - PDFGenerator.talentBoxStroke - 50, textOffsetY, 0); } canvas.endText(); // draw talent text canvas.setColorFill(BaseColor.BLACK); PdfPTable table = getTalentCell(key, talentBoxWidth, 9f); // too large? float max = y - talentBoxHeight; if (table.getRowHeight(0) > offSetYTalentText - max - 2 * PDFGenerator.wedgeOffset) table = getTalentCell(key, talentBoxWidth, 8.5f); // create smaller cell if (table.getRowHeight(0) > offSetYTalentText - max - 2 * PDFGenerator.wedgeOffset) table = getTalentCell(key, talentBoxWidth, 7.5f); // create tiny cell table.writeSelectedRows(0, -1, x + PDFGenerator.talentBoxStroke * 1.5f, offSetYTalentText, canvas); }
From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java
License:Open Source License
public void addTable(List<String> headers, float[] headerWidth, List<List<Map.Entry<String, BaseColor>>> cells) throws Exception { PdfPTable table = new PdfPTable(headers.size()); if (headerWidth != null) { table.setWidths(headerWidth);//from ww w . j a va 2 s .com } for (String header : headers) { PdfPCell cell = new PdfPCell( new Phrase(header, new Font(Font.FontFamily.HELVETICA, 18, Font.BOLDITALIC))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); } for (List<Map.Entry<String, BaseColor>> row : cells) { for (Map.Entry<String, BaseColor> cellItem : row) { PdfPCell cell = new PdfPCell( new Phrase(cellItem.getKey(), new Font(Font.FontFamily.HELVETICA, 14, Font.NORMAL))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(cellItem.getValue()); table.addCell(cell); } } this.document.add(table); }
From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { try {/*from ww w .jav a 2 s . c o m*/ Rectangle rect = writer.getBoxSize("art"); Image img = Image.getInstance(Converter.convertDrawableToByteArray(this.context, R.drawable.icon)); Phrase phrase = new Phrase(); phrase.add(new Chunk(img, 0, 0)); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, phrase, rect.getLeft(), rect.getBottom(), 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(String .valueOf(this.context.getString(R.string.api_page) + " " + document.getPageNumber())), rect.getRight(), rect.getBottom(), 0); } catch (Exception ex) { Helper.printException(context, ex); } }