List of usage examples for com.itextpdf.text Image setPaddingTop
public void setPaddingTop(float paddingTop)
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfImpressaoBarraDeCodigo(String codigo) { Document documento = new Document(new Rectangle(90, 65)); documento.setMargins(0, 0, 0, 0);/* w w w . j a v a2s . c om*/ PdfWriter pdf; try { pdf = PdfWriter.getInstance(documento, new FileOutputStream("codigodebarras.pdf")); documento.open(); PdfContentByte contB = pdf.getDirectContent(); Barcode128 barCode = new Barcode128(); barCode.setCode(codigo); barCode.setCodeType(Barcode128.CODE128); Image image = barCode.createImageWithBarcode(contB, BaseColor.BLACK, BaseColor.BLACK); Paragraph titulo = new Paragraph("ATCADO DOS PISOS\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 5)); titulo.setPaddingTop(0); titulo.setAlignment(Element.ALIGN_CENTER); float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin() - 0) / image.getWidth()) * 60; image.scalePercent(scaler); image.setPaddingTop(0); image.setAlignment(Element.ALIGN_CENTER); documento.add(titulo); documento.add(image); documento.close(); Desktop.getDesktop().open(new File("codigodebarras.pdf")); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }