List of usage examples for com.itextpdf.text Document Document
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Document
-object. From source file:br.unisc.video_locadora.controll.Generator_PDF.java
public void geraRelatorio() throws DocumentException, FileNotFoundException { // Cria um novo documento com tamanho e margens definidas pelo usurio // new Document(tamanho da pgina, margem esquerda, margem direita, // margem topo, margem rodap); Document doc = new Document(PageSize.A4, 10, 10, 10, 10); try {//from www . ja v a 2 s . c o m JFileChooser jFileChooser = new JFileChooser(); //seta para selecionar apenas arquivos jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //desabilita todos os tipos de arquivos jFileChooser.setAcceptAllFileFilterUsed(false); //filtra por extensao jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "Extenso PDF"; } @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith("pdf"); } }); //mostra janela para salvar int acao = jFileChooser.showSaveDialog(null); //executa acao conforme opcao selecionada if (acao == JFileChooser.APPROVE_OPTION) { //escolheu arquivo System.out.println(jFileChooser.getSelectedFile().getAbsolutePath()); PdfWriter.getInstance(doc, new FileOutputStream(jFileChooser.getSelectedFile().getAbsolutePath() + ".pdf")); doc.open(); listaF = f.buscaFilme(""); // Definindo uma fonte, com tamanho 20 e negrito Font f = new Font(Font.FontFamily.COURIER, 30, Font.BOLD); Font f2 = new Font(Font.FontFamily.HELVETICA, 20, Font.BOLD); // adicionando um pargrafo ao documento com a fonte acima Paragraph pa = new Paragraph("Relatrio", f); // Setando o alinhamento p/ o centro pa.setAlignment(Paragraph.ALIGN_CENTER); // Definindo pa.setSpacingAfter(50); doc.add(pa); //doc.add(new Paragraph(" ")); // Criando uma tabela com 4 colunas PdfPTable table = new PdfPTable(7); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Todos os Ttulos", f2); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 4 colunas header.setColspan(7); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela table.addCell(header); List<String> list = new ArrayList<>(); list.add("Id"); list.add("Ttulo"); list.add("Ano"); list.add("Diretor"); list.add("Gnero"); list.add("Linguagem"); list.add("Locado"); for (Filmes p : listaF) { list.add(String.valueOf(p.getId())); list.add(p.getTitulo()); list.add(String.valueOf(p.getAno())); list.add(p.getDiretor()); list.add(p.getGenero()); list.add(p.getIdioma()); list.add(p.getLocado()); } for (String s : list) { table.addCell(s); } doc.add(table); /* doc.add(new Paragraph(" ID | Nome | Idade | Cidade")); for (Pessoa p : lista) { doc.add(new Paragraph(p.getId() + " | " + p.getNome() + " | " + p.getIdade() + " | " + p.getCidade())); }*/ } } catch (FileNotFoundException | DocumentException e) { System.err.println(e.getMessage()); } doc.close(); }
From source file:BUS.ExportPDF.java
public boolean ExportPN(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {//from ww w . j ava2 s . c om // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "PhieuNhap_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Data PdfPTable t = new PdfPTable(7); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("STT")); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("M phiu nhp", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f)); t.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f)); t.addCell(c5); PdfPCell c6 = new PdfPCell(new Phrase("Nh cung cp", f)); t.addCell(c6); PdfPCell c7 = new PdfPCell(new Phrase("Tng ti?n", f)); t.addCell(c7); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(al.get(i)[1]); t.addCell(new Phrase(al.get(i)[2], f)); t.addCell(al.get(i)[3]); t.addCell(new Phrase(al.get(i)[4], f)); t.addCell(al.get(i)[5]); } document.add(t); // ?ng File document.close(); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
From source file:BUS.ExportPDF.java
public boolean ExportPX(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {//from ww w .ja v a2 s . co m // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "PhieuXuat_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Data PdfPTable t = new PdfPTable(5); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("STT")); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("M phiu xut", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f)); t.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f)); t.addCell(c5); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(al.get(i)[1]); t.addCell(new Phrase(al.get(i)[2], f)); t.addCell(al.get(i)[3]); } document.add(t); // ?ng File document.close(); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
From source file:BUS.ExportPDF.java
public boolean ExportHD(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {/* ww w . java 2s . co m*/ // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "Hoadon_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Data PdfPTable t = new PdfPTable(6); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("STT")); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("M ha n", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("Tn khch hng", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f)); t.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f)); t.addCell(c5); PdfPCell c6 = new PdfPCell(new Phrase("Tng ti?n", f)); t.addCell(c6); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(new Phrase(al.get(i)[1], f)); t.addCell(new Phrase(al.get(i)[2], f)); t.addCell(al.get(i)[3]); t.addCell(al.get(i)[4]); } document.add(t); // ?ng File document.close(); System.out.println("Write file succes!"); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
From source file:BUS.ExportPDF.java
public boolean ExportTKDT(ArrayList<String[]> al, String year) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {/* w ww.j a va 2s .co m*/ // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Nam can bao cao Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title2); //Chart Image image = Image.getInstance("src\\Library\\barChart3D.jpeg"); image.scaleToFit(500, 400); document.add(new Paragraph()); document.add(image); //Data PdfPTable t = new PdfPTable(4); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("Thng", f)); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Li", f)); t.addCell(c4); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(al.get(i)[1]); t.addCell(al.get(i)[2]); } document.add(t); // ?ng File document.close(); System.out.println("Write file succes!"); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
From source file:BUS.ExportPDF.java
public boolean ExportTKSP(ArrayList<String[]> al, String year) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {// w ww . ja v a2 s. c o m // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "ThongKeSanPham_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Nm c bo co Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title2); //Chart Image image = Image.getInstance("src\\Library\\pie_Chart3D.jpeg"); image.scaleToFit(500, 400); document.add(new Paragraph()); document.add(image); //Data PdfPTable t = new PdfPTable(5); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("STT")); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("M sn phm", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("Tn sn phm", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Tng s lng", f)); t.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("Tng ti?n", f)); t.addCell(c5); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(new Phrase(al.get(i)[1], f)); t.addCell(al.get(i)[2]); t.addCell(al.get(i)[3]); } document.add(t); // ?ng File document.close(); System.out.println("Write file succes!"); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
From source file:ca.sqlpower.wabit.report.LayoutToPDF.java
License:Open Source License
public void writePDF() throws DocumentException, FileNotFoundException, PrinterException { monitorableHelper.setStarted(true);//from w ww .ja v a2 s .c o m int pageNum = 0; int numPages = layout.getNumberOfPages(); monitorableHelper.setJobSize(numPages); Page page = layout.getPage(); OutputStream out = fileOS; Rectangle pageSize; pageSize = new Rectangle(page.getWidth(), page.getHeight()); Document pdfDoc = new Document(pageSize, 0f, 0f, 0f, 0f); PdfWriter pdfOut = PdfWriter.getInstance(pdfDoc, out); pdfDoc.open(); pdfDoc.addCreator("Wabit " + WabitVersion.VERSION); PdfContentByte pdfContent = pdfOut.getDirectContent(); Graphics2D pdfGraphics = null; try { while (pageNum < numPages) { monitorableHelper.checkCancelled(); monitorableHelper.setProgress(pageNum); pdfGraphics = pdfContent.createGraphics(pageSize.getWidth(), pageSize.getHeight()); int flag = layout.print(pdfGraphics, layout.getPageFormat(pageNum), pageNum); if (watermarker != null) { java.awt.Rectangle watermarkSize = new java.awt.Rectangle(); watermarkSize.setSize(Math.round(pageSize.getWidth()), Math.round(pageSize.getHeight())); watermarker.watermark(pdfGraphics, watermarkSize); } pdfGraphics.dispose(); pdfGraphics = null; if (flag == Printable.NO_SUCH_PAGE) break; pdfDoc.newPage(); pageNum++; } } finally { if (pdfGraphics != null) pdfGraphics.dispose(); if (pdfDoc != null) pdfDoc.close(); monitorableHelper.setFinished(true); } }
From source file:CadastroDeMusicas.Principal.java
public static void main(String[] args) throws Exception { ConecBanco c = new ConecBanco(con); Genero g;/*from w w w . j av a 2s . co m*/ Artista a1; Album a2; Musica m; String nome, tipo; int nota, duracao, ano; int opc; try { new Principal(); } catch (ClassNotFoundException | SQLException e) { System.out.println("No conectado."); } do { opc = Integer.parseInt(JOptionPane.showInputDialog( "Informe a OPO:\n1.Inserir\n2.Deletar\n3.Pesquisar\n4.Relatorio em Pdf\n5.Sair")); switch (opc) { case 1: nome = JOptionPane.showInputDialog("Genero: "); g = new Genero(nome); nome = JOptionPane.showInputDialog("Artista: "); a1 = new Artista(nome); nome = JOptionPane.showInputDialog("Album: "); ano = Integer.parseInt(JOptionPane.showInputDialog("Ano: ")); a2 = new Album(nome, ano); nome = JOptionPane.showInputDialog("Musica: "); nota = Integer.parseInt(JOptionPane.showInputDialog("Nota (1/10): ")); duracao = Integer.parseInt(JOptionPane.showInputDialog("Durao: ")); m = new Musica(nome, nota, duracao); c.cadastrar(g, a1, a2, m); break; case 2: System.out.println("DELETAR MUSICA: "); nome = JOptionPane.showInputDialog("Musica: "); c.deletar(nome); break; case 3: System.out.println("PESQUISAR MUSICA: "); ResultSet rs = ConecBanco.pesquisar(); if (rs != null) { try { while (rs.next()) { System.out.println("MUSICA: " + rs.getString("nome")); System.out.println("NOTA: " + rs.getString("nota")); System.out.println("DURAO: " + rs.getString("duracao")); System.out.println("ALBUM: " + rs.getString("nomeAL")); System.out.println("ANO: " + rs.getString("ano")); System.out.println("ARTISTA: " + rs.getString("nomeAR")); System.out.println("GENERO: " + rs.getString("nomeGE")); } } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } break; case 4: Document doc = null; OutputStream os = null; String add; System.out.println("LISTA DE MUSICAS: "); try { doc = new Document(PageSize.A4, -1, -1, 25, 1) { }; os = new FileOutputStream("Relatorio.pdf"); PdfWriter.getInstance((com.itextpdf.text.Document) doc, os); doc.open(); Image img = Image.getInstance("images.jpg"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); PdfPTable TB1, TB2, TB3, TB4; TB1 = new PdfPTable(2); TB2 = new PdfPTable(3); TB3 = new PdfPTable(4); TB4 = new PdfPTable(5); PdfPCell T1, T2, T3, T4, T5; T1 = new PdfPCell(new Paragraph("\nCADASTRO DE MUSICAS\n")); T1.setColspan(2); TB1.addCell(T1); T2 = new PdfPCell(new Paragraph("\nGENEROS\n")); T2.setColspan(2); TB1.addCell(T2); ResultSet res, res1, res2, res3; res = ConecBanco.relatorioGenero(); if (res != null) { try { while (res.next()) { TB1.addCell("ID: " + res.getString("id")); TB1.addCell("NOME: " + res.getString("nomeGE")); } doc.add(TB1); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T3 = new PdfPCell(new Paragraph("\nARTISTAS\n")); T3.setColspan(3); TB2.addCell(T3); res1 = ConecBanco.relatorioArtista(); if (res1 != null) { try { while (res1.next()) { TB2.addCell("ID: " + res1.getString("id")); TB2.addCell("NOME: " + res1.getString("nomeAR")); TB2.addCell("GENERO ID: " + res1.getString("genero_id")); } doc.add(TB2); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T4 = new PdfPCell(new Paragraph("\nALBUM\n")); T4.setColspan(4); TB3.addCell(T4); res2 = ConecBanco.relatorioAlbum(); if (res2 != null) { try { while (res2.next()) { TB3.addCell("ID: " + res2.getString("id")); TB3.addCell("NOME: " + res2.getString("nomeAL")); TB3.addCell("ANO: " + res2.getString("ano")); TB3.addCell("ARTISTA ID: " + res2.getString("artista_id")); } doc.add(TB3); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T5 = new PdfPCell(new Paragraph("\nMUSICA\n")); T5.setColspan(5); TB4.addCell(T5); res3 = ConecBanco.relatorioMusica(); if (res3 != null) { try { while (res3.next()) { TB4.addCell("ID: " + res3.getString("id")); TB4.addCell("NOME: " + res3.getString("nome")); TB4.addCell("NOTA: " + res3.getString("nota")); TB4.addCell("DURAO: " + res3.getString("duracao")); TB4.addCell("ALBUM ID: " + res3.getString("album_id")); } doc.add(TB4); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } } finally { if (doc != null) { doc.close(); } if (os != null) { os.close(); } } break; case 5: System.out.println("SAINDO..."); break; default: System.out.println("OPO INVALIDA!"); } } while (opc != 5); }
From source file:clases.Funciones.java
private String GenerateReporte_pdf(JTable t, String title, int open) { Document documento = new Document(PageSize.LETTER.rotate(), 10, 10, 10, 10); FileOutputStream ficheroPdf;/* w w w . j a v a 2 s .co m*/ File ruta = null; com.itextpdf.text.Image imagen = null; try { imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo)); char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } else { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } ficheroPdf = new FileOutputStream(ruta); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); } catch (DocumentException | IOException ex) { Alert("Verifique las rutas de guardado de reportes y logo."); } try { documento.open(); title += "\nGENER: " + ReturnNombreUsuario(); Paragraph Title = new Paragraph(title.toUpperCase()); Title.setAlignment(1); documento.add(Title); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleToFit(200, 100); String membrete = ReturnDatosFisicos(this.Datos_Nombre) + "\n"; membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n"; membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n"; membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n"; membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n"; membrete += "FECHA Y HORA DE GENERACION: " + GetFechaAndHourActual() + "\n"; ///////// PdfPTable HeaderDatos = new PdfPTable(2); HeaderDatos.setWidthPercentage(100); documento.add(new Paragraph("\n")); PdfPCell cell = new PdfPCell(new Phrase(membrete)); cell.setBorder(0); HeaderDatos.addCell(cell); cell = new PdfPCell(imagen); cell.setBorder(0); cell.setHorizontalAlignment(1); HeaderDatos.addCell(cell); documento.add(HeaderDatos); documento.add(new Paragraph("\n")); ///////// PdfPTable tabla = new PdfPTable(t.getColumnCount()); tabla.setWidthPercentage(100); for (int i = 0; i < t.getColumnCount(); i++) { Paragraph header = new Paragraph(t.getColumnName(i)); header.setAlignment(1); tabla.addCell(header); } for (int i = 0; i < t.getRowCount(); i++) { for (int a = 0; a < t.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t.getValueAt(i, a))); campo.setAlignment(1); tabla.addCell(campo); } } documento.add(tabla); documento.add(new Paragraph(" ")); Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM"); footer.setAlignment(1); documento.add(footer); documento.close(); if (open > 0) { Desktop.getDesktop().open(ruta); } } catch (IOException | DocumentException ex) { Alert(ex.getMessage()); } return ruta.getAbsolutePath(); }
From source file:clases.Funciones.java
public boolean GenerateReporte_Service(JTable t_client, JTable t_vehiculos, int open, String S_solicitad, String S_realizado, JTable t_productos, String Total, String Prioridad, JComboBox client, JComboBox vehiculos, Double km) { boolean r = false; int Folio = GenerateFolioService(); if (AddService(client, vehiculos, S_solicitad, S_realizado, t_productos, Double.parseDouble(Total), "URGENTE".equals(Prioridad)) && vehiculos.getSelectedIndex() > 0) { UpdateKilometraje((String) ListVehiculos.get(vehiculos.getSelectedIndex()), km); Table_LoadClient(t_client, client); Table_LoadCar(t_vehiculos, vehiculos); Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10); FileOutputStream ficheroPdf; File ruta = null;//from ww w .j a v a2 s . c om com.itextpdf.text.Image imagen = null; try { imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo)); char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } else { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } ficheroPdf = new FileOutputStream(ruta); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); } catch (DocumentException | IOException ex) { Alert("Verifique las rutas de guardado de reportes y logo."); } try { documento.open(); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleToFit(200, 100); String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n"; membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n"; membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n"; membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n"; membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n"; membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n"; membrete += "GENERADO: " + GetFechaAndHourActual() + "\n"; PdfPTable HeaderDatos = new PdfPTable(2); HeaderDatos.setWidthPercentage(100); documento.add(new Paragraph("\n")); PdfPCell cell = new PdfPCell(new Phrase(membrete)); cell.setBorder(0); HeaderDatos.addCell(cell); cell = new PdfPCell(imagen); cell.setBorder(0); cell.setHorizontalAlignment(1); cell.setVerticalAlignment(1); HeaderDatos.addCell(cell); documento.add(HeaderDatos); documento.add(new Paragraph("\n")); ///////// //Tabla_Clientes String Client_header = "CLIENTE"; Paragraph Title = new Paragraph(Client_header.toUpperCase()); Title.setAlignment(1); documento.add(Title); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(t_client.getColumnCount()); tabla.setWidthPercentage(100); for (int i = 0; i < t_client.getColumnCount(); i++) { Paragraph header = new Paragraph(t_client.getColumnName(i)); header.setAlignment(1); tabla.addCell(header); } for (int i = 0; i < t_client.getRowCount(); i++) { for (int a = 0; a < t_client.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a))); campo.setAlignment(1); tabla.addCell(campo); } } documento.add(tabla); documento.add(new Paragraph(" ")); //Tabla_Vehiculos String Vehiculos_header = "VEHICULO"; Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase()); Title1.setAlignment(1); documento.add(Title1); documento.add(new Paragraph(" ")); PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount()); tabla_vehiculos.setWidthPercentage(100); for (int i = 0; i < t_vehiculos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_vehiculos.getColumnName(i)); header.setAlignment(1); tabla_vehiculos.addCell(header); } for (int i = 0; i < t_vehiculos.getRowCount(); i++) { for (int a = 0; a < t_vehiculos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a))); campo.setAlignment(1); tabla_vehiculos.addCell(campo); } } documento.add(tabla_vehiculos); documento.add(new Paragraph("SERVICIO SOLICITADO: " + S_solicitad.toUpperCase())); documento.add(new Paragraph("SERVICIO REALIZADO: " + S_realizado.toUpperCase())); documento.add(new Paragraph("PRIORIDAD: " + Prioridad)); //Tabla de servicios y productos String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS"; Paragraph Title2 = new Paragraph(Service_header.toUpperCase()); Title2.setAlignment(1); documento.add(Title2); documento.add(new Paragraph(" ")); PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount()); tabla_PRODUCTS.setWidthPercentage(100); for (int i = 0; i < t_productos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_productos.getColumnName(i)); header.setAlignment(1); tabla_PRODUCTS.addCell(header); } for (int i = 0; i < t_productos.getRowCount(); i++) { for (int a = 0; a < t_productos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a))); campo.setAlignment(1); tabla_PRODUCTS.addCell(campo); } } documento.add(tabla_PRODUCTS); documento.add(new Paragraph("")); // documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + Total)); documento.add(new Paragraph( "FECHA Y HORA DE ENTREGA: ____________________________________________________")); documento.add(new Paragraph( "NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________")); documento.add(new Paragraph( "CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________")); documento.add(new Paragraph( "PROXIMO SERVICIO: ___________________________________________________________")); Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM"); footer.setAlignment(1); documento.add(footer); documento.close(); r = true; if (open > 0) { Desktop.getDesktop().open(ruta); } } catch (IOException | DocumentException ex) { Alert(ex.getMessage()); } } else { Alert("VERIFIQUE SU INFORMACION"); } return r; }