List of usage examples for com.lowagie.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:biblivre3.administration.reports.ReservationReport.java
License:Open Source License
private void createBody(PdfPTable table, List<String[]> dataList) { if (dataList == null || dataList.isEmpty()) { return;// w w w . j ava 2s .c om } for (String[] data : dataList) { PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[3]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[4]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } }
From source file:biblivre3.administration.reports.SearchesByDateReport.java
License:Open Source License
private PdfPTable createTable(SearchesByDateReportDto dto) { PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); //Table header PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell);/*from w w w . j a va2s . co m*/ cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); //Table body if (dto.getData() == null || dto.getData().isEmpty()) return table; for (String[] data : dto.getData()) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.SummaryReport.java
License:Open Source License
@Override protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception { SummaryReportDto dto = (SummaryReportDto) reportData; Paragraph p1 = new Paragraph(this.getText("REPORTS_SUMMARY_TITLE")); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1);// w w w. ja v a2 s .c o m document.add(new Phrase("\n")); PdfPTable table = new PdfPTable(10); table.setWidthPercentage(100f); createHeader(table); Collections.sort(dto.getData(), this); PdfPCell cell; for (String[] data : dto.getData()) { cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[6]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[0]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[2]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[3]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[4]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[5]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[7]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); }
From source file:biblivre3.administration.reports.SummaryReport.java
License:Open Source License
private void createHeader(PdfPTable table) { PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_DEWEY")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell);//from w ww.j a v a 2 s . c o m cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_TITLE")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_AUTHOR")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_ISBN")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_EDITOR")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_YEAR")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_EDITION")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_HOLDINGS_TOTAL")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); }
From source file:biblivre3.administration.reports.UserReport.java
License:Open Source License
private PdfPTable createLendingsTable(List<String[]> lendings) { PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100f);// w w w . j a va 2 s .c om PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TITLE")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_AUTHOR")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); for (String[] lending : lendings) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[1]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.UserReport.java
License:Open Source License
private PdfPTable createUserDataTable(UserDTO user) { PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f);// ww w. j av a2 s . co m PdfPCell cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_NAME")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getName()))); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ENROL")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(user.getUserid())))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_SIGNUP_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); Date signupDate = user.getSignup_date(); cell = new PdfPCell( new Paragraph(this.getNormalChunk(signupDate != null ? dateFormat.format(signupDate) : ""))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_SOCIAL_NUMBER")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getSocial_id_number()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ID")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getDlicense() + " " + user.getTypeId()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_BIRTHDATE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getBirthday()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_OBS")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getObs()))); cell.setColspan(4); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); return table; }
From source file:biblivre3.administration.reports.UserReport.java
License:Open Source License
private PdfPTable createAddressTable(UserDTO user) { PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f);/*from w w w . j av a2 s .c om*/ PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ADDRESS")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getAddress()))); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_NUMBER")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getNumber()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ADDRESS_2")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getCompletion()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_CITY")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getCity()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_STATE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getState()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_COUNTRY")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getCountry()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ZIP_CODE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getZip_code()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_HOME_PHONE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getTelRef1()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_MOBILE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getCellphone()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_OFFICE_PHONE")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getTelRef2()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_EXTENSION")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getExtension_line()))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_EMAIL")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(user.getEmail()))); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); return table; }
From source file:biblivre3.cataloging.bibliographic.BiblioBO.java
License:Open Source License
public MemoryFileDTO createFileLabelsPDF(ArrayList<LabelDTO> labels, LabelConfigDTO labelConfig) { Document document = new Document(); final MemoryFileDTO file = new MemoryFileDTO(); file.setFileName("biblivre_etiquetas_" + new Date().getTime() + ".pdf"); try {// www. j a va2 s. c om ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.setPageSize(PageSize.A4); float verticalMargin = (297.0f - (labelConfig.getHeight() * labelConfig.getRows())) / 2; document.setMargins(7.15f * ApplicationConstants.MM_UNIT, 7.15f * ApplicationConstants.MM_UNIT, verticalMargin * ApplicationConstants.MM_UNIT, verticalMargin * ApplicationConstants.MM_UNIT); document.open(); PdfPTable table = new PdfPTable(labelConfig.getColumns()); table.setWidthPercentage(100f); PdfPCell cell; int i = 0; for (i = 0; i < labelConfig.getOffset(); i++) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setFixedHeight(labelConfig.getHeight() * ApplicationConstants.MM_UNIT); table.addCell(cell); } for (LabelDTO ldto : labels) { PdfContentByte cb = writer.getDirectContent(); String holdingSerial = String.valueOf(ldto.getHoldingSerial()); while (holdingSerial.length() < 10) { holdingSerial = "0" + holdingSerial; } Barcode39 code39 = new Barcode39(); code39.setExtended(true); code39.setCode(holdingSerial); code39.setStartStopText(false); Image image39 = code39.createImageWithBarcode(cb, null, null); if (labelConfig.getHeight() > 30.0f) { image39.scalePercent(110f); } else { image39.scalePercent(90f); } Paragraph para = new Paragraph(); Phrase p1 = new Phrase(StringUtils.left(ldto.getAuthor(), 28) + "\n"); Phrase p2 = new Phrase(StringUtils.left(ldto.getTitle(), 28) + "\n\n"); Phrase p3 = new Phrase(new Chunk(image39, 0, 0)); para.add(p1); para.add(p2); para.add(p3); cell = new PdfPCell(para); i++; cell.setNoWrap(true); cell.setFixedHeight(labelConfig.getHeight() * ApplicationConstants.MM_UNIT); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); Paragraph para2 = new Paragraph(); Phrase p5 = new Phrase(ldto.getLocationA() + "\n"); Phrase p6 = new Phrase(ldto.getLocationB() + "\n"); Phrase p7 = new Phrase(ldto.getLocationC() + "\n"); Phrase p8 = new Phrase(ldto.getLocationD() + "\n"); Phrase p4 = new Phrase(ldto.getAssetHolding() + "\n"); para2.add(p5); para2.add(p6); para2.add(p7); para2.add(p8); para2.add(p4); cell = new PdfPCell(para2); i++; cell.setFixedHeight(labelConfig.getHeight() * ApplicationConstants.MM_UNIT); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } if ((i % labelConfig.getColumns()) != 0) { while ((i % labelConfig.getColumns()) != 0) { i++; cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } } document.add(table); writer.flush(); document.close(); file.setFileData(baos.toByteArray()); } catch (Exception de) { System.out.println(de.getMessage()); } return file; }
From source file:biblivre3.circulation.CirculationBO.java
License:Open Source License
public MemoryFileDTO createFileUserCardsPDF(ArrayList<UserCardDTO> cards, int startOffset, Properties i18n) { Document document = new Document(); MemoryFileDTO file = new MemoryFileDTO(); file.setFileName("user_cards_" + new Date().getTime() + ".pdf"); try {/*from w ww .jav a 2 s . com*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.setPageSize(PageSize.A4); document.setMargins(7.15f * ApplicationConstants.MM_UNIT, 7.15f * ApplicationConstants.MM_UNIT, 9.09f * ApplicationConstants.MM_UNIT, 9.09f * ApplicationConstants.MM_UNIT); document.open(); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell; int i = 0; for (i = 0; i < startOffset; i++) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setFixedHeight(46.47f * ApplicationConstants.MM_UNIT); table.addCell(cell); } for (UserCardDTO card : cards) { String userEnrollNumber = String.valueOf(card.getUserId()); PdfContentByte cb = writer.getDirectContent(); Barcode39 code39 = new Barcode39(); code39.setExtended(true); while (userEnrollNumber.length() < 10) { userEnrollNumber = "0" + userEnrollNumber; } code39.setCode(userEnrollNumber); code39.setStartStopText(false); Image image39 = code39.createImageWithBarcode(cb, null, null); image39.scalePercent(110f); Paragraph para = new Paragraph(); String name = card.getUserName(); name = name.length() >= 30 ? name.substring(0, 30) : name; Phrase p1 = new Phrase(name + "\n"); Phrase p2 = new Phrase(new Chunk(image39, 0, 0)); Phrase p3 = new Phrase( I18nUtils.getText(i18n, "LABEL_USER_SERIAL") + ": " + card.getUserId() + "\n"); Phrase p4 = new Phrase( I18nUtils.getText(i18n, "LABEL_USER_TYPE") + ": " + card.getUserType() + "\n\n"); para.add(p1); para.add(p3); para.add(p4); para.add(p2); cell = new PdfPCell(para); i++; cell.setFixedHeight(46.47f * ApplicationConstants.MM_UNIT); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } if ((i % 3) != 0) { while ((i % 3) != 0) { i++; cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } } document.add(table); writer.flush(); document.close(); writer.close(); file.setFileData(baos.toByteArray()); } catch (DocumentException de) { System.out.println(de.getMessage()); } return file; }
From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java
License:Open Source License
private static void geraCabecalho(PdfPTable table) { PdfPCell cell; cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.P_V)); cell.setBorderWidth(1.5f);//from w w w. j a va 2s.c om cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.DESCRICAO)); cell.setColspan(3); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.OCORRENCIAS)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.LINHAS)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); }