List of usage examples for com.itextpdf.text.pdf PdfPCell setPadding
public void setPadding(float padding)
From source file:dbms_prj.Status.java
public void create_pdf() throws Exception { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf")); Image image = Image.getInstance("src/Travel partners.png"); image.scaleAbsolute(500f, 200f);//from w w w .j a v a 2 s. co m Image ima = Image.getInstance("src/images.jpg"); ima.scaleAbsolute(100f, 100f); ima.setAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(9); PdfPCell cell = new PdfPCell(new Paragraph("Ticket")); cell.setColspan(9); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); table.setTotalWidth(300.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("PNR"); table.addCell("BOOK_ID"); table.addCell("FLIGHT_NO"); table.addCell("NAME"); table.addCell("SOURCE"); table.addCell("DESTINATION"); table.addCell("STATUS"); table.addCell("FARE"); table.addCell("Date"); table.addCell(S1); table.addCell(S11); table.addCell(S4); table.addCell(S6 + S7); table.addCell(S8); table.addCell(S9); table.addCell(S5); table.addCell(S10); table.addCell(S2); table.setSpacingBefore(50.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(50.0f); doc.open(); //doc.add(new Paragraph("Hello!! Yo this is my first pdf!")); doc.add(image); //doc.add(new Paragraph("Ticket created on " + new Date().toString())); doc.add(table); //doc.add(list); doc.add(ima); doc.close(); }
From source file:de.jost_net.JVerein.io.Reporter.java
License:Open Source License
public void addColumn(byte[] image, int width, int height, int horizontalalignment) throws BadElementException, MalformedURLException, IOException { Image i = Image.getInstance(image); float w = i.getWidth() / width; float h = i.getHeight() / height; if (w > h) { h = i.getHeight() / w;/*ww w . j a v a2 s . c o m*/ w = width; } else { w = i.getHeight() / h; h = height; } i.scaleToFit(w, h); PdfPCell cell = new PdfPCell(i, false); cell.setPadding(3); cell.setHorizontalAlignment(horizontalalignment); table.addCell(cell); }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createUmfrageauswertung(List<UmfrageResult> res1, List<UmfrageResult> res2, int idUmfrage1, int idUmfrage2, String filter1, String filter2, String kopf, OutputStream out) throws DocumentException, BadElementException, IOException { Document document = new Document(); /* Basic PDF Creation inside servlet */ Umfrage u1 = em.find(Umfrage.class, idUmfrage1); Umfrage u2 = em.find(Umfrage.class, idUmfrage2); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f);// ww w . j av a 2 s .co m StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf); htmlString.append("<br></br>"); int maxRows = res1.size(); if (res2.size() > maxRows) { maxRows = res2.size(); } PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); writer.setPageEmpty(false); Font boldFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normalFont = new Font(Font.FontFamily.HELVETICA, 10, Font.ITALIC); PdfPTable table = new PdfPTable(new float[] { 1, 2, 2 }); PdfPCell qestionCell; PdfPCell group1Cell; PdfPCell group2Cell; int i = 0; for (i = 0; i < maxRows; i++) { Log.d("Print Row " + i); if (i % 5 == 0) { if (i != 0) { document.add(table); document.newPage(); document = printHead(writer, document, htmlString, out, image); } else { document = printHead(writer, document, htmlString, out, image); } table = new PdfPTable(new float[] { 1, 2, 2 }); table.setWidthPercentage((float) 100.0); qestionCell = new PdfPCell(new Phrase("\nFragen", boldFont)); group1Cell = new PdfPCell(); group1Cell.addElement(new Phrase("Hauptgruppe:", boldFont)); group1Cell.addElement(new Phrase(u1.getNAME() + "\n" + filter1, normalFont)); group2Cell = new PdfPCell(); group2Cell.addElement(new Phrase("Vergleichsgruppe:", boldFont)); group2Cell.addElement(new Phrase(u2.getNAME() + "\n" + filter2, normalFont)); qestionCell.setBorderWidth(2.0f); group1Cell.setBorderWidth(2.0f); group2Cell.setBorderWidth(2.0f); table.addCell(qestionCell); table.addCell(group1Cell); table.addCell(group2Cell); } String url1 = UmfrageUtil.getCharUrl(res1.get(i)); Log.d("URL1=" + url1); Image image1 = Image.getInstance(url1); Image image2 = null; if (res2.size() > i) { String url2 = UmfrageUtil.getCharUrl(res2.get(i)); Log.d("URL2=" + url2); image2 = Image.getInstance(url2); } Log.d("Write to pdf:" + res1.get(i).getFrage()); qestionCell = new PdfPCell(new Phrase(res1.get(i).getFrage(), normalFont)); qestionCell.setBorderWidth(1.0f); group1Cell = new PdfPCell(image1, true); group1Cell.setBorderWidth(1.0f); group1Cell.setPadding(10); if (image2 != null) group2Cell = new PdfPCell(image2, true); else group2Cell = new PdfPCell(); group2Cell.setBorderWidth(1.0f); group2Cell.setPadding(10); table.addCell(qestionCell); table.addCell(group1Cell); table.addCell(group2Cell); } if (!(i % 5 == 0)) { document.add(table); } document.close(); return document; }
From source file:eeebees.PDFGen.java
public static void main(String[] args) { try {/*from w w w .ja v a 2s . c o m*/ OutputStream file = new FileOutputStream(new File("D:\\PDF_Java4s.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); //Inserting Image in PDF //Image image = Image.getInstance ("src/pdf/java4s.png"); //image.scaleAbsolute(120f, 60f);//image width,height //Inserting Table in PDF PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Paragraph("Java4s.com")); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("Name"); table.addCell("Address"); table.addCell("Country"); table.addCell("Java4s"); table.addCell("NC"); table.addCell("United States"); table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(30.0f); // Space After table starts, like margin-Bottom in CSS //Inserting List in PDF List list = new List(true, 30); list.add(new ListItem("Java4s")); list.add(new ListItem("Php4s")); list.add(new ListItem("Some Thing...")); //Text formating in PDF Chunk chunk = new Chunk("Welecome To Java4s Programming Blog..."); chunk.setUnderline(+1f, -2f);//1st co-ordinate is for line width,2nd is space between Chunk chunk1 = new Chunk("Php4s.com"); chunk1.setUnderline(+4f, -8f); chunk1.setBackground(new BaseColor(17, 46, 193)); //Now Insert Every Thing Into PDF Document document.open();//PDF document opened........ //document.add(image); document.add(Chunk.NEWLINE); //Something like in HTML :-) document.add(new Paragraph("Dear Java4s.com")); document.add(new Paragraph("Document Generated On - " + new Date().toString())); document.add(table); document.add(chunk); document.add(chunk1); document.add(Chunk.NEWLINE); //Something like in HTML :-) document.newPage(); //Opened new page document.add(list); //In the new page we are going to add list document.close(); file.close(); System.out.println("Pdf created successfully.."); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
public void processNote(Document document, Note note, int count) throws Exception { String name = Utilities.makeXmlSafe(note.getName()); String form = note.getForm(); DaoImages daoImages = new DaoImages(); if (form != null && form.length() > 0) { JSONObject sectionObject = new JSONObject(form); if (!sectionObject.has(FormUtilities.ATTR_SECTIONNAME)) { return; }//from www . j a v a 2 s. c o m String sectionName = sectionObject.getString(FormUtilities.ATTR_SECTIONNAME); Anchor anchor = new Anchor(sectionName); anchor.setName(sectionName); Chapter currentChapter = new Chapter(new Paragraph(anchor), count); addEmptyLine(currentChapter, 3); PdfPTable infoTable = new PdfPTable(2); infoTable.setHeaderRows(0); infoTable.setWidthPercentage(90); currentChapter.add(infoTable); addKeyValueToTableRow(infoTable, "Timestamp", new Date(note.getTimeStamp()).toString()); addKeyValueToTableRow(infoTable, "Latitude", note.getLat() + ""); addKeyValueToTableRow(infoTable, "Longitude", note.getLon() + ""); addEmptyLine(currentChapter, 3); List<String> formsNames = TagsManager.getFormNames4Section(sectionObject); for (String formName : formsNames) { Paragraph section = new Paragraph(formName); currentChapter.addSection(section); addEmptyLine(currentChapter, 3); PdfPTable currentTable = new PdfPTable(2); currentTable.setHeaderRows(1); currentTable.setWidthPercentage(90); currentChapter.add(currentTable); JSONObject form4Name = TagsManager.getForm4Name(formName, sectionObject); JSONArray formItems = TagsManager.getFormItems(form4Name); for (int i = 0; i < formItems.length(); i++) { JSONObject formItem = formItems.getJSONObject(i); if (!formItem.has(FormUtilities.TAG_KEY)) { continue; } String type = formItem.getString(FormUtilities.TAG_TYPE); String key = formItem.getString(FormUtilities.TAG_KEY); String value = formItem.getString(FormUtilities.TAG_VALUE); String label = key; if (formItem.has(FormUtilities.TAG_LABEL)) { label = formItem.getString(FormUtilities.TAG_LABEL); } if (type.equals(FormUtilities.TYPE_PICTURES)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else if (type.equals(FormUtilities.TYPE_MAP)) { if (value.trim().length() == 0) { continue; } String imageId = value.trim(); Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } else if (type.equals(FormUtilities.TYPE_SKETCH)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else { addKeyValueToTableRow(currentTable, label, value); } } } document.add(currentChapter); document.newPage(); } }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
private void addKeyValueToTableRow(PdfPTable table, String key, String value) { PdfPCell keyCell = new PdfPCell(new Phrase(key)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); table.addCell(keyCell);/* w w w. j a v a2 s. co m*/ PdfPCell valueCell = new PdfPCell(new Phrase(value)); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); table.addCell(valueCell); }
From source file:Export.ExporOnlyViagemPdf.java
private void setStyleRodape(PdfPCell cellRodape) { cellRodape.setBorderWidthBottom(0.5f); cellRodape.setPadding(2f); cellRodape.setPaddingLeft(0.8f);//from ww w . j a va2s. com cellRodape.setPaddingRight(0.8f); }
From source file:Export.ExportViagemSemanaExcel.java
private static PdfPTable cellEspecial(PdfPCell cellEspcial) { PdfPTable pTable = new PdfPTable(1); pTable.addCell(cellEspcial);//from w w w. j a va2s . c om cellEspcial.setPadding(3f); return pTable; }
From source file:Export.ExportViagemSemanaPdf.java
public static void criarDoc(Date dataInicio, Date dateFim, String user, String nomeFuncinario) { Font fontTableCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontTableTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontRoadape = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontRoadapeP = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontRoadapeB = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontRoadapeBU = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f, Font.UNDEFINED);//from w w w .ja v a 2s . c o m Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f); Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f); Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f, Font.UNDERLINE); OutputStream outputStraem; try { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh.mm.ss"); SimpleDateFormat sdfTitile = new SimpleDateFormat("dd-MM-yyyy"); Document documento = new Document(); documento.setPageSize(PageSize.A4.rotate()); documento.setMargins(10f, 10f, 35f, 20f); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Seguro Viagem/"); ff.mkdirs(); String Ddata = sdf.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa Viagem Semanal " + Ddata + ".pdf"); String reString = "../Documentos/" + user + "/Seguro Viagem/" + "Export Mapa Viagem Semanal " + Ddata + ".pdf"; outputStraem = new FileOutputStream(ff); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); PdfPTable tableDados = new PdfPTable( new float[] { 5f, 10.6f, 5f, 5f, 4.6f, 19f, 5.6f, 6f, 10.6f, 9.6f, 7f, 5.5f, 5.5f }); tableDados.setWidthPercentage(100f); BaseColor colorCinza = new BaseColor(129, 138, 145); for (int j = 0; j < 13; j++) { PdfPCell cellTitileTable = new PdfPCell(new Phrase(titileTable(j), fontTableTitile)); cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellTitileTable.setBackgroundColor(colorCinza); tableDados.addCell(cellTitileTable); } dataViagem(dataInicio, dateFim); float premiototal = 0; for (HashMap<String, Object> data : hasList) { tableDados.addCell(new Phrase(toString(data.get(DATA)), fontTableCorpo)); tableDados.addCell(ExportViagemSemanaPdf .cellEspecial(new PdfPCell(new Phrase(toString(data.get(NUMEROAPOLICE)), fontTableCorpo)))); tableDados.addCell( new Phrase(ConfigDoc.toFormat(toString(data.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"), fontTableCorpo)); tableDados.addCell(new Phrase( ConfigDoc.toFormat(toString(data.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), fontTableCorpo)); premiototal += toFloat(data.get(PREMIO)); PdfPCell cellRigh = new PdfPCell( new Phrase(ConfigDoc.toMoeda(toFloat(data.get(PREMIO)), ""), fontTableCorpo)); cellRigh.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); tableDados.addCell(cellRigh); tableDados.addCell(new Phrase(toString(data.get(CLIENTE)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(DATANASCIMENTO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(TELEFONE)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(ENDERECO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(LOCALNASCIMENTO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(PAISDESTINO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(CIDADEDESTINO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(ZONADESTINO)), fontTableCorpo)); } PdfPCell cellTotal = new PdfPCell(ExportViagemSemanaPdf.cellEspecial(new PdfPCell( new Phrase("AL AMOUNT..........................................", fontTableTitile)))); cellTotal.setColspan(4); cellTotal.setPadding(1.5f); cellTotal.setBackgroundColor(colorCinza); tableDados.addCell(cellTotal); cellTotal = new PdfPCell(ExportViagemSemanaPdf .cellEspecial(new PdfPCell(new Phrase(ConfigDoc.toMoeda(premiototal, ""), fontTableTitile)))); cellTotal.setPadding(1.5f); cellTotal.setBackgroundColor(colorCinza); tableDados.addCell(cellTotal); cellTotal = new PdfPCell( ExportViagemSemanaPdf.cellEspecial(new PdfPCell(new Phrase(" ", fontTableTitile)))); cellTotal.setColspan(8); cellTotal.setPadding(1.5f); cellTotal.setBackgroundColor(colorCinza); tableDados.addCell(cellTotal); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 15f, 85f }); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 85f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); pTableEmpresaPricipal.setWidthPercentage(95); pTableEmpresaPricipal.addCell(cellTabela6); pTableEmpresaPricipal.addCell(cellTabela5); PdfPTable pTableTitulo = new PdfPTable(1); pTableTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); pTableTitulo.setWidthPercentage(100); PdfPCell cellTitulo = new PdfPCell(new Phrase("RLELATORIO SEMANAL NO. " + "" + "\n" + ((dataInicio != null) ? sdfTitile.format(dataInicio) + " - " : "") + ((dateFim != null) ? sdfTitile.format(dateFim) : ""), fontCorpoNG)); cellTitulo.setBorder(0); cellTitulo.setPaddingBottom(20f); cellTitulo.setPaddingTop(10f); cellTitulo.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pTableTitulo.addCell(cellTitulo); pTableEmpresaPricipal.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable pTableRodape = new PdfPTable(new float[] { 50f, 50f }); pTableRodape.setWidthPercentage(90f); PdfPCell cellRodape = new PdfPCell(new Phrase("DEPARTAMENTO FINANCEIRO", fontRoadapeBU)); cellRodape.setBorder(0); cellRodape.setColspan(2); cellRodape.setPaddingTop(20f); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("QUEIRA POR FAVOR CONFERIR OS PAGAMENTOS", fontRoadape)); cellRodape.setColspan(2); cellRodape.setBorder(0); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("ELABORADO POR", fontRoadapeB)); cellRodape.setBorder(0); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("VENFICADO POR", fontRoadapeB)); cellRodape.setBorder(0); cellRodape.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("................................................", fontRoadape)); cellRodape.setBorder(0); cellRodape.setPaddingTop(30f); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("................................................", fontRoadape)); cellRodape.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellRodape.setBorder(0); cellRodape.setPaddingTop(30f); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase(nomeFuncinario, fontRoadapeP)); cellRodape.setColspan(2); cellRodape.setBorder(0); pTableRodape.addCell(cellRodape); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableTitulo); documento.add(tableDados); documento.add(pTableRodape); documento.close(); RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(ExportViagemSemanaPdf.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportViagemSemanaPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Export.FaturaCoReSeguro__.java
public String docSeguros(String nomeSeguro, String numApolice, String fundoContrato, String user, String moeda, String arquivo, String numeroRegistro) { String reString;//from w ww . j ava 2s . c om try { Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontLinha = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 0.000000358f); Font fontCabecalhoS = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontNull = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 4f); Font fontMenor = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontMenorN = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 80, 20 }); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres4 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoN)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); PdfPCell pCellCapital = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAPITALSOCIAL, fontCabecalhoN)); pCellCapital.setBorder(0); PdfPCell pCellPolice = new PdfPCell(new Phrase(ConfigDoc.Empresa.APOLICE + numApolice, fontCabecalhoN)); pCellPolice.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 100f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); pTableEmpresaInforImpres2.addCell(pCellCapital); pTableEmpresaInforImpres2.addCell(pCellPolice); PdfPCell cellTabela1 = new PdfPCell(pTableEmpresaInforImpres2); cellTabela1.setBorder(0); pTableEmpresaInforImpres4.addCell(cellTabela1); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela4 = new PdfPCell(pTableEmpresaInforImpres4); cellTabela4.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela4); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); pTableEmpresaPricipal.addCell(cellTabela5); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); cellTabela6.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableEmpresaPricipal.addCell(cellTabela6); PdfPTable pTableLinha = new PdfPTable(1); PdfPCell linha = new PdfPCell(new Phrase(" ", fontLinha)); linha.setBorderWidthTop(0.5f); linha.setBorderWidthBottom(0); linha.setBorderWidthLeft(0); linha.setBorderWidthRight(0); pTableLinha.addCell(linha); /** * Tile Doc */ PdfPTable pTableTileDoc = new PdfPTable(new float[] { 65f, 35f }); PdfPCell cellTileDoc = new PdfPCell(new Phrase("FACTURA", fontCabecalhoS)); cellTileDoc.setColspan(2); cellTileDoc.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellTileDoc.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellTileDoc); Paragraph pNumFatura = new Paragraph(); pNumFatura.add(new Phrase("Factura N ", fontMenorN)); pNumFatura.add(new Phrase("0019528/16 ", fontMenor)); cellTileDoc = new PdfPCell(pNumFatura); cellTileDoc.setColspan(2); cellTileDoc.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellTileDoc.setBorder(PdfPCell.NO_BORDER); cellTileDoc.setPaddingBottom(10f); pTableTileDoc.addCell(cellTileDoc); PdfPTable pTableCliente = new PdfPTable(new float[] { 100 }); Paragraph pCliente = new Paragraph(); pCliente.add(new Phrase("Nome: ", fontCorpo)); pCliente.add(new Phrase(" ", fontCorpoN)); PdfPCell cellCliente = new PdfPCell(pCliente); cellCliente.setBorder(PdfPCell.NO_BORDER); pTableCliente.addCell(cellCliente); pCliente = new Paragraph(); pCliente.add(new Phrase("Morada: ", fontCorpo)); pCliente.add(new Phrase(" ", fontCorpoN)); cellCliente = new PdfPCell(pCliente); cellCliente.setBorder(PdfPCell.NO_BORDER); pTableCliente.addCell(cellCliente); pCliente = new Paragraph(); pCliente.add(new Phrase("Localidade: ", fontCorpo)); pCliente.add(new Phrase(" ", fontCorpoN)); pCliente.add(new Phrase(" ?rea: ", fontCorpo)); pCliente.add(new Phrase(" ", fontCorpoN)); pCliente.add(new Phrase(" CP: ", fontCorpo)); pCliente.add(new Phrase(" ", fontCorpoN)); cellCliente = new PdfPCell(pCliente); cellCliente.setBorder(PdfPCell.NO_BORDER); pTableCliente.addCell(cellCliente); pCliente = new Paragraph(); pCliente.add(new Phrase("Telefone: ", fontCorpo)); pCliente.add(new Phrase(" ", fontCorpoN)); cellCliente = new PdfPCell(pCliente); cellCliente.setBorder(PdfPCell.NO_BORDER); pTableCliente.addCell(cellCliente); cellCliente = new PdfPCell(pTableCliente); cellCliente.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellCliente); PdfPTable pTableContrato = new PdfPTable(new float[] { 40, 60 }); PdfPCell cellContrato = new PdfPCell(new Phrase("Data", fontCorpo)); cellContrato.setBorder(PdfPCell.NO_BORDER); pTableContrato.addCell(cellContrato); cellContrato = new PdfPCell(new Phrase("09-12-2016", fontCorpo)); cellContrato.setBorder(PdfPCell.NO_BORDER); pTableContrato.addCell(cellContrato); cellContrato = new PdfPCell(new Phrase("Vendedor", fontCorpo)); cellContrato.setBorder(PdfPCell.NO_BORDER); pTableContrato.addCell(cellContrato); cellContrato = new PdfPCell(new Phrase("SAT ISURANCE", fontCorpoN)); cellContrato.setBorder(PdfPCell.NO_BORDER); pTableContrato.addCell(cellContrato); cellContrato = new PdfPCell(new Phrase(" ", fontCorpoN)); cellContrato.setBorder(PdfPCell.NO_BORDER); pTableContrato.addCell(cellContrato); Paragraph pNIF = new Paragraph(); pNIF.add(new Phrase("NIF: ", fontCorpoN)); pNIF.add(new Phrase(" 517255068", fontCorpoN)); cellContrato = new PdfPCell(pNIF); cellContrato.setBorder(PdfPCell.NO_BORDER); pTableContrato.addCell(cellContrato); cellContrato = new PdfPCell(pTableContrato); cellContrato.setBorder(PdfPCell.BOX); cellContrato.setPadding(5f); pTableTileDoc.addCell(cellContrato); PdfPTable pTableDados = new PdfPTable(new float[] { 10, 50, 18, 22 }); PdfPCell cellDados = new PdfPCell(new Phrase("Qtde.", fontCorpoN)); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Descrio.", fontCorpoN)); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Preo unitrio", fontCorpoN)); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Total", fontCorpoN)); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Qtde.", fontCorpo)); cellDados.setRowspan(13); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Descrio.", fontCorpo)); cellDados.setRowspan(13); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Preo unitrio", fontCorpo)); cellDados.setRowspan(13); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Total", fontCorpo)); cellDados.setBorderWidthTop(0); cellDados.setBorderWidthBottom(0); cellDados.setBorderWidthLeft(0); cellDados.setBorderWidthRight(0.5f); pTableDados.addCell(cellDados); for (int i = 0; i < 12; i++) { cellDados = new PdfPCell(new Phrase(" ", fontCorpo)); cellDados.setBorderWidthTop(0f); if ((i != (12 - 1))) { cellDados.setBorderWidthBottom(0f); } cellDados.setBorderWidthLeft(0f); cellDados.setBorderWidthRight(0.5f); pTableDados.addCell(cellDados); } cellDados = new PdfPCell(new Phrase("Total", fontCorpo)); cellDados.setColspan(2); cellDados.setRowspan(8); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("SubTotal", fontCorpo)); cellDados.setBorder(PdfPCell.NO_BORDER); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("46.666.790,01 STD", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Acessrios", fontCorpo)); cellDados.setBorder(PdfPCell.NO_BORDER); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("1.000.000,00 STD", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Imposto", fontCorpo)); cellDados.setBorder(PdfPCell.NO_BORDER); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("2.680.669,75 STD", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("FGA", fontCorpo)); cellDados.setBorder(PdfPCell.NO_BORDER); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("1.196.669,75 STD", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("TOTAL", fontCorpoN)); cellDados.setBorder(PdfPCell.NO_BORDER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("51.744.000,00 STD", fontCorpoN)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Cambio", fontCorpo)); cellDados.setBorder(PdfPCell.NO_BORDER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("24.500,00 STD", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellDados.setBorder(PdfPCell.NO_BORDER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Total a pagar Euros", fontCorpo)); cellDados.setBorderWidthRight(0); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("2.112,00 EUR", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellDados.setBorderWidthLeft(0); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Total a Pagar USD", fontCorpo)); cellDados.setBorderWidthRight(0); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("2.282.78 USD", fontCorpo)); cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellDados.setBorderWidthLeft(0); pTableDados.addCell(cellDados); SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 70f, 5f); String f1 = (arquivo + "/" + user + "/Seguro " + nomeSeguro + "/"); File f = new File(f1); String Ddata = sdf1.format(new Date()); f.mkdirs(); f = new File(f.getAbsoluteFile() + "/" + "Fatura CO-Re SEGURO " + Ddata + ".pdf"); reString = "../Documentos/" + user + "/Seguro " + nomeSeguro + "/" + "Fatura CO-Re SEGURO " + Ddata + ".pdf"; OutputStream outputStraem = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableLinha); documento.add(pTableLinha); documento.add(pTableTileDoc); documento.add(pTableDados); documento.close(); return reString; } catch (FileNotFoundException | DocumentException e) { } catch (IOException ex) { Logger.getLogger(DocNotaCredito.class.getName()).log(Level.SEVERE, null, ex); } return ""; }