List of usage examples for com.lowagie.text.pdf Barcode39 setExtended
public void setExtended(boolean extended)
From source file:biblivre3.administration.reports.AssetHoldingFullReport.java
License:Open Source License
@Override protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception { AssetHoldingDto dto = (AssetHoldingDto) reportData; String title = ""; if (this.topographic) { title = this.getText("REPORTS_TOPOGRAPHIC_TITLE"); } else {//from www.j a v a2 s . com title = this.getText("REPORTS_ASSET_HOLDING_TITLE"); } Paragraph p1 = new Paragraph(title); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); document.add(new Phrase("\n")); PdfPTable table = new PdfPTable(20); table.setWidthPercentage(100f); createHeader(table); PdfPCell cell; List<String[]> dataList = dto.getData(); Collections.sort(dataList, this); for (String[] data : dataList) { PdfContentByte cb = getWriter().getDirectContent(); String holdingSerial = StringUtils.leftPad(data[0], 10, "0"); Barcode39 code39 = new Barcode39(); code39.setExtended(true); code39.setCode(holdingSerial); code39.setStartStopText(false); Image image39 = code39.createImageWithBarcode(cb, null, null); image39.scalePercent(100f); cell = new PdfPCell(new Paragraph(new Phrase(new Chunk(image39, 0, 0)))); cell.setColspan(6); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1]))); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); Paragraph para = new Paragraph(); para.add(new Phrase(this.getSmallFontChunk(data[2] + "\n"))); para.add(new Phrase(this.getSmallFontChunk(data[3] + "\n"))); if (StringUtils.isNotBlank(data[4])) { para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_LOCATION") + ": "))); para.add(new Phrase(this.getSmallFontChunk(data[4] + " "))); } if (StringUtils.isNotBlank(data[5])) { para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_EDITION") + ": "))); para.add(new Phrase(this.getSmallFontChunk(data[5] + " "))); } if (StringUtils.isNotBlank(data[6])) { para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_DATE") + ": "))); para.add(new Phrase(this.getSmallFontChunk(data[6]))); } cell = new PdfPCell(para); cell.setColspan(11); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.setPaddingTop(5f); cell.setPaddingLeft(7f); cell.setPaddingBottom(4f); table.addCell(cell); } document.add(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 {//from w w w .j a v a 2s . com 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 w w . ja va 2s . 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; }