private void addMetaData(String barcode, DLIDownloader adminData, Document document, PdfWriter pdfWriter, Rectangle pageSize) throws DocumentException { document.addTitle(adminData.getAttr(AppConstants.Title)); document.addAuthor(adminData.getAttr(AppConstants.Author)); document.addLanguage(adminData.getAttr(AppConstants.Language)); document.addSubject(adminData.getAttr(AppConstants.Subject)); document.addCreator("DLI-Downloader Tool"); document.addHeader("Barcode", adminData.getAttr(AppConstants.BARCODE)); document.addCreationDate(); document.setPageSize(pageSize); document.setMargins(1, 1, 1, 1); PdfContentByte cb = pdfWriter.getDirectContent(); document.add(new Paragraph("Barcode - " + barcode + "\nTitle - " + adminData.getAttr(AppConstants.Title) + "\nSubject - " + adminData.getAttr(AppConstants.Subject) + "\nAuthor - " + adminData.getAttr(AppConstants.Author) + "\nLanguage - " + adminData.getAttr(AppConstants.Language) + "\nPages - " + adminData.getAttr(AppConstants.TotalPages) + "\nPublication Year - " + adminData.getAttr(AppConstants.Year) + "\nCreator - Fast DLI Downloader" + "\nhttps://github.com/cancerian0684/dli-downloader" + "\nBarcode EAN.UCC-13 \n")); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode(barcode); document.add(codeEAN.createImageWithBarcode(cb, null, null)); codeEAN.setGuardBars(true); document.newPage(); }
public void onRender( PdfContentByte cb ) throws PdfRenderException{ float[] positions = new BlockFactory().getBoundsInPs(this); BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType( BarCodeType.getBarCodeType(barCodeType).codeType ); barcode.setCode( getCode() ); barcode.setSize( getFontSize() ); barcode.setGuardBars(isShowGuardBars()); barcode.setBarHeight( positions[3] ); barcode.setTextAlignment(Element.ALIGN_RIGHT); if( getBaseFont() != null ){ barcode.setFont(getBaseFont()); } if( align.equals( "top" )){ barcode.setBaseline( -1f ); } PdfDocument request = getPage().getPdfDocument(); float pageHeight = request.getSize()[1]; float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight); com.itextpdf.text.Image image = barcode.createImageWithBarcode(cb, getBarBaseColor(), getCodeBaseColor()); image.setRotationDegrees( rotation ); image.setAbsolutePosition( positions[0] , pageHeightInPs - ( positions[1] + positions[3] + fontSize ) ); try { cb.addImage( image ); } catch (DocumentException e) { throw new PdfRenderException(e); } }
/** * The Config method to creating the desired UPC-A * @param cb - PdfContentByte * @param upc - A 12 digit String representation of the UPC * @return An Image of the UPC */ private static Image generateUPC(PdfContentByte cb, String upc){ BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.UPCA); codeEAN.setCode(upc); codeEAN.setSize(7); codeEAN.setBaseline(6f); codeEAN.setBarHeight(20f); codeEAN.setX(.7f); return codeEAN.createImageWithBarcode(cb, null, null); }