Example usage for com.itextpdf.text Image scalePercent

List of usage examples for com.itextpdf.text Image scalePercent

Introduction

In this page you can find the example usage for com.itextpdf.text Image scalePercent.

Prototype

public void scalePercent(final float percent) 

Source Link

Document

Scale the image to a certain percentage.

Usage

From source file:com.vimbox.hr.LicensePDFGenerator.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w  w  w  .jav  a2 s. co m
 *
 * @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 {
    response.setContentType("application/pdf");
    String fileName = request.getParameter("license_name");
    String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
    String path = System.getProperty("user.dir") + "/documents/licenses/" + fileName;
    path = path.replaceAll("%20", " ");
    if (ext.equalsIgnoreCase("pdf")) {
        FileInputStream baos = new FileInputStream(path);

        OutputStream os = response.getOutputStream();

        byte buffer[] = new byte[8192];
        int bytesRead;

        while ((bytesRead = baos.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }

        os.flush();
        os.close();
    } else {
        try {
            // Document Settings //
            Document document = new Document();
            PdfWriter.getInstance(document, response.getOutputStream());
            document.open();

            // Loading MC //
            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100);
            // the cell object
            PdfPCell cell;

            Image img = Image.getInstance(path);
            int indentation = 0;
            float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()
                    - indentation) / img.getWidth()) * 100;
            img.scalePercent(scaler);
            //img.scaleAbsolute(80f, 80f);
            cell = new PdfPCell(img);
            cell.setBorder(Rectangle.NO_BORDER);
            table.addCell(cell);
            document.add(table);
            //-----------------------------------//
            document.close();
        } catch (DocumentException de) {
            throw new IOException(de.getMessage());
        }
    }

}

From source file:containers.Receipt.java

public void printReceiptTogether() {
    try {/* www. j a v  a2 s . c o  m*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\receiptTogether.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        p.add(header);
        p.add(new Date().toString());
        footerTogether();
        p.add(body);
        p.add(footer);
        document.add(p);

        document.close();
        file.close();

        header = "";
        body = "";
        footer = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Receipt.java

public void printReceiptSeparate() {
    try {/*from   w  ww  .  ja v  a2s .c o m*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\receipt" + orderNumber + ".pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        p.add(header);
        p.add(new Date().toString());
        footerSeparate();
        p.add(body);
        p.add(footer);
        document.add(p);

        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateHours(String hours, String from, String to) {
    try {/*  w  w w .  j  a  v  a  2s . c  o m*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\EmployeeReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        ehours = hours;

        body = String.format("%-15s - %2s\n", "Employee Number", empno);
        body += String.format("%-15s - %5s\n", "First Name", fname);
        body += String.format("%-15s - %1s\n", "Last Name", lname);
        body += String.format("%-15s - %9s\n", "Address", address);
        body += String.format("%-15s - %9s\n", "Phone Number", phone);
        body += String.format("%-15s - %3s\n", "Position", position);
        body += String.format("%-15s - %8s\n", "Total Hours", ehours);
        body += "\n";

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nEmployee Report\n\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body);
        document.add(p);

        document.close();
        file.close();

        body = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderByDate(ArrayList<String> entry, String from, String to) {
    try {/*  ww  w.  j  a v  a 2s .com*/
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\DateOrderReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body2 = String.format("%5s - %5s - %5s - %5s\n", "Order No.", "Order Total", "Payment Type",
                "Order Date");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 4) {
            body2 += String.format("%-10s %8s %15s %24s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2),
                    entry.get(i + 3).substring(0, 19));
            counter += Double.parseDouble(entry.get(i + 1));
        }

        body2 += "\n\nTotal for all orders: $" + counter;

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nOrder by Date Report\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body2);
        document.add(p);

        document.close();
        file.close();

        body2 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderByPayment(String type, ArrayList<String> entry, String from, String to) {
    try {//from w  w  w . j  av  a  2  s  .  c om
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\PayTypeReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body3 = String.format("%5s - %5s - %5s\n", "Order No.", "Order Total", "Order Date");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 3) {
            body3 += String.format("%-10s %8s %25s\n", entry.get(i), entry.get(i + 1),
                    entry.get(i + 2).substring(0, 19));
            counter += Double.parseDouble(entry.get(i + 1));
        }

        body3 += "\n\nTotal for all orders: $" + counter;

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nOrder by Payment Report\n");
        p.add("Payment Type: " + type + "\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body3);
        document.add(p);

        document.close();
        file.close();

        body3 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderItem(String ordernum, ArrayList<String> entry) {
    try {//from  w ww. java2  s .c  om
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\OrderReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body4 = String.format("%5s  %27s  %10s\n", "Item Name", "Base Price", "Log Total");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 3) {
            body4 += String.format("%-10s %15s %12s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2));
            counter += Double.parseDouble(entry.get(i + 2));
        }

        body4 += "\n\nTotal for all orders: $" + counter;

        p.add(new Date().toString());
        p.add("\n\nItems on Order Report\n");
        p.add("Order Number: " + ordernum + "\n\n");

        p.add(body4);
        document.add(p);

        document.close();
        file.close();

        body4 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:Controlador.ControladorCrearPase.java

public void generaPDF(String Prueba, String Causa, Integer idCita, Integer idPaciente, Integer idPersona)
        throws FileNotFoundException, DocumentException, IOException {

    Calendar cal = Calendar.getInstance();
    String time = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(cal.getTime());
    String timename = new SimpleDateFormat("yyyyMMddHHmm").format(cal.getTime());

    File file = new File("PaseServicio" + timename + ".pdf");
    FileOutputStream fileout = new FileOutputStream(file);
    Document document = new Document();
    PdfWriter writer;/*  www. ja v a  2  s  . c  o m*/
    writer = PdfWriter.getInstance(document, fileout);

    Font fuente = new Font();
    Font fuente2 = new Font();
    Font fuente3 = new Font();

    // fuente.setColor(BaseColor.BLUE);
    fuente.setStyle(Font.UNDERLINE | Font.BOLDITALIC);
    fuente2.setStyle(Font.BOLD);
    fuente2.setSize(12);
    fuente3.setSize(20);
    fuente3.setStyle(Font.BOLD);

    document.open();
    document.add(new Paragraph("\n \n \n \n \n"));
    document.add(new Paragraph("Clinica Mdica INFTEL", fuente3));

    String imageUrl = "src/Imagen/logo.png";
    //  String imagen="src\Imagen\logo.png"; 
    Image image = Image.getInstance(imageUrl);
    image.setAbsolutePosition(300, 750);
    image.scalePercent(80f);
    document.add(image);

    document.add(new Paragraph(" "));
    document.add(new Paragraph("---------------------"));

    document.add(new Paragraph("DATOS DEL PACIENTE", fuente));
    document.add(new Paragraph(" "));
    document.add(
            new Paragraph("Apellidos y Nombre : " + paciente.getApellidos() + ", " + paciente.getNombre()));
    document.add(new Paragraph("NIF : " + paciente.getNif()));
    document.add(new Paragraph("NSS : " + paciente.getNumSS()));
    document.add(new Paragraph("Direccion : " + paciente.getDireccion()));
    document.add(new Paragraph("Telefono : " + paciente.getTelefono()));
    document.add(new Paragraph("Email : " + paciente.getEmail()));
    document.add(new Paragraph("ID Paciente : " + idPaciente));

    document.add(new Paragraph(" "));
    document.add(new Paragraph("---------------------"));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("DATOS ", fuente));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Prueba : ", fuente2));
    document.add(new Paragraph(Prueba));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Causa : ", fuente2));
    document.add(new Paragraph(Causa));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    absText(writer, time, 450, 50);

    document.close();
    File myfile = new File("PaseServicio" + timename + ".pdf");
    Desktop.getDesktop().open(myfile);
}

From source file:controller.PlanController.java

public Document PrintPressed(String Path) throws DocumentException, IOException {
    // step 1//w  w  w .j  av a 2  s  .  c  o  m
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(Path));
    // step 3
    document.open();
    // step 4
    PdfPTable tablaDatosPlan = new PdfPTable(2);

    tablaDatosPlan.setWidthPercentage(100);

    if (!Team.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Team") + ":" + Team.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!Season.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Season") + ":" + Season.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!Date.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Date") + ":" + Date.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!Players.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Players") + ":" + Players.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!Start.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Start") + ":" + Start.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!End.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("End") + ":" + End.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!Place.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Place") + ":" + Place.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }
    if (!Equipment.getText().isEmpty()) {
        PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Equipment") + ":" + Equipment.getText()));
        cell1.setBorderColor(BaseColor.WHITE);
        tablaDatosPlan.addCell(cell1);
    }

    document.add(tablaDatosPlan);

    document.add(new Phrase("\n"));
    document.add(new Phrase("\n"));

    PdfPTable tablaEjercicios = new PdfPTable(4);
    tablaEjercicios.setHeaderRows(contadorlineas);
    tablaEjercicios.addCell(messages.getString("Start"));
    tablaEjercicios.addCell(messages.getString("End"));
    tablaEjercicios.addCell(messages.getString("Drill"));
    tablaEjercicios.addCell(messages.getString("Notes"));
    int cont = 0;
    for (int aw = 4; aw < contadorlineas + 4; aw++) {

        tablaEjercicios.addCell(starColumn.getCellData(cont));
        tablaEjercicios.addCell(endColumn.getCellData(cont));
        tablaEjercicios.addCell(drillColumn.getCellData(cont));
        tablaEjercicios.addCell(notesColumn.getCellData(cont));
        cont++;
    }

    document.add(tablaEjercicios);
    int contadorListado = 0, contadorRecorrer = 0;

    if (checkboxDrills.isSelected()) {

        while (contadorListado < planData.size()) {
            contadorRecorrer = 0;

            while (contadorRecorrer < playData.size()) {
                System.out.println("Busco el ejercicio " + drillColumn.getCellData(contadorListado));
                if (drillColumn.getCellData(contadorListado)
                        .contains(playData.get(contadorRecorrer).getNombreJugada())) {
                    int contador = 1;
                    System.out.println("Ejercicio encontrado");
                    document.add(new Paragraph(
                            messages.getString("Drill") + " " + drillColumn.getCellData(contadorListado)));
                    while (contador < playData.get(contadorRecorrer).getContadorJugada() + 1) {

                        document.add(new Paragraph(messages.getString("Diagram") + " " + contador));
                        document.add(new Paragraph(" "));

                        Image image2 = Image.getInstance(playData.get(contadorRecorrer).getNombreJugada() + "-"
                                + playData.get(contadorRecorrer).getTipoJugada() + "-"
                                + playData.get(contadorRecorrer).getSubtipoJugada() + "_" + contador);
                        image2.scalePercent(50);

                        PdfPTable table1 = new PdfPTable(2);

                        table1.addCell(image2);
                        table1.addCell(
                                textPdf.textPdf(contador, playData.get(contadorRecorrer).getDescripcionJugada(),
                                        playData.get(contadorRecorrer).getContadorJugada()));
                        document.add(table1);

                        contador++;

                    }

                }
                contadorRecorrer++;

            }
            contadorListado++;
        }

    }
    // step 5
    document.close();
    return document;

}

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);

    StringBuilder htmlString = new StringBuilder();
    htmlString.append(kopf);/* ww w  . jav a2s .  c o m*/
    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;
}