List of usage examples for com.itextpdf.text Image setAlignment
public void setAlignment(final int alignment)
From source file:principal.Informes.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . jav a 2 s .c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DocumentException, InterruptedException { // SERVLET PARA LA IMPRESIN DE LOS REGISTROS DE SISTEMA try { // Ejecucion de comando que sera introducido en el pdf Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("/opt/script/owncloud/logOwncloud"); process.waitFor(); BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream())); String linea; //Imagen para documento PDF Image imagen = Image.getInstance("images/owncloud.png"); imagen.setAlignment(Element.ALIGN_CENTER); //donde estara la imagen localizada imagen.setAlt("50"); // Creo objeto document de la clase Document Document document = new Document(); // paso 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Abro nuevo documento PDF document.open(); document.addAuthor("Administrator"); //Nuevo parrafo con texto centrado Paragraph parrafo1 = new Paragraph("Informe de servidor Owncloud"); parrafo1.setAlignment(1); //Centrar el texto document.add(imagen); //introduccion de la imagen en el documento pdf document.add(parrafo1); // bucle ejecutando el comando e introduciendolo en un nuevo parrafo del PDF while ((linea = buffer.readLine()) != null) { document.add(new Paragraph(linea)); } // Cierre del documento PDF document.close(); // Response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // Tipo de contenido que ser response.setContentType("application/pdf"); // the contentlength response.setContentLength(baos.size()); // Extrae todo el PDF para introducirlo en el servlet OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:projetohorus.DadosColetadosPDF.java
void GerarPDF() throws IOException, DocumentException, EmailException { Document doc = null;/*from w w w .j a v a2 s . com*/ OutputStream os = null; try { doc = new Document(PageSize.A4, 72, 72, 72, 72); os = new FileOutputStream("tesfinal11.pdf"); PdfWriter.getInstance(doc, os); doc.open(); Image img = Image.getInstance("LogoProject.png"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); InetAddress localHost = Inet4Address.getLocalHost(); NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); short x = networkInterface.getInterfaceAddresses().get(0).getNetworkPrefixLength(); String n = localHost.getHostAddress() + "/" + x; SubnetUtils utils = new SubnetUtils(n); ; PdfPTable table = new PdfPTable(new float[] { 0.50f, 0.70f, 0.90f }); table = new PdfPTable(3); Paragraph p = new Paragraph(""); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(30); doc.add(p); p = new Paragraph("Informaes da Network"); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(30); doc.add(p); Paragraph paragraph = new Paragraph("" + utils.getInfo()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(30); doc.add(paragraph); table.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell header = new PdfPCell(new Paragraph("Diagnostico do Scanner da Rede")); header.setColspan(3); table.addCell(header); table.addCell("IP"); table.addCell("HostName"); table.addCell("Portas Abertas"); for (int i = 0; i < IP.size(); i++) { table.addCell(IP.get(i)); table.addCell(NameHost.get(i)); table.addCell("" + PortasA.get(i)); } doc.add(table); } finally { if (doc != null) { doc.close(); } if (os != null) { os.close(); } } EnvioEmail sc = new EnvioEmail(); sc.EnvioEmail(); }
From source file:report.pdfs.Basics_PDF_Report.java
private void addBarChart(Section catPart) { Basics_Bar_Chart_Report chart = new Basics_Bar_Chart_Report(show, "Basic Expenses Overview"); Image To_be_Added = null; try {//from w w w . j a v a 2 s . co m To_be_Added = Image.getInstance("bar_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Basics_PDF_Report.java
private void addPieChart(Section catPart) { Basics_Pie_Chart_Report chart = new Basics_Pie_Chart_Report(show, "Comparison", "Basic Expenses Overview"); Image To_be_Added = null; try {/*from w ww .j a v a2s . c o m*/ To_be_Added = Image.getInstance("pie_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Feed_PDF_Report.java
private void addBarChart(Section catPart) { Feed_Bar_Chart_Report chart = new Feed_Bar_Chart_Report(show, "Feed Expenses Overview"); Image To_be_Added = null; try {/*from w ww .j av a 2s . c om*/ To_be_Added = Image.getInstance("bar_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Feed_PDF_Report.java
private void addPieChart(Section catPart) { Feed_Pie_Chart_Report chart = new Feed_Pie_Chart_Report(show, "Comparison", "Feed Expenses Overview"); Image To_be_Added = null; try {/*from w w w. jav a2s.c o m*/ To_be_Added = Image.getInstance("pie_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Fertilizer_PDF_Report.java
private void addBarChart(Section catPart) { Fertilizer_Bar_Chart_Report chart = new Fertilizer_Bar_Chart_Report(show, "Fertilizer Expenses Overview"); Image To_be_Added = null; try {/* w ww . j a v a2s . c o m*/ To_be_Added = Image.getInstance("bar_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Fertilizer_PDF_Report.java
private void addPieChart(Section catPart) { Fertilizer_Pie_Chart_Report chart = new Fertilizer_Pie_Chart_Report(show, "Comparison", "Fertilizer Expenses Overview"); Image To_be_Added = null; try {// w ww .j a v a 2s. c o m To_be_Added = Image.getInstance("pie_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Gas_PDF_Report.java
private void addBarChart(Section catPart) { Gas_Bar_Chart_Report chart = new Gas_Bar_Chart_Report(show, "Gas Expenses Overview"); Image To_be_Added = null; try {/*from w w w. j a v a 2 s. c o m*/ To_be_Added = Image.getInstance("bar_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }
From source file:report.pdfs.Gas_PDF_Report.java
private void addPieChart(Section catPart) { Gas_Pie_Chart_Report chart = new Gas_Pie_Chart_Report(show, "Comparison", "Gas Expenses Overview"); Image To_be_Added = null; try {/*from www . j ava 2 s . c o m*/ To_be_Added = Image.getInstance("pie_chart.png"); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } To_be_Added.setAlignment(Image.MIDDLE | Image.TEXTWRAP); //To_be_Added.setBorder(Image.BOX); //To_be_Added.setBorderWidth(15); catPart.add(To_be_Added); }