List of usage examples for com.itextpdf.text PageSize A4
Rectangle A4
To view the source code for com.itextpdf.text PageSize A4.
Click Source Link
From source file:br.com.primetestes.TableBean.java
License:Apache License
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();/*from www . ja v a 2 s . c om*/ pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "prime_logo.png"; pdf.add(Image.getInstance(logo)); }
From source file:br.edu.unipampa.recipemanager.pdf.CreatePDF.java
public boolean newPdf(List<MenuRecipe> menuRecipe, String month, String responsibleName) { double valueMonth = 0; try {/*from ww w .j a v a2 s .c om*/ Document doc = new Document(PageSize.A4, 72, 72, 72, 72); OutputStream os = new FileOutputStream(namePdf(menuRecipe)); PdfWriter.getInstance(doc, os); doc.open(); Paragraph p; Font f = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); p = new Paragraph("Ms: " + month, f); doc.add(p); f = new Font(Font.FontFamily.COURIER, 14, Font.ITALIC); for (MenuRecipe menu : menuRecipe) { valueMonth += menu.priceMenu(); p.setSpacingBefore(5); p.setSpacingAfter(5); p = new Paragraph(menu.toString(), f); doc.add(p); } p = new Paragraph("Preo total de todos os cardpios: " + valueMonth, f); doc.add(p); f = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); p = new Paragraph("_____________________________________\n" + responsibleName, f); p.setSpacingAfter(15); p.setAlignment(Element.ALIGN_RIGHT); doc.add(p); doc.close(); os.close(); return true; } catch (Exception e) { return false; } }
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 w w w. j a v a 2 s . co 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 {/* w ww . ja v a 2 s .c o m*/ // 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 {// w ww .j a v a 2 s .c om // 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 {//from w w w . j av a 2 s. 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 {// www .j av a 2s . c om // 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 w w . j a v a 2 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.uwo.csd.cs2212.team02.MainWindow.java
/** * Export current page to PDF/*from w w w . ja v a2 s .c o m*/ * * @param jpanel Panel to be exported to PDF */ public void createPDF(JLayeredPane jpanel) { playButtonSound(); com.itextpdf.text.Rectangle r = new com.itextpdf.text.Rectangle(0, 0, jpanel.getWidth(), jpanel.getHeight()); Document doc = new Document(r); String filename = fileChooser(); if (filename != "INVALID") { try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filename)); doc.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(PageSize.A4.getHeight() * 2, PageSize.A4.getWidth() * 2); Graphics2D g2; g2 = tp.createGraphics(jpanel.getWidth(), jpanel.getHeight(), new DefaultFontMapper()); jpanel.print(g2); g2.dispose(); cb.addTemplate(tp, 0, 0); PopUpWindow saveSuccess = new PopUpWindow(filename, "Save Successful!", 8); } catch (Exception e) { new PopUpWindow("Please try again.", "Error saving file"); } } doc.close(); }
From source file:CadastroDeMusicas.Principal.java
public static void main(String[] args) throws Exception { ConecBanco c = new ConecBanco(con); Genero g;//from ww w .j ava 2 s . c o 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); }