List of usage examples for com.itextpdf.text Image scalePercent
public void scalePercent(final float percent)
From source file:documentos.PlanillaServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w .j a v a 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { response.setContentType("application/pdf"); Connection conexion = null; HttpSession session = request.getSession(true); try { conexion = ds.getConnection(); edificioDAO edifDAO = new edificioDAO(); edifDAO.setConexion(conexion); usuarioDAO usuDAO = new usuarioDAO(); usuDAO.setConexion(conexion); //obtener variable boolean error = false; String idString = (String) request.getParameter("id_edificio"); int idEdificio = 0; try { idEdificio = Integer.parseInt(idString); } catch (Exception ex) { System.out.println("Error al convertir variables :" + ex); error = true; } //obtener datos de edificio segun el id edificio edif = new edificio(); edif = edifDAO.findbyIdEdificio(idEdificio); DetalleEdificioDAO detEdifDAO = new DetalleEdificioDAO(); detEdifDAO.setConexion(conexion); administradorDAO adminDAO = new administradorDAO(); adminDAO.setConexion(conexion); //obtener admin Edificio administrador admin = new administrador(); admin = adminDAO.findbyIdEdificio(idEdificio); //obtener datos de detalleEdif detalleEdificio detalleEdif = new detalleEdificio(); detalleEdif = detEdifDAO.findbyIdEdificio(idEdificio); //obtener datos de usuario segun id edificio usuario usuario = new usuario(); usuario = usuDAO.findbyIdUsuarios(edif.getIdUsuario()); //guardar datos de edif en variables separadas String nombreVendedor = usuario.getNombre(); String apellidoVendedor = usuario.getApellido(); int annoNorma = edif.getAnoEdificio(); String ubicacionMed = detalleEdif.getUbicacionMedidores(); String ciige = detalleEdif.getCiigeAnterior(); String testDePruebas = detalleEdif.getDespiche(); String nombreEdif = edif.getNombreEdificio(); String correo = admin.getEmailAdmin(); String fonoAdmin = admin.getTelefonoAdmin(); String fonoEdif = edif.getTelefonoEdificio(); String rutEdif = edif.getRutEdificio(); String dirEdif = edif.getDireccionEdificio(); String nomAdmin = admin.getNombreAdmin(); String rutAdmin = admin.getRutAdmin(); int cantidadDe = edif.getCantCasas() + edif.getCantDepartamentos() + edif.getCantLocales() + edif.getCantLavanderias(); int cantPisos = edif.getCantPisos(); int idEmpresaGas = edif.getIdGas(); //determinar el nombre de la empresa de gas segun su id String empresagas = ""; if (idEmpresaGas == 1) { empresagas = "GASVALPO"; } if (idEmpresaGas == 2) { empresagas = "LIPIGAS"; } if (idEmpresaGas == 3) { empresagas = "ABASTIBLE"; } if (idEmpresaGas == 4) { empresagas = "GASCO"; } if (idEmpresaGas == 5) { empresagas = "OTROS"; } int annoEdif = edif.getAnoEdificio(); int potencia = edif.getPotenciaReal(); int cantidaConductos = edif.getCantConductos(); int cantidadCalderas = edif.getCantCalderas(); //Crear documento Document document = new Document(); Image logo = Image.getInstance(getClass().getResource("logo.png")); PdfWriter.getInstance(document, response.getOutputStream()); Font fuenteNegrita = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD); Font fuenteNormal = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL); Font fuenteEPiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.BOLD); Font fuentePiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD); // step 3 document.open(); // step 4 logo.setAbsolutePosition(270f, 750f); logo.scalePercent(65f); PdfPTable tablaEncabezado = new PdfPTable(2); PdfPTable tablaContenido = new PdfPTable(2); tablaEncabezado.addCell(new Paragraph("PLANILLA CIIG-e INSPECCIN PERIODICA")); tablaEncabezado.addCell(logo); tablaContenido.setSpacingBefore(15); tablaContenido.setSpacingAfter(20); tablaContenido.addCell(new Paragraph("VENDEDORA", fuenteNormal)); tablaContenido.addCell(new Paragraph(nombreVendedor + " " + apellidoVendedor, fuenteNormal)); tablaContenido.addCell(new Paragraph("AO DEL EDIFICIO Y NORMA APLICAR", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(annoEdif), fuenteNormal)); tablaContenido .addCell(new Paragraph("UBICACIN MEDIDORES: EN LOS PISOS, FUERA DEL EDIFICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(ubicacionMed, fuenteNormal)); tablaContenido .addCell(new Paragraph("NRO CIIGE DE LA INSPECCION ANTERIOR (VER PAGINA SEC)", fuenteNormal)); tablaContenido.addCell(new Paragraph(ciige, fuenteNormal)); tablaContenido.addCell(new Paragraph("T DE PRUEBAS, DESPICHE OTRO (COCINA)", fuenteNormal)); tablaContenido.addCell(new Paragraph(testDePruebas, fuenteNormal)); tablaContenido.addCell(new Paragraph("NOMBRE: EDIFICIO, CONDOMINIO, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(nombreEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("CORREO ELECTRONICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(correo, fuenteNormal)); tablaContenido.addCell(new Paragraph("FONO ADMINISTRADOR /FONO EDIFICIO", fuenteNormal)); tablaContenido.addCell(new Paragraph("Fono Administrador :" + fonoAdmin + " Fono Edificio :" + fonoEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("R.U.T EDIFICIO, CONDOMINIO, PROPIETARIOS, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(rutEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("DIRECCIN DEL EDIFICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(dirEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("NOMBRE ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(nomAdmin, fuenteNormal)); tablaContenido.addCell(new Paragraph("RUT: ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(rutAdmin, fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE: DEPTOS, CASAS, LOCALES, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE PISOS INMUEBLE", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantPisos), fuenteNormal)); tablaContenido.addCell(new Paragraph("EMPRESA DISTRIBUIDORA DE GAS", fuenteNormal)); tablaContenido.addCell(new Paragraph(empresagas, fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE INSTALACIONES", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal)); tablaContenido.addCell(new Paragraph("TIPO DE ARTEFACTOS INSTALADOS", fuenteNormal)); tablaContenido.addCell(new Paragraph("", fuenteNormal)); tablaContenido.addCell(new Paragraph("POTENCIA TOTAL INSTALADA", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(potencia), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE CONDUCTOS COLECTIVOS", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidaConductos), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE CALDERAS CENTRALES", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadCalderas), fuenteNormal)); document.add(tablaEncabezado); document.add(tablaContenido); Paragraph textoIng = new Paragraph("IngeneriaRSLimitada", fuenteEPiePagina); textoIng.setAlignment(Element.ALIGN_CENTER); Paragraph textPie = new Paragraph( "Calle Montaa 754 Oficina 37-A Via Del Mar / ingenieria.sr@gmail.com - Fono 032-2697175 / 92564059", fuentePiePagina); textPie.setAlignment(Element.ALIGN_CENTER); document.add(textoIng); document.add(textPie); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:edu.ucue.jparking.srv.ExportOrdenPagoService.java
private void addContent(Document document, String cedula) throws DocumentException, UsuarioNoExistenteException, CedulaNoValidaException, ContratoNoEstablecidoException, FueraDelDiaDePagoException, BadElementException, IOException, UsuarioNoRegistradoEnUnParqueaderoException, ClassNotFoundException, FileNotFoundException, ObjectSizeException {/*from ww w . j a v a 2 s . c om*/ document.addTitle("Orden de pago del Parqueadero"); Paragraph preface = new Paragraph(); // Lets write a big header Paragraph tituloUniversidad = new Paragraph("UNIVERSIDAD DE CUENCA", catFont); Paragraph subtituloOrdenPago = new Paragraph("ORDEN DE PAGO", subFont); tituloUniversidad.setAlignment(Paragraph.ALIGN_CENTER); subtituloOrdenPago.setAlignment(Paragraph.ALIGN_CENTER); Image logoU = null; logoU = Image.getInstance(getClass().getResource("/edu/ucue/jparking/img/logo_u.png")); logoU.scalePercent(10); logoU.setAlignment(Image.ALIGN_CENTER); OrdenPagoService ops = new OrdenPagoService(); UsuarioService service = new UsuarioService(); Usuario u = service.get(cedula); OrdenPago orden = ops.getOrdenPago(cedula); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); preface.add(tituloUniversidad); addEmptyLine(preface, 1); preface.add(logoU); addEmptyLine(preface, 1); preface.add(subtituloOrdenPago); addEmptyLine(preface, 2); preface.add(new Paragraph(String.format("%s %s", "Fecha:", df.format(Calendar.getInstance().getTime())), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Cdula:", u.getCedula()), smallBody)); preface.add( new Paragraph(String.format("%s %s %s", "Nombre:", u.getNombres(), u.getApellidos()), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Direccin:", u.getDireccion()), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Telfono:", u.getTelefono()), smallBody)); preface.add(new Paragraph(String.format("%s %s", "Tipo de Usuario:", u.getTipoUsuarioString()), smallBody)); //preface.add(new Paragraph(String.format("%s %s", "Fecha de contrato:", df.format(orden.getFechaEmision().getTime())), smallBody)); preface.add(new Paragraph(String.format("%s $%.2f", "Valor a pagar:", orden.getCosto()), smallBody)); /*if(u.estaDebiendo()){ preface.add(new Paragraph("Estado: Debe")); }else{ preface.add(new Paragraph("Estado: Cancelado")); }*/ addEmptyLine(preface, 2); preface.add(new Paragraph(String.format("%s ...............................", "Firma:"), smallBody)); addEmptyLine(preface, 1); preface.add(new Paragraph(String.format("%s ..........................", "Autorizado:"), smallBody)); addEmptyLine(preface, 2); preface.add(new Paragraph("Documento generado automticamente por la aplicacin JParking.", footPage)); document.add(preface); }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment, int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize) throws DocumentException, IOException { float ratio = getRatio(masterHeight, masterWidth, pageNum); float x = Float.parseFloat(sx); float y = Float.parseFloat(sy); float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1);//from w w w . j a v a 2s . c o m if (customFontSize > 0) fontSize = customFontSize; PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum); // comment tag image (width=35pts, height=8pts) float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum); /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ float coords[] = translateRotation(trans[0], trans[1], pageNum); coords = checkBounds(coords[0], coords[1], pageNum); /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then * render the comment inside a comment box. */ if (pinned == 1) { insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment, pageNum, masterHeight, masterWidth); // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015 Rectangle rect = new Rectangle(0, 0, 0, 0); PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect, id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id); pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber()); } else { Image image = Image.getInstance(commentIMGPath); image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]); /* * Commented out by Jon Changkachith 12/09/2015 because it was throwing * DocumentException with the message "The image must have absolute positioning." image.scaleAbsoluteHeight(1); image.scaleAbsoluteWidth(1); */ image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015 image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), 0, 0, 0, 0)); fg.addImage(image); } fg.setLineWidth(.5f * ratio); fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB())); fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB())); float tHeight = scalar[1]; float tWidth = 0; if (id.length() > 3) { tWidth = (scalar[0] * (id.length() / 5f)); } else { tWidth = (scalar[0]); } fg.moveTo(coords[0], coords[1]); fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2)); fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2)); fg.lineTo(coords[0], coords[1]); fg.closePathFillStroke(); fg.fill(); // Comment number that goes on the comment tag image Phrase p = new Phrase(id); p.getFont().setColor(BaseColor.WHITE); p.getFont().setSize(8f * ratio); //comment number font size = 8f //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); float fs[] = translateRotation(f[0], f[1], pageNum); fs = checkBounds(fs[0], fs[1], pageNum); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)), (float) (fs[1] - (3 * ratio)), 0); return ""; }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
private void addLogo(Document doc) throws DocumentException, Exception { try {//from w w w. j a v a2 s . c om String logo = Executions.getCurrent().getDesktop().getWebApp().getRealPath("logo.png"); Image companyLogo = Image.getInstance(logo); companyLogo.setAbsolutePosition(35, 700); companyLogo.scalePercent(20); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
/** * // w w w .ja v a 2 s . c om * @param img * The Image to resize * @param maxWidht * maximum imageWitdh * @param maxHeight * maximum imageHeight * @param enlarge * true if the image should be enlarged if is smaller than maxWidth && maxHeigt * @return the percentual reduction scale factor (100 means no reduction) */ protected float fitImageInArea(Image img, float maxWidht, float maxHeight, boolean enlarge) { if (maxHeight <= 0 && maxWidht <= 0) throw new RuntimeException("Invalid value"); float imgWidth = img.getPlainWidth(); float imgHeight = img.getPlainHeight(); float reductionScale = 100; if (maxHeight <= 0) { reductionScale = (maxWidht / imgWidth) * 100; } else if (maxWidht <= 0) { reductionScale = (maxHeight / imgHeight) * 100; } else { float widthScale = maxWidht / imgWidth; float heightScale = maxHeight / imgHeight; reductionScale = (Math.min(widthScale, heightScale)) * 100; } if (reductionScale > 100 && !enlarge) reductionScale = 100; if (reductionScale != 100) { img.scalePercent(reductionScale); } return reductionScale; }
From source file:fc.extensions.itext.Writer.java
License:MIT License
public void writeBarcode(String barcode, float leftX, float bottomY, float scalePercent, boolean isShowCode) throws Exception { Barcode39 code39 = new Barcode39(); code39.setStartStopText(false);/*w w w.j ava 2s . c om*/ code39.setTextAlignment(PdfContentByte.ALIGN_LEFT); if (!isShowCode) { code39.setFont(null); } code39.setCode(barcode); Image image = code39.createImageWithBarcode(pdfWriterCB, this.baseColor, this.baseColor); image.setAbsolutePosition(leftX, bottomY); image.scalePercent(scalePercent); pdfWriterCB.addImage(image); }
From source file:fc.extensions.itext.Writer.java
License:MIT License
public void writeImage(String imagePath, float leftX, float bottomY, float scalePercent) throws Exception { Image image = Image.getInstance(imagePath); image.setAbsolutePosition(leftX, bottomY); if (scalePercent > 0F) { image.scalePercent(scalePercent); }/*from w ww . ja v a2s . c om*/ pdfWriterCB.addImage(image); }
From source file:Funciones.TicketPDF.java
PdfPTable tablaHeader() throws IOException, BadElementException { PdfPTable tablaheader = new PdfPTable(4); tablaheader.setTotalWidth(600);/*from www. jav a2 s.co m*/ BasededatosManager bd = new BasededatosManager(); try { ResultSet consulta = bd.consultar("SELECT logoempresa FROM configuracion"); byte[] arreglo = null; while (consulta.next()) { arreglo = consulta.getBytes("logoempresa"); } Image logo = Image.getInstance(arreglo); logo.scalePercent(15); PdfPCell celdalogo = new PdfPCell(logo); celdalogo.setBorderColor(BaseColor.WHITE); celdalogo.setColspan(4); celdalogo.setHorizontalAlignment(Element.ALIGN_CENTER); tablaheader.addCell(celdalogo); } catch (SQLException ex) { Logger.getLogger(PedidoPDF.class.getName()).log(Level.SEVERE, null, ex); } Font a = new Font(FontFamily.HELVETICA, 18, Font.BOLD, BaseColor.BLACK); PdfPCell celdatitulo = new PdfPCell(new Paragraph("PEDIDO PIZZAS", a)); celdatitulo.setColspan(2); celdatitulo.setBorderColor(BaseColor.WHITE); tablaheader.addCell(celdatitulo); PdfPCell celdafecha = new PdfPCell(new Paragraph("Fecha: " + LocalDate.now(), f)); celdafecha.setBorderColor(BaseColor.WHITE); tablaheader.addCell(celdafecha); PdfPCell celdapedido = new PdfPCell(new Paragraph("N Pedido: " + idpedido, f)); celdapedido.setBorderColor(BaseColor.WHITE); tablaheader.addCell(celdapedido); vacio.setColspan(4); vacio.setBorder(Rectangle.BOTTOM); tablaheader.addCell(vacio); return tablaheader; }
From source file:fxml.test.PDFService.java
private PdfPTable createDocumentHeader() throws IOException, BadElementException { //start creating header for the document...... PdfPTable headerTable = new PdfPTable(3); headerTable.setHorizontalAlignment(Element.ALIGN_LEFT); try {//from w w w . ja v a 2 s. c o m headerTable.setTotalWidth(new float[] { 57.5f, 531.5f, 183f }); headerTable.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } Image image = Image.getInstance(getClass().getClassLoader().getResource("img/sust.jpg")); image.scalePercent(42f); image.setAlignment(Element.ALIGN_LEFT); PdfPCell imageCell = new PdfPCell(image, false); imageCell.setPaddingTop(6); imageCell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(imageCell); //start info table..... PdfPTable infoTable = new PdfPTable(1); infoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); String universityText = "SHAHJALAL UNIVERSITY OF SCIENCE & TECHNOLOGY SYLHET, BANGLADESH"; String tabulationText = "TABULATION SHEET"; String deptText = inputs.get(0).trim(); String s1 = inputs.get(1).trim(); String s2 = inputs.get(2).trim(); String semesterText = ("B.Sc (Engg.) " + s1 + " SEMESTER EXAMINATION " + s2); String session = inputs.get(3).trim(); String date = inputs.get(4).trim(); String sessionDateText = ("SESSION:" + session + " EXAMINATION HELD IN: " + date); infoTable.addCell(getCellForHeaderString(universityText, 0, false, 0, Element.ALIGN_CENTER, font10, true)); infoTable.addCell(getCellForHeaderString(tabulationText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable.addCell(getCellForHeaderString(deptText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable.addCell(getCellForHeaderString(semesterText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable .addCell(getCellForHeaderString(sessionDateText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); //end info table..... PdfPCell infoCell = new PdfPCell(infoTable); infoCell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(infoCell); PdfPCell resultPublishDateCell = new PdfPCell( new Paragraph("Result Published On............................", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); resultPublishDateCell.setBorder(Rectangle.NO_BORDER); resultPublishDateCell.setVerticalAlignment(Element.ALIGN_MIDDLE); resultPublishDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(resultPublishDateCell); headerTable.setSpacingAfter(17.5f); // System.err.println("completed header table"); return headerTable; //end creating header for the document...... }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private void addLogo() throws IOException, DocumentException { Image image = Image.getInstance(AbstractPdfWriterGenerator.class.getResource(LOGO_IMAGE_PATH)); image.setAlignment(Image.RIGHT); image.scalePercent(FIFTY_PERCENT); document.add(image);// w w w. j ava 2 s . c om }