List of usage examples for com.itextpdf.text Document add
public boolean add(Element element) throws DocumentException
Element
to the Document
. From source file:beans.SolicitudDeMantenimientoPDF.java
public void createPdf(String dest) throws IOException, DocumentException { Parametrizacion p = new Parametrizacion(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();/*from w w w . j a v a 2 s.c om*/ PdfPTable table = new PdfPTable(12); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell celda; table.setWidthPercentage(100); Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png"); celda = new PdfPCell(img, true); celda.setPadding(5); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("CODIGO: " + sm.getCodigo() + "\nREVISION: " + sm.getRevision() + "\nSOLICITUD DE SERVICIO: " + sm.getSolicitudDeServicio() + "\nFECHA: " + sm.getFecha() + "", font)); celda.setColspan(8); // head.setBackgroundColor(BaseColor.CYAN); table.addCell(celda); celda = new PdfPCell(new Phrase("SECCION", font)); celda.setColspan(4); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("MAQUINA", font)); celda.setColspan(4); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("NOMBRE DEL OPERARIO", font)); celda.setColspan(4); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getEquipo().getUbicacion(), font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getEquipo().getNombre(), font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getEquipo().getOperario(), font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); String reparacion = " "; String mtoMecanico = " "; String mtoPreventivo = " "; String mtoElectrico = " "; String mtoCorrectivo = " "; String otros = " "; if (sm.isReparacion()) { reparacion += " X"; } if (sm.isMtoMecanico()) { mtoMecanico += " X"; } if (sm.isMtoPreventivo()) { mtoPreventivo += " X"; } if (sm.isMtoElectrico()) { mtoElectrico += " X"; } if (sm.isMtoCorrectivo()) { mtoCorrectivo += " X"; } if (sm.isOtros()) { otros += " X"; } celda = new PdfPCell(new Phrase("REPARACION", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(reparacion, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. MECANICO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoMecanico, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. PREVENTIVO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoPreventivo, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. ELECTRICO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoElectrico, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. CORRECTIVO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoCorrectivo, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("OTROS", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(otros, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DEL SERVICIO SOLICITADO", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getDescripcionServicio(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE ACCIONES A REALIZAR", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getDescripcionAcciones(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("MATERIAL A EMPLEAR", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getMaterial(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("GENERALIDADES", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + sm.getHorasParada() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("HORA SOLICITUD: " + sm.getHoraSolicitud() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + sm.getHorasMTO() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("HORA ENTREGA: " + sm.getHoraEntrega() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO POR: " + sm.getSolicitadoPor() + "\n" + "SERVICIO REALIZADO POR: " + sm.getRealizadoPor() + "\n" + "RECIBO A CONFORMIDAD: " + sm.getRecibidoPor() + "\n\n\n FIRMA", font)); celda.setColspan(12); table.addCell(celda); document.add(table); document.close(); }
From source file:bemyguest.controller.ValidationResevation.java
@FXML private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException { Resrevation e = tab_reservation.getSelectionModel().getSelectedItem(); if (e == null) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle("Warning Dialog"); alert.setHeaderText(null);//from ww w . j ava 2s. c o m alert.setContentText("selectionner un demande de reservation a traiter svp!"); alert.showAndWait(); LoadData(); setCellTable(); } else { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Confiramtion"); alert.setHeaderText(null); alert.setContentText("vous etes sur d'accepter cette demande de reservation"); Optional<ButtonType> answer = alert.showAndWait(); if (answer.get() == ButtonType.OK) { ResevationDAO dao = new ResevationDAO(); if (dao.ajouter_Reservation(e)) { LoadData(); setCellTable(); alert.setTitle("Success Dialog"); alert.setHeaderText(null); alert.setContentText("Demandes accepter avec success"); alert.showAndWait(); try { Document d = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf")); d.open(); d.add(new Paragraph("BeMyGuest Facture :", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); d.add(new Paragraph(new Date().toString())); d.add(new Paragraph( "-------------------------------------------------------------------------------------------------------------")); d.add(new Paragraph(" ")); d.add(new Paragraph(" ")); PdfPTable pdt = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.RED); pdt.addCell(cell); pdt.addCell(new Paragraph("Nom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prenom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Debut:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Fin:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre chambre:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre personne:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prix:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getNom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateDebut().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateFin().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(e.getDateDebut().toString()); int nb = e.getPropriete().getNbrChambre(); float pr = e.getPropriete().getPrix(); int nbp = e.getPropriete().getNbrVoyageur(); pdt.addCell(new Paragraph(Integer.toString(nb), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Integer.toString(nbp), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Float.toString(pr), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(Float.toString(pr)); d.add(pdt); d.close(); } catch (Exception b) { JOptionPane.showMessageDialog(null, b); } } else { alert.setTitle("Error Dialog"); alert.setHeaderText(null); alert.setContentText("Cette Propriete Reserver pendant cette date "); alert.showAndWait(); LoadData(); setCellTable(); } } else { LoadData(); setCellTable(); } } }
From source file:bencoding.pdf.ConvertersProxy.java
License:Open Source License
@Kroll.method public TiBlob convertImageToPDF(TiBlob blob, @Kroll.argument(optional = true) Object resolution) throws Exception { TiBlob result = null;// ww w . ja va 2 s.c om Bitmap bitmap = null; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TiDrawableReference ref = TiDrawableReference.fromBlob(getActivity(), blob); Document document = new Document(); try { PdfWriter.getInstance(document, outputStream); document.open(); bitmap = ref.getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] bitmapdata = stream.toByteArray(); Image image1 = Image.getInstance(bitmapdata); document.add(image1); document.close(); byte[] bytes = outputStream.toByteArray(); result = TiBlob.blobFromData(bytes); return result; } catch (FileNotFoundException e) { e.printStackTrace(); Log.i(PdfModule.MODULE_FULL_NAME, e.toString()); } catch (DocumentException e) { Log.i(PdfModule.MODULE_FULL_NAME, e.toString()); e.printStackTrace(); } finally { if (bitmap != null) { bitmap.recycle(); bitmap = null; } outputStream = null; ref = null; document = null; } return result; }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Alunos public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null; OutputStream os = null;//w w w . j a v a2 s .c om try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("TabelaA.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaA = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.9f, 0.7f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Alunos")); header.setColspan(5); tabelaA.addCell(header); tabelaA.addCell("ID"); tabelaA.addCell("Matrcula"); tabelaA.addCell("Nome"); tabelaA.addCell("C.P.F"); tabelaA.addCell("Telefone"); Statement stA = conn.conectar1().createStatement(); ResultSet rsa = stA.executeQuery("SELECT idAluno,matriculaAluno,nomeAluno,nCPF,Telefone FROM `Aluno`;"); while (rsa.next()) { Aluno a = new Aluno(0, 0, "", "", ""); a.setIdaluno(rsa.getInt("idAluno")); a.setMatricula(rsa.getInt("matriculaAluno")); a.setNoAluno(rsa.getString("nomeAluno")); a.setCpf(rsa.getString("nCPF")); a.setTelefone(rsa.getString("Telefone")); tabelaA.addCell(String.valueOf(a.getIdaluno())); tabelaA.addCell(String.valueOf(a.getMatricula())); tabelaA.addCell(a.getNoAluno()); tabelaA.addCell(a.getCpf()); tabelaA.addCell(a.getTelefone()); } doc.add(tabelaA); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Livros public void pdfL() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null; OutputStream os = null;/*from w w w .j a va 2 s .c o m*/ try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("TabelaL.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaL = new PdfPTable(new float[] { 0.1f, 0.7f, 0.7f, 0.1f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Livros")); header.setColspan(4); tabelaL.addCell(header); tabelaL.addCell("ID"); tabelaL.addCell("Ttulo"); tabelaL.addCell("Autor"); tabelaL.addCell("Qtde."); Statement st = conn.conectar1().createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM `Livro`;"); while (rs.next()) { Livro l = new Livro(0, "", "", 0, 0); l.setIdlivro(rs.getInt("idlivro")); l.setTiLivro(rs.getString("nomeLivro")); l.setNoAutor(rs.getString("nomeAutor")); l.setQtdeLivro(rs.getInt("qtdelivro")); tabelaL.addCell(String.valueOf(l.getIdlivro())); tabelaL.addCell(l.getTiLivro()); tabelaL.addCell(l.getNoAutor()); tabelaL.addCell(String.valueOf(l.getQtdeLivro())); } doc.add(tabelaL); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Reservas public void pdfR() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null; OutputStream os = null;//from ww w .j a va2 s . c o m try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("Tabela de Reservas.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaR = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.7f, 0.7f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Reservas")); header.setColspan(5); tabelaR.addCell(header); tabelaR.addCell("ID"); tabelaR.addCell("Ttulo do Livro"); tabelaR.addCell("Aluno"); tabelaR.addCell("Data de Saida"); tabelaR.addCell("Data de Entrega"); Statement stR = conn.conectar1().createStatement(); ResultSet rsr = stR.executeQuery( "SELECT Itens.id_Itens as \"Item\", Itens.id_reserva AS \"Reserva\", Aluno.nomeAluno " + "as \"Aluno\", Itens.id_Livro as \"idLivro\", Livro.nomeLivro AS \"NomeLivro\", Reserva.dataRetirada AS \"DataSaida\", Reserva.dataEntrega as \"DataEntrega\"" + "FROM Itens JOIN Reserva ON id_reserva = Reserva.idReserva\n" + "JOIN Aluno ON Reserva.idAluno = Aluno.idAluno\n" + "JOIN Livro ON Livro.idLivro = Itens.id_Livro;"); while (rsr.next()) { Reserva r = new Reserva(0, 0, "", 0, "", "", ""); r.setIdItem(rsr.getInt("Item")); r.setIdReserva(rsr.getInt("Reserva")); r.setNoAluno(rsr.getString("Aluno")); r.setIdLivro(rsr.getInt("idLivro")); r.setNoLivro(rsr.getString("NomeLivro")); r.setDaSaida(rsr.getString("DataSaida")); r.setDaEntrada(rsr.getString("DataEntrega")); tabelaR.addCell(String.valueOf(r.getIdReserva())); tabelaR.addCell(r.getNoLivro()); tabelaR.addCell(r.getNoAluno()); tabelaR.addCell(r.getDaSaida()); tabelaR.addCell(r.getDaEntrada()); } doc.add(tabelaR); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
/** * createPdf es una funcin estatica que funciona como plantilla para generar * reportes dinamicos, segn la necesidad del usuario. * @param path La direccin del archivo donde se guardar el pdf * @param titulo El Ttulo que llevar el pdf * @param encabezado Un texto que se mostrar bajo el ttulo * @param tabla La tabla de resultados que mostrar el pdf */// ww w . j a v a 2 s .c o m static public void createPdf(String path, String titulo, String encabezado, PdfPTable tabla) { Document document = new Document(); // step 2 try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(14); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora del Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); document.add(new Paragraph(encabezado + (tabla.getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tabla); // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createArrayListPdf(String path, String titulo, String encabezado, ArrayList<PdfPTable> tablas) { Document document = new Document(); ArrayList<String> NombreTablas = new DaoReportesEstadisticas().getNombreTablas(); //step 2// www . j a v a 2 s . c o m try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); for (int i = 0; i < tablas.size(); i++) { document.add(new Paragraph(NombreTablas.get(i))); document.add(new Paragraph(encabezado + (tablas.get(i).getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tablas.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createDinamicPdf(String path, String titulo, String encabezado, ArrayList<Element> contenido) { Document document = new Document(); //step 2//w w w . j ava2 s . c om try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados"); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); // document.add(Introduccion); document.add(new Paragraph("\r\n")); for (int i = 0; i < contenido.size(); i++) { document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass()) ? (PdfPTable) contenido.get(i) : contenido.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:bicimotos3hermanos.MainFrom.java
public void toPFD(String out, String in) { try {/* w ww . j ava 2s . c om*/ //Create Document Object Document convertJpgToPdf = new Document(); //Create PdfWriter for Document to hold physical file PdfWriter.getInstance(convertJpgToPdf, new FileOutputStream(out));//"c:\\java\\ConvertImagetoPDF.pdf" convertJpgToPdf.open(); //Get the input image to Convert to PDF Image convertJpg = Image.getInstance(in); convertJpg.setAbsolutePosition(0f, 260f);//posicion en x,y convertJpg.scalePercent(72, 85);//porcentaje en escala //Add image to Document convertJpgToPdf.add(convertJpg); //Close Document convertJpgToPdf.close(); System.out.println("Successfully Converted JPG to PDF in iText"); } catch (Exception i1) { i1.printStackTrace(); } }