List of usage examples for com.itextpdf.text FontFactory getFont
public static Font getFont(final String fontname, final float size, final int style, final BaseColor color)
Font
-object. From source file:org.smap.sdal.managers.MiscPDFManager.java
License:Open Source License
public void createTasksPdf(Connection sd, OutputStream outputStream, String basePath, HttpServletRequest request, HttpServletResponse response, int tgId) { try {// ww w. j a v a 2s. co m // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "default"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("default", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); /* * Get the tasks for this task group */ String urlprefix = request.getScheme() + "://" + request.getServerName(); TaskManager tm = new TaskManager(localisation, tz); TaskListGeoJson t = tm.getTasks(sd, urlprefix, 0, tgId, 0, false, 0, null, "all", 0, 0, "scheduled", "desc"); PdfWriter writer = null; String filename = "tasks.pdf"; // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); setFilenameInResponse(filename, response); } Document document = new Document(PageSize.A4); document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); writer = PdfWriter.getInstance(document, outputStream); writer.setInitialLeading(12); writer.setPageEvent(new PageSizer()); document.open(); PdfPTable table = new PdfPTable(4); // Add the header row table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setBackgroundColor(VLG); table.addCell("Form Name"); table.addCell("Task Name"); table.addCell("Status"); table.addCell("Assigned To"); table.setHeaderRows(1); // Add the task data table.getDefaultCell().setBackgroundColor(null); for (TaskFeature tf : t.features) { TaskProperties p = tf.properties; table.addCell(p.survey_name); table.addCell(p.name); table.addCell(p.status); table.addCell(p.assignee_name); } document.add(table); document.close(); } catch (SQLException e) { log.log(Level.SEVERE, "SQL Error", e); } catch (Exception e) { log.log(Level.SEVERE, "Exception", e); } }
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
public String createPdf(OutputStream outputStream, String basePath, String serverRoot, String remoteUser, String language, boolean generateBlank, String filename, boolean landscape, // Set true if landscape HttpServletResponse response) throws Exception { if (language != null) { language = language.replace("'", "''"); // Escape apostrophes } else {//from w w w . j a va 2s . c om language = "none"; } mExcludeEmpty = survey.exclude_empty; User user = null; ServerManager serverManager = new ServerManager(); ServerData serverData = serverManager.getServer(sd, localisation); UserManager um = new UserManager(localisation); int[] repIndexes = new int[20]; // Assume repeats don't go deeper than 20 levels Document document = null; PdfWriter writer = null; PdfReader reader = null; PdfStamper stamper = null; try { // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); //FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/Library/Fonts/NotoSans-Regular.ttf", "notosans"); FontFactory.register("/Library/Fonts/NotoSans-Bold.ttf", "notosansbold"); FontFactory.register("/Library/Fonts/NotoSansBengali-Regular.ttf", "bengali"); FontFactory.register("/Library/Fonts/NotoSansBengali-Bold.ttf", "bengalibold"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Bold.ttf", "notosansbold"); FontFactory.register("/usr/share/fonts/truetype/NotoSansBengali-Regular.ttf", "bengali"); FontFactory.register("/usr/share/fonts/truetype/NotoSansBengali-Bold.ttf", "bengalibold"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFontLink = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("notosans", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); defaultFontBold = FontFactory.getFont("notosansbold", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); arabicFont = FontFactory.getFont("arabic", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); bengaliFont = FontFactory.getFont("bengali", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); bengaliFontBold = FontFactory.getFont("bengalibold", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); defaultFontLink.setColor(BaseColor.BLUE); /* * Get the results and details of the user that submitted the survey */ log.info("User Ident who submitted the survey: " + survey.instance.user); String userName = survey.instance.user; if (userName == null) { userName = remoteUser; } if (userName != null) { user = um.getByIdent(sd, userName); } // If a filename was not specified then get one from the survey data // This filename is returned to the calling program so that it can be used as a permanent name for the temporary file created here // If the PDF is to be returned in an http response then the header is set now before writing to the output stream log.info("Filename passed to createPDF is: " + filename); if (filename == null) { filename = survey.getInstanceName() + ".pdf"; } else { if (!filename.endsWith(".pdf")) { filename += ".pdf"; } } // If the PDF is to be returned in an http response then set the file name now if (response != null) { log.info("Setting filename to: " + filename); GeneralUtilityMethods.setFilenameInResponse(filename, response); } /* * Get a template for the PDF report if it exists * The template name will be the same as the XLS form name but with an extension of pdf */ File templateFile = GeneralUtilityMethods.getPdfTemplate(basePath, survey.displayName, survey.p_id); /* * Get dependencies between Display Items, for example if a question result should be added to another * question's results */ GlobalVariables gv = new GlobalVariables(); if (!generateBlank) { for (int i = 0; i < survey.instance.results.size(); i++) { getDependencies(gv, survey.instance.results.get(i), survey, i); } } gv.mapbox_key = serverData.mapbox_default; int oId = GeneralUtilityMethods.getOrganisationId(sd, remoteUser); languageIdx = GeneralUtilityMethods.getLanguageIdx(survey, language); if (templateFile.exists()) { log.info("PDF Template Exists"); String templateName = templateFile.getAbsolutePath(); reader = new PdfReader(templateName); stamper = new PdfStamper(reader, outputStream); for (int i = 0; i < survey.instance.results.size(); i++) { fillTemplate(gv, stamper.getAcroFields(), survey.instance.results.get(i), basePath, null, i, serverRoot, stamper, oId); } if (user != null) { fillTemplateUserDetails(stamper.getAcroFields(), user, basePath); } stamper.setFormFlattening(true); } else { log.info("++++No template exists creating a pdf file programmatically"); /* * Create a PDF without the stationary * If we need to add a letter head then create document in two passes, the second pass adds the letter head * Else just create the document directly in a single pass */ Parser parser = getXMLParser(); // Step 1 - Create the underlying document as a byte array if (landscape) { document = new Document(PageSize.A4.rotate()); } else { document = new Document(PageSize.A4); } document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); writer = PdfWriter.getInstance(document, outputStream); writer.setInitialLeading(12); writer.setPageEvent(new PdfPageSizer(survey.displayName, survey.projectName, user, basePath, null, marginLeft, marginRight, marginTop_2, marginBottom_2)); document.open(); // If this form has data maintain a list of parent records to lookup ${values} ArrayList<ArrayList<Result>> parentRecords = null; if (!generateBlank) { parentRecords = new ArrayList<ArrayList<Result>>(); } for (int i = 0; i < survey.instance.results.size(); i++) { processForm(parser, document, survey.instance.results.get(i), basePath, serverRoot, generateBlank, 0, i, repIndexes, gv, false, parentRecords, remoteUser, oId); } fillNonTemplateUserDetails(document, user, basePath); // Add appendix if (gv.hasAppendix) { document.newPage(); document.add(new Paragraph("Appendix", defaultFontBold)); for (int i = 0; i < survey.instance.results.size(); i++) { processForm(parser, document, survey.instance.results.get(i), basePath, serverRoot, generateBlank, 0, i, repIndexes, gv, true, parentRecords, remoteUser, oId); } } } } finally { if (document != null) try { document.close(); } catch (Exception e) { } ; if (writer != null) try { writer.close(); } catch (Exception e) { } ; if (stamper != null) try { stamper.close(); } catch (Exception e) { } ; if (reader != null) try { reader.close(); } catch (Exception e) { } ; } return filename; }
From source file:org.smap.sdal.managers.PDFTableManager.java
License:Open Source License
public void createPdf(Connection sd, OutputStream outputStream, ArrayList<ArrayList<KeyValue>> dArray, SurveyViewDefn mfc, ResourceBundle localisation, String tz, boolean landscape, String remoteUser, String basePath, String title, String project) { User user = null;/* w ww . j a v a2 s.co m*/ UserManager um = new UserManager(localisation); try { user = um.getByIdent(sd, remoteUser); // Get fonts and embed them String os = System.getProperty("os.name"); log.info("Operating System:" + os); if (os.startsWith("Mac")) { FontFactory.register("/Library/Fonts/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/Library/Fonts/Arial Unicode.ttf", "default"); FontFactory.register("/Library/Fonts/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/Library/Fonts/NotoSans-Regular.ttf", "notosans"); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) { // Linux / Unix FontFactory.register("/usr/share/fonts/truetype/fontawesome-webfont.ttf", "Symbols"); FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "default"); FontFactory.register("/usr/share/fonts/truetype/NotoNaskhArabic-Regular.ttf", "arabic"); FontFactory.register("/usr/share/fonts/truetype/NotoSans-Regular.ttf", "notosans"); } Symbols = FontFactory.getFont("Symbols", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); defaultFont = FontFactory.getFont("default", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); ArrayList<PdfColumn> cols = getPdfColumnList(mfc, dArray, localisation); ArrayList<String> tableHeader = new ArrayList<String>(); for (PdfColumn col : cols) { tableHeader.add(col.displayName); } /* * Create a PDF without the stationary */ PdfWriter writer = null; /* * If we need to add a letter head then create document in two passes, the second pass adds the letter head * Else just create the document directly in a single pass */ Parser parser = getXMLParser(); // Step 1 - Create the underlying document as a byte array Document document = null; if (landscape) { document = new Document(PageSize.A4.rotate()); } else { document = new Document(PageSize.A4); } document.setMargins(marginLeft, marginRight, marginTop_1, marginBottom_1); writer = PdfWriter.getInstance(document, outputStream); writer.setInitialLeading(12); writer.setPageEvent(new PdfPageSizer(title, project, user, basePath, tableHeader, marginLeft, marginRight, marginTop_2, marginBottom_2)); document.open(); document.add(new Chunk("")); // Ensure there is something in the page so at least a blank document will be created processResults(parser, document, dArray, cols, basePath); document.close(); } catch (SQLException e) { log.log(Level.SEVERE, "SQL Error", e); } catch (Exception e) { log.log(Level.SEVERE, "Exception", e); } }
From source file:pdf.PdfBuilder.java
/** * Creates an accessible PDF with images and text. * @param dest the path to the resulting PDF * @throws IOException/*from w ww.j a v a2 s. c o m*/ * @throws DocumentException */ public String createPdf(Invoice invoice) throws IOException, DocumentException { DEST = "C://temp/"; SimpleDateFormat sdf = new SimpleDateFormat("MM"); DEST += invoice.getCar().getId() + "month" + sdf.format(invoice.getSeriesOfLocationsOnRoad().get(0).getLocations().get(0).getDate()) + ".pdf"; File file = new File(DEST); file.getParentFile().mkdirs(); Document document = new Document(PageSize.A4.rotate()); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST)); writer.setPdfVersion(PdfWriter.VERSION_1_7); //TAGGED PDF //Make document tagged writer.setTagged(); //=============== //PDF/UA //Set document metadata writer.setViewerPreferences(PdfWriter.DisplayDocTitle); document.addLanguage("en-US"); document.addTitle("Factuur voor auto " + invoice.getCar().getLicensePlate()); writer.createXmpMetadata(); //===================== document.open(); Font font = FontFactory.getFont(FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 20); double amountPaidForDistance = invoice.getTotalAmount(); double amountPaidForCordons = 0; for (Cordon c : invoice.getCordonOccurrences()) { amountPaidForDistance -= c.getAmount(); amountPaidForCordons += c.getAmount(); } Paragraph p = new Paragraph("\n", font); p.add(new Chunk("Aantal gereden kilometers:")); p.add(new Chunk("\n")); p.add(new Chunk(String.valueOf(invoice.getTotalDistance()) + " kilometer")); p.add(new Chunk("\n")); p.add(new Chunk("Met een gemiddeld tarief van " + (amountPaidForDistance / invoice.getTotalDistance() * 100) + " eurocent per kilometer")); p.add(new Chunk("\n")); p.add(new Chunk("Bedrag dat betaald dient te worden over de kilometers: ")); p.add(new Chunk("\n")); p.add(new Chunk(amountPaidForDistance + " euro")); document.add(p); p = new Paragraph("\n\n", font); p.add(new Chunk(invoice.cordonOccurrencesString())); p.add(new Chunk("\n")); p.add(new Chunk("Bedrag dat betaald dient te worden over de cordons: ")); p.add(new Chunk("\n")); p.add(new Chunk(amountPaidForCordons + " euro")); document.add(p); p = new Paragraph("\n\n", font); p.add(new Chunk("Totaal bedrag dat betaald dient te worden: ")); p.add(new Chunk("\n")); p.add(new Chunk(String.valueOf(invoice.getTotalAmount()) + " euro")); document.add(p); document.close(); return DEST; }
From source file:pkgAgenda_Virtual.frmActividades.java
public void PDFpersonales() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;//from ww w. j a v a 2 s.com try { FacturaPdf = new FileOutputStream("archives/ActividadesPersonales.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades Personales de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tblHoy = new PdfPTable(4); PdfPTable tblAntes = new PdfPTable(4); PdfPTable tblDespues = new PdfPTable(4); tblHoy.addCell("Titulo"); tblHoy.addCell("Fecha"); tblHoy.addCell("Hora"); tblHoy.addCell("Lugar"); tblAntes.addCell("Titulo"); tblAntes.addCell("Fecha"); tblAntes.addCell("Hora"); tblAntes.addCell("Lugar"); tblDespues.addCell("Titulo"); tblDespues.addCell("Fecha"); tblDespues.addCell("Hora"); tblDespues.addCell("Lugar"); //sdfhfjhsdfsd int valor; rs = H.Buscar("SELECT nom_act, fecha_act, hora_act, lugar_act FROM Actividades WHERE cod_usu = " + H.Usuario + " AND id_tipoact = 2"); while (rs.next()) { String fecharecibida = rs.getString(2).substring(0, 10); valor = H.FechaAnterior(fecharecibida); if (valor == 2) { tblHoy.addCell(H.desencriptar(rs.getString(1))); tblHoy.addCell(fecharecibida); tblHoy.addCell(rs.getString(3).substring(0, 5)); tblHoy.addCell(H.desencriptar(rs.getString(4))); } else if (valor == 1) { tblAntes.addCell(H.desencriptar(rs.getString(1))); tblAntes.addCell(fecharecibida); tblAntes.addCell(rs.getString(3).substring(0, 5)); tblAntes.addCell(H.desencriptar(rs.getString(4))); } else if (valor == 0) { tblDespues.addCell(H.desencriptar(rs.getString(1))); tblDespues.addCell(fecharecibida); tblDespues.addCell(rs.getString(3).substring(0, 5)); tblDespues.addCell(H.desencriptar(rs.getString(4))); } } //askjdhskfjhdf documento.add(new Paragraph("Actividades Pasadas")); documento.add(new Paragraph(" ")); documento.add(tblAntes); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades de Hoy")); documento.add(new Paragraph(" ")); documento.add(tblHoy); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades Futuras")); documento.add(new Paragraph(" ")); documento.add(tblDespues); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pkgAgenda_Virtual.frmActividades.java
public void PDFdeestudio() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;/* ww w .ja v a 2 s . c o m*/ try { FacturaPdf = new FileOutputStream("archives/ActividadesdeEstudio.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades de Estudio de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tblHoy = new PdfPTable(4); PdfPTable tblAntes = new PdfPTable(4); PdfPTable tblDespues = new PdfPTable(4); tblHoy.addCell("Asignatura"); tblHoy.addCell("Tarea"); tblHoy.addCell("Fecha"); tblHoy.addCell("Hora"); tblAntes.addCell("Asignatura"); tblAntes.addCell("Tarea"); tblAntes.addCell("Fecha"); tblAntes.addCell("Hora"); tblDespues.addCell("Asignatura"); tblDespues.addCell("Tarea"); tblDespues.addCell("Fecha"); tblDespues.addCell("Hora"); //sdfhfjhsdfsd int valor; rs = H.Buscar("SELECT nom_act, des_act, fecha_act, hora_act FROM Actividades WHERE cod_usu = " + H.Usuario + " AND id_tipoact = 1"); while (rs.next()) { String fecharecibida = rs.getString(3).substring(0, 10); valor = H.FechaAnterior(fecharecibida); if (valor == 2) { tblHoy.addCell(H.desencriptar(rs.getString(1))); tblHoy.addCell(H.desencriptar(rs.getString(2))); tblHoy.addCell(fecharecibida); tblHoy.addCell(rs.getString(4).substring(0, 5)); } else if (valor == 1) { tblAntes.addCell(H.desencriptar(rs.getString(1))); tblAntes.addCell(H.desencriptar(rs.getString(2))); tblAntes.addCell(fecharecibida); tblAntes.addCell(rs.getString(4).substring(0, 5)); } else if (valor == 0) { tblDespues.addCell(H.desencriptar(rs.getString(1))); tblDespues.addCell(H.desencriptar(rs.getString(2))); tblDespues.addCell(fecharecibida); tblDespues.addCell(rs.getString(4).substring(0, 5)); } } //askjdhskfjhdf documento.add(new Paragraph("Actividades Pasadas")); documento.add(new Paragraph(" ")); documento.add(tblAntes); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades de Hoy")); documento.add(new Paragraph(" ")); documento.add(tblHoy); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades Futuras")); documento.add(new Paragraph(" ")); documento.add(tblDespues); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pkgAgenda_Virtual.frmAgenda.java
public void PDF() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;//from www . ja va 2s . c o m try { FacturaPdf = new FileOutputStream("archives/Notas.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Notas de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(2); tabla.addCell("Titulo"); tabla.addCell("Descripcion"); //sdfhfjhsdfsd rs = H.Buscar( "SELECT nom_nota, des_nota FROM Notas WHERE cod_usu = " + H.Usuario + " ORDER BY nom_nota ASC"); while (rs.next()) { tabla.addCell(rs.getString(1)); tabla.addCell(rs.getString(2)); } //askjdhskfjhdf documento.add(tabla); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pkgAgenda_Virtual.frmVerContactos.java
public void PDF() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;//ww w . j a v a 2 s .c o m try { FacturaPdf = new FileOutputStream("archives/Contactos.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Contactos de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(4); tabla.addCell("Apellidos"); tabla.addCell("Nombres"); tabla.addCell("Telefono"); tabla.addCell("Correo"); //sdfhfjhsdfsd rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + ""); while (rs.next()) { cantidad_contactos += 1; } contactosdesordenados = new String[cantidad_contactos]; rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + ""); while (rs.next()) { contactosdesordenados[num_contacto] = H.desencriptar(rs.getString(1)); num_contacto += 1; } contactosordenados = new String[cantidad_contactos]; Arrays.sort(contactosdesordenados); contactosordenados = contactosdesordenados; for (int i = 0; i < contactosordenados.length; i++) { if (!"".equals(contactosordenados[i].toString())) { rs = H.Buscar( "SELECT ape_contacto, nom_contacto, tel1_contacto, correo_contacto FROM Contactos WHERE ape_contacto = '" + H.encriptar(contactosordenados[i].toString()) + "'"); while (rs.next()) { tabla.addCell(H.desencriptar(rs.getString(1))); tabla.addCell(H.desencriptar(rs.getString(2))); tabla.addCell(rs.getString(3)); tabla.addCell(H.desencriptar(rs.getString(4))); } } } //askjdhskfjhdf documento.add(tabla); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pkgfinal.viewTable.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed try {//from w ww.ja v a2 s .c om Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(" " + jComboBox1.getSelectedItem() + ".pdf")); document.open(); // Image image = Image.getInstance("save.png"); // document.add(new Paragraph("image")); // document.add(image); document.add(new Paragraph("ECHO TRADERS", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.RED))); document.add(new Paragraph(" " + jComboBox1.getSelectedItem() + " Report ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.BLUE))); document.add(new Paragraph(new java.util.Date().toString())); document.add(new Paragraph("--------------------------------------------------------")); PdfPTable table = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Purcahse_Sale Report")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); String sql = "select * from '" + jComboBox1.getSelectedItem() + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { String v1 = rs.getString("ID"); String add = rs.getString("Date"); String v2 = rs.getString("BrandName"); String v3 = rs.getString("ManufactureName"); String v4 = rs.getString("PurchaseQuantity"); String v5 = rs.getString("SaleQuantity"); String v6 = rs.getString("TotalQuantity"); // table.addCell("ID"); table.addCell(v1); // table.addCell(v/*.date_tf.getDateFormatString()*/); table.addCell(add); // table.addCell("Brand name"); table.addCell(v2); // table.addCell("Manyfacture Name"); table.addCell(v3); // table.addCell("purchase Quantity"); table.addCell(v4); table.addCell(v5); table.addCell(v6); } document.add(table); com.itextpdf.text.List list = new com.itextpdf.text.List(true, 20); list.add("Printed Date:_____________"); list.add("Signature:_______________"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Saved Report"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:PROCESOS.ImprimirPDF.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); String precio_unitario = request.getParameter("precio"); String id_vale = request.getParameter("codigo"); // if(request.getParameter("codigo")!=null){ OutputStream salida = response.getOutputStream(); try {// w w w .j ava2 s. c o m try { DTO.ClaseTransaccion clase = new ClaseTransaccion(); clase = consulta.Transaccion(); Document documento = new Document(PageSize.A4, 36, 36, 45, 20); PdfWriter pw = PdfWriter.getInstance(documento, salida); documento.open(); Paragraph parrafo1 = new Paragraph(); Font font_titulo = new Font(Font.FontFamily.HELVETICA, 16, Font.UNDERLINE, BaseColor.BLACK); parrafo1.add(new Phrase("TecnoBencina, COMPROBANTE", font_titulo)); parrafo1.setAlignment(Element.ALIGN_CENTER); parrafo1.add(new Phrase(Chunk.NEWLINE)); parrafo1.add(new Phrase(Chunk.NEWLINE)); documento.add(parrafo1); Paragraph parrafo2 = new Paragraph(); Font font_titulo_p2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK); if (id_vale.length() > 0) { parrafo2.add(new Phrase("Comprobante de transaccion : codigo del vale : " + id_vale, font_titulo_p2)); } else { parrafo2.add(new Phrase("Comprobante de transaccion ", font_titulo_p2)); } parrafo2.setAlignment(Element.ALIGN_JUSTIFIED); parrafo2.add(new Phrase(Chunk.NEWLINE)); parrafo2.add(new Phrase(Chunk.NEWLINE)); parrafo2.add(new Phrase(Chunk.NEWLINE)); documento.add(parrafo2); PdfPTable tabla = new PdfPTable(9); PdfPCell celda1 = new PdfPCell(new Paragraph("ID transaccion ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell( new Paragraph("Estado ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("ID de surtidor", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell( new Paragraph("Litros", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda5 = new PdfPCell( new Paragraph("Monto", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda6 = new PdfPCell( new Paragraph("Fecha", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda7 = new PdfPCell( new Paragraph("ID pago", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda8 = new PdfPCell(new Paragraph("Precio unitario", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); tabla.addCell(celda5); tabla.addCell(celda6); tabla.addCell(celda7); tabla.addCell(celda8); tabla.addCell(String.valueOf(clase.getId_transaccion())); tabla.addCell(clase.getEstado()); tabla.addCell(String.valueOf(clase.getId_transaccion())); tabla.addCell(String.valueOf(clase.getLitros())); tabla.addCell(String.valueOf(clase.getMonto())); tabla.addCell(String.valueOf(clase.getFecha())); tabla.addCell(String.valueOf(clase.getId_pago())); tabla.addCell(precio_unitario); documento.add(tabla); documento.addAuthor("TecnoBencina"); documento.addTitle("Comprobante"); documento.addLanguage("Espaol"); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph("texto....", font_titulo_p2)); documento.close(); } catch (Exception s) { s.getMessage(); } } catch (Exception s) { System.out.println("" + s.getMessage()); } finally { salida.close(); } // } }