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: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 .ja v a2 s . 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:bestdeal.util.genererPdf.java
public static void main(String[] args) { // - Paramtres de connexion la base de donnes Connection connection;/*from www. j av a2 s . c o m*/ String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, }; try { String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur"; connection = MyConnection.getInstance(); mypdf = new Document(PageSize.A4, 50, 50, 50, 50); File di = new File("C:/Voucher"); File fl[] = di.listFiles(); try { OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf")); PdfWriter.getInstance(mypdf, file); mypdf.open(); Statement stm; mypdf.addAuthor("Best Deal"); mypdf.addSubject("Voucher "); mypdf.add(new Paragraph("Socite BestDeal")); mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT ")); mypdf.add(new Paragraph("TEL : xx xxx xxx")); mypdf.add(new Paragraph("FAX : xx xxx xxx")); mypdf.add(new Paragraph( " " + new Date().toString())); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" " + "Voucher N'01", FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("CLIENT :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); try { stm = connection.createStatement(); ResultSet rs = stm.executeQuery(requete); while (rs.next()) { // add a country to the document as a Chunk //mypdf.add(new Chunk(rs.getString("quantite"))); Phrase p = new Phrase("Nom: "); Phrase p2 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa = new Paragraph(); pa.add(p); pa.add(p2); mypdf.add(pa); Phrase p3 = new Phrase("Prenom: "); Phrase p4 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa1 = new Paragraph(); pa1.add(p3); pa1.add(p4); mypdf.add(pa1); Phrase p5 = new Phrase("Adresse: "); Phrase p6 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa2 = new Paragraph(); pa2.add(p5); pa2.add(p6); mypdf.add(pa2); Phrase p7 = new Phrase("Tlphone: "); Phrase p8 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa3 = new Paragraph(); pa3.add(p7); pa3.add(p8); mypdf.add(pa3); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("Vendeur :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); Phrase p9 = new Phrase("Nom: "); Phrase p10 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa4 = new Paragraph(); pa4.add(p9); pa4.add(p10); mypdf.add(pa4); Phrase p11 = new Phrase("Prnom: "); Phrase p12 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa5 = new Paragraph(); pa5.add(p11); pa5.add(p12); mypdf.add(pa5); Phrase p13 = new Phrase("Tlphone: "); Phrase p14 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa6 = new Paragraph(); pa6.add(p13); pa6.add(p14); mypdf.add(pa6); Phrase p15 = new Phrase("Adresse: "); Phrase p16 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa7 = new Paragraph(); pa7.add(p15); pa7.add(p16); mypdf.add(pa7); Phrase p17 = new Phrase("Email: "); Phrase p18 = new Phrase(new Chunk(rs.getString("email"))); Paragraph pa8 = new Paragraph(); pa8.add(p17); pa8.add(p18); mypdf.add(pa8); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); for (int i = 0; i < rs.getRow(); i++) { for (int j = 0; j < data[i].length - 1; j++) { data[i][j] = rs.getString(j + 9); // if (j==3) // data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+""; } } for (int i = 0; i < rs.getRow(); i++) { float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim()); data[i][4] = s + ""; } //mypdf.add(new Phrase("nom")); //mypdf.add(new Chunk(rs.getString("nom"))); //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom")))); //mypdf.add(new Chunk(" ")); //Chunk id = new Chunk(rs.getString("id")); // with a background color //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f); // and a text rise //id.setTextRise(6); // mypdf.add(id); mypdf.add(Chunk.NEWLINE); } } catch (SQLException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Prenom ")); // mypdf.add(new Paragraph("Adresse ")); //mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Nom de la socit ")); // mypdf.add(new Paragraph("Adresse ")); // mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph(" ")); String[] headers = new String[] { " Id_deal", " Nom Deal", " Quantit", " Prix unitaire", " Prix total" }; PdfPTable table = new PdfPTable(headers.length); for (int i = 0; i < headers.length; i++) { String header = headers[i]; PdfPCell cell = new PdfPCell(); cell.setGrayFill(0.9f); cell.setPhrase(new Phrase(header.toUpperCase())); table.addCell(cell); } table.completeRow(); for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { String datum = data[i][j]; PdfPCell cell = new PdfPCell(); cell.setPhrase(new Phrase(datum.toUpperCase())); table.addCell(cell); } table.completeRow(); } mypdf.add(table); } catch (FileNotFoundException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph( "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ", FontFactory.getFont(null, 9, Font.NORMAL))); mypdf.add(new Paragraph( " Merci pour votre confiance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.close(); } catch (DocumentException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Alunos public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null;//ww w . ja v a2 s . c o m OutputStream os = null; 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;/*from w w w .j a v a 2s . co m*/ OutputStream os = null; 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;/*w w w . java2s . c o m*/ OutputStream os = null; 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:bladwin.web.reg.regPDF.java
public void genPed(String loc, regMgr regMgr, dbMgrInterface db) { Document document = null;/*from ww w . ja va2 s . com*/ //String loc = "C:/_bisc/_javaApps/jlData/jvp/CellWidths.pdf"; //regMgr.getCustomerRegBean().setPdf(loc); try { document = new Document(PageSize.A4, 30, 30, 30, 30); PdfWriter.getInstance(document, new FileOutputStream(loc)); document.open(); customerRegBean r = regMgr.getCustomerRegBean(); customerBean c = regMgr.getCustomerBean(); customerBean a = new custObj().getcustomerBean(r.getRegCustId(), db); mgnLookupBean bean = new mgnLookupObj().getLookupBean(-947, db); Paragraph pg; pg = new Paragraph(r.getLookupDesc()); pg.setAlignment(Paragraph.ALIGN_CENTER); pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)); document.add(getHeader(r.getLookupDesc())); document.add(getHeader("BALDWIN BLAZERS TRACK CLUB")); document.add(getHeader("REGISTRATION")); pg = new Paragraph("\n\r"); document.add(pg); // ------------------------------------------------------- document.add(genAthleteInfo(r, a)); pg = new Paragraph("\n\r"); document.add(pg); document.add(genParentInfo(c)); pg = new Paragraph("\n\r"); document.add(pg); document.add(genSport(r)); pg = new Paragraph("\n\r"); document.add(pg); pg = new Paragraph("PARENTS SIGNATURE"); document.add(pg); pg = new Paragraph("\n\r"); document.add(pg); pg = new Paragraph("\n\r"); document.add(pg); pg = new Paragraph("_____________________________________________________________________"); document.add(pg); pg = new Paragraph("\n\r"); document.add(pg); document.add(getHeader(r.getFeeDesc() + "\n\r" + bean.getSubjectBody())); // ---------------------------------------------------------------------------- } catch (DocumentException ex) { logger.error("DocumentException", ex); } catch (FileNotFoundException ex) { logger.error("FileNotFoundException", ex); } finally { try { if (document != null) document.close(); //pdfFileOpen(loc); } catch (Exception e) { logger.error("FileNotFoundException", e); } } }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report that has no data in it (only the image). * The length is the given number of pages. * /*from w ww. java 2s.co m*/ * @param numPages * @return True if the report was generated. */ public boolean generateBlank(Dao dao, Integer numPages) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 1; while (true) { drawBout(cb, bf, 35, midPage - 35, null); drawBout(cb, bf, midPage + 35, pageWidth - 35, null); if (++count > numPages) { break; } document.newPage(); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report for the given list of bouts. * It is assumed that the list is in the desired order (no sorting is done here). * * @param list/*from ww w . j a v a2 s . c o m*/ * @return True if the report was generated. */ public boolean generateReport(Dao dao, List<Bout> list) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 0; for (Bout b : list) { boolean rightSide = false; if ((count++ % 2) == 0) { if (count > 2) { // We could put this after Bout 2 is added, but // that could leave a blank last page. document.newPage(); } // Bout 1 (Left side) drawBout(cb, bf, 35, midPage - 35, b); } else { // Bout 2 (Right side) drawBout(cb, bf, midPage + 35, pageWidth - 35, b); rightSide = true; } // Print the watermark, if necessary boolean doWatermark = false; String gClass = b.getGroup().getClassification(); String wmValues = dao.getBoutsheetWatermarkValues(); if ((wmValues != null) && !wmValues.isEmpty()) { String[] tokens = wmValues.split(","); for (String s : tokens) { if (s.trim().equalsIgnoreCase(gClass)) { doWatermark = true; break; } } } if (doWatermark) { int rotation = 45; PdfContentByte ucb = writer.getDirectContentUnder(); BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); ucb.saveState(); ucb.setColorFill(BaseColor.LIGHT_GRAY); ucb.beginText(); ucb.setFontAndSize(helv, 86); float centerWidth = document.getPageSize().getWidth() / 4; if (rightSide) { centerWidth = centerWidth * 3; } ucb.showTextAligned(Element.ALIGN_CENTER, gClass, centerWidth, document.getPageSize().getHeight() / 2, rotation); ucb.endText(); ucb.restoreState(); } } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.utility.boutsheet.BoutSheetMaker.java
License:Open Source License
/** * @param args the command line arguments *//*from w w w. j a v a 2 s. co m*/ public static void main(String[] args) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer PdfWriter writer; if (args.length >= 1) { writer = PdfWriter.getInstance(document, new FileOutputStream(args[0])); } else { System.err.println("ERROR : Must specify output file."); return; } // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; drawBout(cb, bf, 35, midPage - 35); drawBout(cb, bf, midPage + 35, pageWidth - 35); } catch (DocumentException de) { System.err.println(de.getMessage()); return; } catch (IOException ioe) { System.err.println(ioe.getMessage()); return; } // step 5: we close the document document.close(); if ((args.length == 3) && (Boolean.parseBoolean(args[2]))) { showPDF(args[0]); } }
From source file:br.com.ifrn.panfleto.gui.PainelCadastrar.java
public Rectangle tamanhoDaPagina() { if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A0")) { return new Rectangle(PageSize.A0); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A1")) { return new Rectangle(PageSize.A1); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A2")) { return new Rectangle(PageSize.A2); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A3")) { return new Rectangle(PageSize.A3); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A4")) { return new Rectangle(PageSize.A4); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A5")) { return new Rectangle(PageSize.A5); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B0")) { return new Rectangle(PageSize.B0); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B1")) { return new Rectangle(PageSize.B1); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B2")) { return new Rectangle(PageSize.B2); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B3")) { return new Rectangle(PageSize.B3); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B4")) { return new Rectangle(PageSize.B4); } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B5")) { return new Rectangle(PageSize.B5); }/* w w w .ja v a 2s . c om*/ //caso erro, retorna o tamanho a4 como padrao return new Rectangle(PageSize.A4); }