List of usage examples for com.itextpdf.text Image getInstance
public static Image getInstance(final Image image)
From source file:emailworkshop.EmailWorkshop.java
public static void gerarPDF(String nome, int numCert) { Calendar data = Calendar.getInstance(); // criao do objeto documento Document document = new Document() { };/*from w w w .ja v a 2s . co m*/ document.setPageSize(new Rectangle(800, 500)); try { PdfWriter.getInstance(document, new FileOutputStream("Certificado.pdf")); document.open(); // adicionando um pargrafo ao documento Image img = Image.getInstance("logo.png"); img.scaleAbsoluteWidth(620); img.scaleAbsoluteHeight(130); Paragraph texto1 = new Paragraph("\n Conferimos o presente Certificado a " + nome + " por ter " + "participado do II Workshop de Inovao, com durao de 4 horas. Onde foram apresentadas as palestras: "); Paragraph texto2 = new Paragraph( "Economia compartilha & Inovao Disruptiva - Arthur Schuler da Igreja.\n" + "Empreendedorismo: Um case de sucesso - Cludio Kopp."); Paragraph texto3 = new Paragraph( "\n\n\n\n\nRegistrado na UFPR Setor Palotina Livro 4 certificado Nr " + numCert + "."); Paragraph localData = new Paragraph("\nPalotina, " + new SimpleDateFormat("dd").format(data.getTime()) + " de " + new SimpleDateFormat("MMMM").format(data.getTime()) + " de " + new SimpleDateFormat("yyyy").format(data.getTime()) + ".\n\n"); texto1.setAlignment("center"); texto2.setAlignment("center"); texto3.setAlignment("right"); localData.setAlignment("center"); Image assinatura = Image.getInstance("assinatura.png"); assinatura.scaleAbsoluteHeight(75); assinatura.scaleAbsoluteWidth(250); assinatura.setAbsolutePosition(275, 110); document.add(img); document.add(texto1); document.add(texto2); document.add(localData); document.add(assinatura); document.add(texto3); document.close(); } catch (DocumentException | IOException de) { System.err.println(de.getMessage()); } }
From source file:empguadalupe.Menu.Evaluacion.Menu.Resultado.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed FileOutputStream archivo = null; String nombrearchivo = NombreOP.getText() + "_" + CedulaOP.getText(); try {/*from w ww .j a va 2 s. c o m*/ archivo = new FileOutputStream(nombrearchivo + ".pdf"); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(rootPane, "Cierre la ventana del PDF para poder crear uno nuevo"); return; } Document documento = new Document(); try { PdfWriter.getInstance(documento, archivo); } catch (DocumentException ex) { } documento.open(); try { Image foto = Image.getInstance("src\\imgfondo\\thumbGRUPO20EPM20CON20CIERRE202013.jpg"); foto.scaleToFit(150, 150); foto.setAlignment(Chunk.ALIGN_LEFT); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } try { documento.add(new Paragraph("RESULTADOS EVALUACION GENERAL", FontFactory.getFont("arial", // fuente 27, // tamao Font.BOLD, BaseColor.BLACK))); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("\r\n\r\n\r\n\r\n")); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Nombre del Funcionario: " + NombreOP.getText() + "\r\n\r\n")); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Cedula del Funcionario: " + CedulaOP.getText() + "\r\n\r\n")); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Registro EPM del Funcionario: " + Registro.getText() + "\r\n\r\n")); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Nombre del Gestor:" + NombreS.getText() + "\r\n\r\n")); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("\r\n\r\n")); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("RESULTADOS ", FontFactory.getFont("arial", // fuente 17, // tamao Font.BOLD, BaseColor.BLACK))); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("\r\n\r\n" + "Arranque ", FontFactory.getFont("arial", // fuente 15, // tamao Font.BOLD, BaseColor.BLACK))); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Numero de Intentos Negativos: " + CalificacionA.getText() + " " + "Tiempo: " + tiempoA)); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("\r\n\r\n" + "Paro Normal ", FontFactory.getFont("arial", // fuente 15, // tamao Font.BOLD, BaseColor.BLACK))); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Numero de Intentos Negativos: " + CalificacionA1.getText() + " " + "Tiempo: " + tiempoA1)); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("\r\n\r\n" + "Paro Rapido ", FontFactory.getFont("arial", // fuente 15, // tamao Font.BOLD, BaseColor.BLACK))); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Numero de Intentos Negativos: " + CalificacionA2.getText() + " " + "Tiempo: " + tiempoA2)); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("\r\n\r\n" + "Paro de Emergencia ", FontFactory.getFont("arial", // fuente 15, // tamao Font.BOLD, BaseColor.BLACK))); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } try { documento.add(new Paragraph("Numero de Intentos Negativos: " + CalificacionA3.getText() + " " + "Tiempo:" + tiempoA3)); } catch (DocumentException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } documento.close(); File path = new File(nombrearchivo + ".pdf"); try { Desktop.getDesktop().open(path); } catch (IOException ex) { Logger.getLogger(Resultado.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertStamp(String loc, float x, float y, int width, int height, int set, String date, int pageNum, int masterHeight, int masterWidth, String projNo) throws BadElementException, MalformedURLException, IOException, DocumentException { Image image = Image.getInstance(loc); float[] scalar = scale(x, y, width, height, masterHeight, masterWidth, pageNum); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum);// w w w.j a va 2s . com float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); float shift = 0; /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ trans = translateRotation(trans[0], trans[1], pageNum); if (set == 1) { float m = image.getPlainHeight(); float pageChunk = r[pageNum - 1].getHeight() / 10; shift = r[pageNum - 1].getHeight() / 100; scalar[1] = (int) (pageChunk); scalar[0] = (int) (image.getPlainWidth() * pageChunk) / image.getPlainHeight(); trans[0] = (int) (0 + (pageChunk * widthScalar)); trans[1] = (int) (r[pageNum - 1].getHeight() - (pageChunk * heightScalar) - (shift * (heightScalar + 2))); heightScalar = heightScalar + 1; if (heightScalar == 8) { heightScalar = 0; widthScalar = widthScalar + 2; } } if (set == 1) { image.setAbsolutePosition(trans[0] + shift, trans[1] - scalar[1]); image.scaleAbsoluteHeight(scalar[1]); image.scaleAbsoluteWidth(scalar[0]); image.setRotationDegrees(rot); } else { //swap stamp dimensions for rotated drawings if (rot > 0) { image.setAbsolutePosition(trans[0] - 2 * scalar[1], trans[1] - 2 * scalar[0]); } else { image.setAbsolutePosition(trans[0], trans[1] - 2 * scalar[1]); } image.scaleAbsoluteHeight(scalar[1] * 2); image.scaleAbsoluteWidth(scalar[0] * 2); image.setRotationDegrees(rot); } PdfContentByte fg = pds.getOverContent(pageNum); fg.addImage(image); //Added by tmittelstadt on 09/21/2012 for ticket #698 //draws a box around the date fg.setColorFill(BaseColor.WHITE); fg.setLineWidth(0f); //dmoody removed box. ticket 900 /*fg.moveTo(trans[0], trans[1] - scalar[1] * 2); fg.lineTo(trans[0], trans[1] - scalar[1] * 2 - 10); fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2 - 10); fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2); fg.lineTo(trans[0], trans[1] - scalar[1] * 2);*/ fg.closePathFillStroke(); fg.fill(); //adds the date the stamp was added to the document to the pdf Phrase p = new Phrase(date); p.getFont().setColor(BaseColor.BLACK); //Modification zreeve 10/11/2012. set font size to 11. p.getFont().setSize(9f); //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)); ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, p, (float) (trans[0]), (float) (trans[1] - scalar[1] * 2 - 12), 0); Phrase pn = new Phrase("#[" + projNo + "]"); pn.getFont().setColor(BaseColor.BLACK); pn.getFont().setSize(10f); pn.getFont().setStyle("bold"); ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, pn, (float) (trans[0]), (float) (trans[1] - scalar[1] * 2 - 22), 0); return ""; }
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);/*ww w .ja v a2 s . 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 ww. j a v a 2s . co m 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:essencialles.modelos.relatorio.tipos.MaisVendidos.java
@Override public void run() { try {/*from w w w . j a va2 s . c om*/ //criao do PDF Document doc = new Document(PageSize.A4, 72, 72, 72, 72); OutputStream saida = new FileOutputStream(this.caminho); PdfWriter.getInstance(doc, saida); doc.open(); try { //logomarca Image img = Image.getInstance("src/views/img/logomarca.png"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); } catch (BadElementException | IOException ex) { throw new RuntimeException(ex); } //paragrafo Paragraph paragrafo = new Paragraph("Relatrio de Produtos Mais Vendidos"); paragrafo.setSpacingAfter(50); paragrafo.setSpacingBefore(15); paragrafo.setFont(new Font(Font.FontFamily.COURIER, Font.BOLD)); paragrafo.setAlignment(Element.ALIGN_CENTER); doc.add(paragrafo); /*tabela PdfPTable tabela = new PdfPTable(9); tabela.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell header = new PdfPCell(new Paragraph("Todos os Produtos")); header.setColspan(9); tabela.addCell(header); tabela.addCell("Codigo"); tabela.addCell("Nome"); tabela.addCell("Marca"); tabela.addCell("Preo"); tabela.addCell("Custo"); tabela.addCell("Cor"); tabela.addCell("Descrio"); tabela.addCell("Peso"); tabela.addCell("Disponibilidade"); tabela.addCell("Validade"); adicionar linhas da tabela. for (Produto p : produtos) { String cod = p.getCod_produto() + ""; String nome = p.getNome(); String marca = p.getMarca(); String preco = p.getPreco() + ""; String custo = p.getCusto() + ""; String cor = p.getCor(); String descricao = p.getDescricao(); String peso = p.getPeso(); String disponibilidade = p.getDisponibilidade(); String validade = p.getValidade() + ""; }*/ try { saida.flush(); } catch (IOException ex) { throw new RuntimeException(ex); } doc.close(); try { saida.close(); } catch (IOException ex) { throw new RuntimeException(ex); } } catch (FileNotFoundException | DocumentException ex) { throw new RuntimeException(ex); } }
From source file:essencialles.modelos.relatorio.tipos.ProdutosTodos.java
@Override public void run() { try {/*w ww. j a v a 2s .com*/ //criao do PDF Document doc = new Document(PageSize.A4, 72, 72, 72, 72); OutputStream saida = new FileOutputStream(this.caminho); PdfWriter.getInstance(doc, saida); doc.open(); try { //logomarca Image img = Image.getInstance("src/views/img/logomarca.png"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); } catch (BadElementException | IOException ex) { throw new RuntimeException(ex); } //paragrafo Paragraph paragrafo = new Paragraph("Relatrio de Produtos"); paragrafo.setSpacingAfter(50); paragrafo.setSpacingBefore(15); paragrafo.setFont(new Font(Font.FontFamily.COURIER, Font.BOLD)); paragrafo.setAlignment(Element.ALIGN_CENTER); doc.add(paragrafo); /*tabela PdfPTable tabela = new PdfPTable(9); tabela.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell header = new PdfPCell(new Paragraph("Todos os Produtos")); header.setColspan(9); tabela.addCell(header); tabela.addCell("Codigo"); tabela.addCell("Nome"); tabela.addCell("Marca"); tabela.addCell("Preo"); tabela.addCell("Custo"); tabela.addCell("Cor"); tabela.addCell("Descrio"); tabela.addCell("Peso"); tabela.addCell("Disponibilidade"); tabela.addCell("Validade"); adicionar linhas da tabela. for (ProdutoModelo p : produtos) { String cod = p.getCod_produto() + ""; String nome = p.getNome(); String marca = p.getMarca(); String preco = p.getPreco() + ""; String custo = p.getCusto() + ""; String cor = p.getCor(); String descricao = p.getDescricao(); String peso = p.getPeso(); String disponibilidade = p.getDisponibilidade(); String validade = p.getValidade() + ""; }*/ try { saida.flush(); } catch (IOException ex) { throw new RuntimeException(ex); } doc.close(); try { saida.close(); } catch (IOException ex) { throw new RuntimeException(ex); } } catch (FileNotFoundException | DocumentException ex) { throw new RuntimeException(ex); } }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.GenUtils.java
License:Open Source License
public static Image getImage(String resourceName) throws BadElementException, MalformedURLException, IOException { return Image.getInstance(getResourceAsByteArray(resourceName)); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.GenUtils.java
License:Open Source License
public static Image getImage(URL url) throws BadElementException, MalformedURLException, IOException { return Image.getInstance(getResourceAsByteArray(url)); }
From source file:Evento.action.ZapisDoPdfAction.java
License:Apache License
public void createPDF(String[] imgURL, String place, String album) throws DocumentException { Document document = new Document(); Rectangle pageSize = new Rectangle(szerokosc, wysokosc); document.setPageSize(pageSize);//w w w .ja va 2s.c o m try { PdfWriter.getInstance(document, new FileOutputStream(new File(place, "nowy.pdf"))); document.open(); Image tlo = Image.getInstance(new URL(zdjecieTla)); tlo.setAbsolutePosition(0f, 0f); document.add(tlo); Paragraph preface = new Paragraph(album, new Font(FontFamily.HELVETICA, 72, Font.BOLDITALIC, new BaseColor(255, 255, 255))); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); document.newPage(); for (int i = 0; i < imgURL.length; i++) { Image tlo2 = Image.getInstance(new URL(zdjecieTla)); tlo2.setAbsolutePosition(0f, 0f); document.add(tlo2); Image image2 = Image.getInstance(new URL(imgURL[i])); if (szerokosc * 1.5f <= image2.getWidth() || wysokosc * 1.5f <= image2.getHeight()) { image2.scaleAbsolute(image2.getWidth() * 0.25f, image2.getHeight() * 0.25f); image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.25f) / 2, wysokosc / 2 - (image2.getHeight() * 0.25f) / 2); } else if ((szerokosc * 0.8f <= image2.getWidth() || wysokosc * 0.8f <= image2.getHeight()) && (szerokosc * 1.2f >= image2.getWidth() || wysokosc * 1.2f >= image2.getHeight())) { image2.scaleAbsolute(image2.getWidth() * 0.8f, image2.getHeight() * 0.8f); image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.8f) / 2, wysokosc / 2 - (image2.getHeight() * 0.8f) / 2); } else if ((szerokosc * 0.4f >= image2.getWidth() || wysokosc * 0.4f >= image2.getHeight()) && (szerokosc * 0.7f <= image2.getWidth() || wysokosc * 0.7f <= image2.getHeight())) { image2.scaleAbsolute(image2.getWidth() * 1.4f, image2.getHeight() * 1.4f); image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 1.4f) / 2, wysokosc / 2 - (image2.getHeight() * 1.4f) / 2); } else { image2.scaleAbsolute(image2.getWidth(), image2.getHeight()); image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth()) / 2, wysokosc / 2 - (image2.getHeight()) / 2); } for (int k = 0; k <= 1000; k++) ; for (int j = 0; j <= 1000; j++) ; document.add(image2); document.newPage(); } document.close(); } catch (Exception e) { e.printStackTrace(); } }