Example usage for com.itextpdf.text Image scaleAbsolute

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

Introduction

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

Prototype

public void scaleAbsolute(final float newWidth, final float newHeight) 

Source Link

Document

Scale the image to an absolute width and an absolute height.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java

License:Open Source License

private void createImage(Document document, PdfWriter writer, Font featureHeaderStyle)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    Image imageSprite = Image.getInstance(new URL(
            "http://lh3.ggpht.com/_4msVPAgKJv8/SCRYD-pPVKI/AAAAAAAAAYU/zUN963EPoZc/s1024/102_0609.JPG"));
    imageSprite.setAbsolutePosition(400, 500);
    imageSprite.scaleAbsolute(171.0f, 250.0f);
    float imageSpriteY = document.getPageSize().getHeight() * 0.60f;
    float imageSpriteX = document.getPageSize().getWidth() * 0.65f;
    imageSprite.setAlignment(Image.UNDERLYING);

    document.add(imageSprite);/*from  w  w  w .j  a va  2s . c o m*/

    PdfContentByte cb = writer.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    Chunk imageHeader = new Chunk("Images", featureHeaderStyle);
    ct.addText(imageHeader);
    ct.setAlignment(Element.ALIGN_LEFT);
    ct.setSimpleColumn(imageSpriteX, imageSpriteY - imageSprite.getScaledHeight(),
            imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY + imageSprite.getScaledHeight() + 20);
    ct.go();

    ct = new ColumnText(cb);
    Chunk imageFooter = new Chunk("Footer to be set for a figure. Similar to 'image cpation'.",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8));
    ct.addText(imageFooter);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.setSimpleColumn(imageSpriteX, imageSpriteY - 150, imageSpriteX + imageSprite.getScaledWidth(),
            imageSpriteY);
    ct.go();
}

From source file:Evento.action.ZapisDoPdfAction.java

License:Apache License

public void createPDF(String[] imgURL, String place, String album) throws DocumentException {
    Document document = new Document();
    Rectangle pageSize = new Rectangle(szerokosc, wysokosc);
    document.setPageSize(pageSize);//  w  w w.  j  a  va2 s . c  o  m

    try {

        PdfWriter.getInstance(document, new FileOutputStream(new File(place, "nowy.pdf")));
        document.open();

        Image tlo = Image.getInstance(new URL(zdjecieTla));
        tlo.setAbsolutePosition(0f, 0f);
        document.add(tlo);
        Paragraph preface = new Paragraph(album,
                new Font(FontFamily.HELVETICA, 72, Font.BOLDITALIC, new BaseColor(255, 255, 255)));
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);
        document.newPage();
        for (int i = 0; i < imgURL.length; i++) {

            Image tlo2 = Image.getInstance(new URL(zdjecieTla));
            tlo2.setAbsolutePosition(0f, 0f);
            document.add(tlo2);
            Image image2 = Image.getInstance(new URL(imgURL[i]));
            if (szerokosc * 1.5f <= image2.getWidth() || wysokosc * 1.5f <= image2.getHeight()) {
                image2.scaleAbsolute(image2.getWidth() * 0.25f, image2.getHeight() * 0.25f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.25f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 0.25f) / 2);
            } else if ((szerokosc * 0.8f <= image2.getWidth() || wysokosc * 0.8f <= image2.getHeight())
                    && (szerokosc * 1.2f >= image2.getWidth() || wysokosc * 1.2f >= image2.getHeight())) {
                image2.scaleAbsolute(image2.getWidth() * 0.8f, image2.getHeight() * 0.8f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.8f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 0.8f) / 2);
            } else if ((szerokosc * 0.4f >= image2.getWidth() || wysokosc * 0.4f >= image2.getHeight())
                    && (szerokosc * 0.7f <= image2.getWidth() || wysokosc * 0.7f <= image2.getHeight())) {
                image2.scaleAbsolute(image2.getWidth() * 1.4f, image2.getHeight() * 1.4f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 1.4f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 1.4f) / 2);
            } else {
                image2.scaleAbsolute(image2.getWidth(), image2.getHeight());
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth()) / 2,
                        wysokosc / 2 - (image2.getHeight()) / 2);
            }
            for (int k = 0; k <= 1000; k++)
                ;
            for (int j = 0; j <= 1000; j++)
                ;
            document.add(image2);
            document.newPage();
        }

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:eyeofthetiger.utils.PDFDossardGenerator.java

public void createPdf(List<Participant> participants, OutputStream out) throws IOException, DocumentException {
    sortParticipants(participants);//from   w ww.ja v  a  2s  .  c  o m

    Document document = new Document(PageSize.A4.rotate());
    float margin = CentimeterToUserSpace(marginCm);
    document.setMargins(margin, margin, margin, margin);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    PdfReader pdfBackgroundReader = null;
    PdfImportedPage backgroundPage = null;
    if (pdfBackground != null && (new File(pdfBackground)).exists() && (new File(pdfBackground)).isFile()) {
        pdfBackgroundReader = new PdfReader(pdfBackground);
        backgroundPage = writer.getImportedPage(pdfBackgroundReader, 1);
    }

    float documentTop = document.top();
    float documentBottom = document.bottom();
    float documentHeight = documentTop - documentBottom;
    float left = document.left();
    float right = document.right();
    float width = right - left;
    float height = documentTop - documentBottom;

    //cb.rectangle(left, documentBottom, width, documentHeight);
    //cb.stroke();

    boolean logoLeftExist = (new File(logoLeft)).exists() && (new File(logoLeft)).isFile();
    boolean logoRightExist = (new File(logoRight)).exists() && (new File(logoRight)).isFile();

    float imgLeftRight = left;
    float imgLeftBottom = documentTop;
    float imgRightLeft = right;
    float imgRighBottom = documentTop;
    Image imgLeft = null;
    Image imgRight = null;
    if (exportLogos) {
        if (logoLeftExist) {
            imgLeft = Image.getInstance(logoLeft);
            float h = imgLeft.getHeight();
            float w = imgLeft.getWidth();
            float nw = width * logoLeftWidth;
            float nh = (h / w) * nw;
            imgLeft.scaleAbsolute(nw, nh);
            //img.scaleAbsoluteHeight(img.getScaledWidth() / xyRatio);
            imgLeft.setAbsolutePosition(left, documentTop - imgLeft.getScaledHeight());
            //cb.addImage(img);   

            imgLeftRight = imgLeft.getAbsoluteX() + imgLeft.getScaledWidth();
            imgLeftBottom = imgLeft.getAbsoluteY();
        }

        if (logoRightExist) {
            imgRight = Image.getInstance(logoRight);
            float h = imgRight.getHeight();
            float w = imgRight.getWidth();
            float nw = width * logoRightWidth;
            float nh = (h / w) * nw;
            imgRight.scaleAbsolute(nw, nh);
            imgRight.setAbsolutePosition(right - imgRight.getScaledWidth(),
                    documentTop - imgRight.getScaledHeight());
            //cb.addImage(imgRight);
            imgRightLeft = imgRight.getAbsoluteX();
            imgRighBottom = imgRight.getAbsoluteY();
        }

    }

    float nameHeightPercent = 0.35f;
    float groupHeightPercent = 0.25f;

    float nameTop = documentTop;
    float nameBottom = nameTop;
    if (exportName) {
        nameBottom = nameTop - (documentHeight * nameHeightPercent);
    }
    float groupeTop = nameBottom;
    float groupeBottom = nameBottom;
    if (exportGroup) {
        groupeBottom = groupeTop - (documentHeight * groupHeightPercent);
    }
    float barcodeTop = groupeBottom;
    float barcodeBottom = documentBottom;

    ColumnText columnText;

    for (Participant participant : participants) {

        if (backgroundPage != null) {
            //cb.addTemplate(backgroundPage, 1f, 0, 0, 1, 0, 0); //TODO
            cb.addTemplate(backgroundPage, 0, 0);
        }

        float nameFontSize = 65f;
        float groupFontSize = 45f;
        float renseignementFontSize = 35f;

        if (imgLeft != null) {
            cb.addImage(imgLeft);
        }
        if (imgRight != null) {
            cb.addImage(imgRight);
        }

        if (exportName) {
            columnText = new ColumnText(cb);
            columnText.setAlignment(Rectangle.ALIGN_CENTER);

            if (imgLeftRight != -1 && imgLeftBottom != -1) {
                float[] leftBorder = null;
                if (imgLeftBottom < nameBottom) {
                    leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, nameBottom, left,
                            nameBottom };
                } else {
                    leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, imgLeftBottom, left,
                            imgLeftBottom, left, nameBottom };
                }

                float[] rightBorder = null;
                if (imgRighBottom < nameBottom) {
                    rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, nameBottom, right,
                            nameBottom };
                } else {
                    rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, imgRighBottom, right,
                            imgRighBottom, right, nameBottom };
                }

                columnText.setColumns(leftBorder, rightBorder);
            } else {
                columnText.setSimpleColumn(left, nameTop, right, nameBottom);
            }
            //cb.rectangle(left, nameBottom, width, (nameTop - nameBottom));
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);

            String txt = participant.getNom().toUpperCase() + " " + participant.getPrenom();

            float previousPos = columnText.getYLine();
            columnText.setLeading(nameFontSize);
            columnText.setText(createCleanPhrase(txt, nameFontSize, true));
            while (nameFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) {
                nameFontSize = nameFontSize - 0.5f;
                columnText.setLeading(nameFontSize);
                columnText.setText(createCleanPhrase(txt, nameFontSize, true));
                columnText.setYLine(previousPos);
            }

            columnText.setLeading(nameFontSize);
            columnText.setText(createCleanPhrase(txt, nameFontSize, true));
            columnText.setYLine(previousPos);
            columnText.go(false);

        }

        if (exportGroup) {
            columnText = new ColumnText(cb);
            columnText.setAlignment(Rectangle.ALIGN_CENTER);

            columnText.setSimpleColumn(document.left(), groupeTop, document.right(), groupeBottom);
            float groupeHeight = groupeTop - groupeBottom;
            //cb.rectangle(document.left(), groupeTop - groupeHeight, document.right() - document.left(), groupeHeight);
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);
            columnText.setFollowingIndent(0);

            String txt1 = participant.getGroupe();
            String txt2 = exportRenseignement ? "\n" + participant.getRenseignements() : null;

            float previousPos = columnText.getYLine();
            columnText.setText(null);
            columnText.setLeading(groupFontSize);
            columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
            columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
            while (groupFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) {
                groupFontSize = groupFontSize - 0.5f;
                renseignementFontSize = renseignementFontSize - 0.5f;
                columnText.setText(null);
                columnText.setLeading(groupFontSize);
                columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
                columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
                columnText.setYLine(previousPos);
            }

            columnText.setText(null);
            columnText.setLeading(groupFontSize);
            columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
            columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
            columnText.setYLine(previousPos);
            columnText.go(false);
        }

        {
            columnText = new ColumnText(cb);

            float topMargin = 12f;
            columnText.setSimpleColumn(left, barcodeTop - topMargin, right, barcodeBottom);
            float barcodeHeight = (barcodeTop - topMargin) - barcodeBottom;
            //cb.rectangle(left, barcodeTop - barcodeHeight, width, barcodeHeight);
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);

            float previousPos = columnText.getYLine();
            columnText.setText(null);
            columnText.addElement(createCleanBarcode(cb, participant.getNumero(), width, barcodeHeight));
            columnText.go(false);
        }

        document.newPage();

    }

    document.close();

    if (pdfBackgroundReader != null) {
        pdfBackgroundReader.close();
    }
}

From source file:gde.report.pdf.ITextInlineImageReplacedElementFactory.java

License:Open Source License

@Override
public ReplacedElement createReplacedElement(final LayoutContext c, final BlockBox box,
        final UserAgentCallback uac, final int cssWidth, final int cssHeight) {
    final Element elem = box.getElement();

    // check if we have an inline png image
    if (!(elem != null && elem.getNodeName().equals("img") && elem.hasAttribute("src") //$NON-NLS-1$//$NON-NLS-2$
            && elem.getAttribute("src").startsWith(PREFIX))) { //$NON-NLS-1$
        return null; // other.createReplacedElement(c, box, uac, cssWidth,
                     // cssHeight);
    }/*from w  w w .  ja v  a  2  s  . c  o  m*/

    int width = 0;
    int height = 0;

    if (cssWidth > 0) {
        width = cssWidth;
    }
    if (cssHeight > 0) {
        height = cssHeight;
    }

    if (elem.hasAttribute("width")) { //$NON-NLS-1$
        width = Integer.parseInt(elem.getAttribute("width")); //$NON-NLS-1$
    }

    if (elem.hasAttribute("height")) { //$NON-NLS-1$
        height = Integer.parseInt(elem.getAttribute("height")); //$NON-NLS-1$
    }

    final String inlineData = elem.getAttribute("src").substring(PREFIX.length()); // strip //$NON-NLS-1$
                                                                                   // leading
                                                                                   // "data:image/png;base64,"

    try {
        final Image image = Image.getInstance(Base64.decode(inlineData));

        if (width == 0) {
            width = (int) image.getWidth();
        }

        if (height == 0) {
            height = (int) image.getHeight();
        }

        image.scaleAbsolute(width * 16, height * 16);

        final ITextFSImage fsImage = new ITextFSImage(image);
        final ITextReplacedElement element = new ITextImageElement(fsImage);
        return element;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:gestionsessions.FenSession.java

private void jTableGestionSessionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableGestionSessionMouseClicked
    Document document = new Document();
    String req;//from  w  w  w.  ja v a 2 s . c o m
    int nbLignes = 0;
    // Creation d'une PdfPTable avec 5 colonnes
    final PdfPTable table = new PdfPTable(5);
    try {
        PdfWriter.getInstance(document,
                new FileOutputStream(System.getProperty("user.dir") + "//listeEmargementSession.pdf"));
        document.open();
        //en tte du pdf
        Image logo = Image.getInstance("logo.png");
        logo.scaleAbsolute(120f, 67f);
        document.add(logo);
        //on indique la marge
        document.add(new Phrase("\n\n\nMarge dgage par la session: "
                + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 9).toString()
                + ""));
        document.add(new Phrase("\n\nListe d'margement de la session "));
        document.add(new Phrase(
                jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 0).toString()));
        document.add(new Phrase(
                " / " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 1).toString()));
        document.add(new Phrase(
                " / " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 2).toString()));
        document.add(new Phrase(" / "
                + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 3).toString() + ":"));
        // Ajout d'un espace entre la PdfPTable et l'lment prcdent.
        table.setSpacingBefore(15f);
        //requte pour les personnes inscrites
        stmt1 = GestionBdd.connexionBdd(GestionBdd.TYPE_MYSQL, "formarmor", "localhost", "root", "");
        req = "Select c.* from client c, inscription i where c.id = i.client_id and i.session_formation_id = "
                + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 0).toString();
        ResultSet rs1 = GestionBdd.envoiRequeteLMD(stmt1, req);
        // Ajout d'une entte pour PdfPTable
        table.addCell("Matricule");
        table.addCell("Nom");
        table.addCell("Rue");
        table.addCell("Code Postal");
        table.addCell("Ville");
        // Ajout d'un espace entre la PdfPTable et l'lment prcdent.
        table.setSpacingBefore(15f);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        //change taille colonnes
        table.setWidths(new int[] { 5, 10, 14, 6, 8 });
        while (rs1.next()) {
            // Ajout d'objets String  la PdfPTable
            table.addCell(rs1.getString(1));
            table.addCell(rs1.getString(3));
            table.addCell(rs1.getString(5));
            table.addCell(rs1.getString(6));
            table.addCell(rs1.getString(7));
            // Ajout d'un espace entre la PdfPTable et l'lment prcdent.
            table.setSpacingBefore(15f);
            nbLignes++;
        }
        //cas ou il n'y a personne d'inscrit
        if (nbLignes == 0) {
            JOptionPane.showMessageDialog(null, "Il n'y a personne d'inscrits");
            document.add(new Phrase("\n\nIl n'y a personne d'inscrits"));
        } else {
            document.add(table);
            //ouvre le fichier listeEmargementSession.pdf avec le logiciel de lecture pdf par dfaut 
            Runtime r = Runtime.getRuntime();
            r.exec(new String[] { "cmd.exe", "/C",
                    System.getProperty("user.dir") + "//listeEmargementSession.pdf" });
        }
        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException ex) {
        Logger.getLogger(FenSession.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(FenSession.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:GestoSAT.Albaran.java

License:Open Source License

public String albaran2PDF(int id) {
    try {/*from www . j a  v  a2  s. co m*/
        String arch = "Albaran" + (new Date()).getTime() + ".pdf";
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch));
        DecimalFormat df = new DecimalFormat("0.00");

        doc.open();
        File f = new File("logo");
        if (f.exists()) {
            Image img = Image.getInstance("logo");
            img.setAbsolutePosition(50, 735);
            img.scaleAbsolute(50, 50);
            doc.add(img);
            Paragraph p = new Paragraph(" ");
            p.setLeading((float) 75);
            doc.add(p);
        }
        doc.add(new Paragraph("ALBAR?N"));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos empresa"));
        Oficina ofi = this.getGestoSAT().getEmpleado().getOficina();
        doc.add(new Paragraph(
                ofi.getProvincia() + " " + ofi.getPoblacion() + " " + ofi.getCalle() + " " + ofi.getNumero()));
        doc.add(new Paragraph(ofi.getNombre()));
        doc.add(new Paragraph("NIF: " + ofi.getNif()));
        doc.add(new Paragraph("Tlf: " + ofi.getTlfFijo() + " " + ofi.getTlfMovil()));
        doc.add(new Paragraph("Fax: " + ofi.getFax()));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos de inters"));
        doc.add(new Paragraph(
                "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos()));
        doc.add(new Paragraph("Concepto: " + this.concepto));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Lugar de entrga:" + this.provincia + " " + this.poblacion + " " + this.calle
                + " " + this.escalera + " " + this.piso + " " + this.puerta));

        doc.add(new Paragraph(" "));

        float auxPrecio = 0;
        PdfPTable table = new PdfPTable(5);

        table.addCell("#");
        table.addCell("Nombre");
        table.addCell("Precio Ud / H");
        table.addCell("Uds / H");
        table.addCell("Total");

        Iterator itTabla = this.materialUtilizado.entrySet().iterator();
        while (itTabla.hasNext()) {
            Map.Entry aux = (Map.Entry) itTabla.next();
            table.addCell(aux.getKey().toString());
            table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getNombre());
            table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad() + "");
            table.addCell(((MaterialTrabajos) aux.getValue()).getCantidad() + "");
            auxPrecio += ((MaterialTrabajos) aux.getValue()).getCantidad()
                    * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad();
            table.addCell((((MaterialTrabajos) aux.getValue()).getCantidad()
                    * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad()) + "");
        }

        itTabla = this.trabajoRealizado.entrySet().iterator();
        while (itTabla.hasNext()) {
            Map.Entry aux = (Map.Entry) itTabla.next();
            table.addCell("*");
            Trabajo tra = (Trabajo) aux.getValue();
            table.addCell(tra.getEmpleado().getNombre() + " " + tra.getEmpleado().getApellidos());
            table.addCell(tra.getEmpleado().getPrecioHora() + "");
            table.addCell(tra.getHoras() + "");
            auxPrecio += tra.getEmpleado().getPrecioHora() * tra.getHoras();
            table.addCell((tra.getEmpleado().getPrecioHora() * tra.getHoras()) + "");
        }
        doc.add(table);
        doc.add(new Paragraph("I.V.A: " + this.getGestoSAT().getIva() + "%"));
        doc.add(new Paragraph(
                "Total I.V.A: " + df.format((this.getGestoSAT().getIva() / (float) 100) * auxPrecio)));
        doc.add(new Paragraph(
                "Total: " + df.format(((this.getGestoSAT().getIva() / (float) 100) + 1) * auxPrecio)));

        doc.close();
        if (this.fchEntrega == null) {
            this.fchEntrega = new Date();
            if (this.getGestoSAT().entregaAlbaran(id, this))
                return "descargables/" + arch;
            else
                return "";
        } else
            return "descargables/" + arch;

    } catch (IOException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (BadElementException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (DocumentException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}

From source file:GestoSAT.Entrada.java

License:Open Source License

public String entrada2PDF() {
    try {/*from  w  w w.ja va2 s  .  c o m*/
        String arch = "Entrada" + (new Date()).getTime() + ".pdf";
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch));
        doc.open();
        File f = new File("logo");

        // http://www.java2s.com/Tutorial/Java/0280__SWT/UseImageDatatocreateanewimage.htm
        if (f.exists()) {
            Image img = Image.getInstance("logo");
            img.setAbsolutePosition(50, 735);
            img.scaleAbsolute(50, 50);
            doc.add(img);
            Paragraph p = new Paragraph(" ");
            p.setLeading((float) 75);
            doc.add(p);
        }
        doc.add(new Paragraph(
                "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos()));
        if (this.incidencia.getClass().getName().equals("GestoSAT.Averia")) {
            doc.add(new Paragraph(" "));
            doc.add(new Paragraph("APARATO"));
            doc.add(new Paragraph(" "));
            Averia av = (Averia) this.incidencia;
            doc.add(new Paragraph("Problema: " + av.getMotivo()));
            doc.add(new Paragraph(" "));
            doc.add(new Paragraph("Tipo: " + av.getAparato().getTipo()));
            doc.add(new Paragraph("Marca: " + av.getAparato().getMarca()));
            doc.add(new Paragraph("Modelo: " + av.getAparato().getModelo()));
            doc.add(new Paragraph("NSerie: " + av.getAparato().getNumSerie()));
            doc.add(new Paragraph("Color: " + av.getAparato().getColor()));
            doc.add(new Paragraph("Observaciones: " + av.getAparato().getObservaciones()));
        } else {
            Cita cita = (Cita) this.incidencia;
            doc.add(new Paragraph(" "));
            doc.add(new Paragraph("CITA"));
            doc.add(new Paragraph("Problema:" + cita.getMotivo()));
            doc.add(new Paragraph(
                    "Direccin:" + cita.getPoblacion() + " " + cita.getCalle() + " " + cita.getNumero() + " "
                            + cita.getEscalera() + " " + cita.getPiso() + " " + cita.getPuerta()));
            doc.add(new Paragraph("Obsevaciones:" + cita.getObservacionesDirrecion()));
            doc.add(new Paragraph(cita.getObservaciones()));
        }
        doc.close();
        return "descargables/" + arch;
    } catch (Exception ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}

From source file:GestoSAT.Factura.java

License:Open Source License

public String factura2PDF() {
    try {//from   w w w  . j  av a  2 s.  c  om
        String arch = "Factura" + (new Date()).getTime() + ".pdf";
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch));
        DecimalFormat df = new DecimalFormat("0.00");

        doc.open();
        File f = new File("logo");
        if (f.exists()) {
            Image img = Image.getInstance("logo");
            img.setAbsolutePosition(50, 735);
            img.scaleAbsolute(50, 50);
            doc.add(img);
            Paragraph p = new Paragraph(" ");
            p.setLeading((float) 75);
            doc.add(p);
        }
        doc.add(new Paragraph("FACTURA"));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos empresa"));
        Oficina ofi = this.getGestoSAT().getEmpleado().getOficina();
        doc.add(new Paragraph(
                ofi.getProvincia() + " " + ofi.getPoblacion() + " " + ofi.getCalle() + " " + ofi.getNumero()));
        doc.add(new Paragraph(ofi.getNombre()));
        doc.add(new Paragraph("NIF: " + ofi.getNif()));
        doc.add(new Paragraph("Tlf: " + ofi.getTlfFijo() + " " + ofi.getTlfMovil()));
        doc.add(new Paragraph("Fax: " + ofi.getFax()));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos de inters"));
        doc.add(new Paragraph(
                "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos()));
        doc.add(new Paragraph("Concepto: " + this.concepto));
        doc.add(new Paragraph("Forma pago: " + this.formaPago));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Albaranes"));

        Iterator itAlbaranes = this.albaran.entrySet().iterator();
        while (itAlbaranes.hasNext()) {
            Map.Entry auxAlbaranes = (Map.Entry) itAlbaranes.next();
            // Leer albaranes
            float auxPrecio = 0;
            PdfPTable table = new PdfPTable(5);

            table.addCell("#");
            table.addCell("Nombre");
            table.addCell("Precio Ud / H");
            table.addCell("Uds / H");
            table.addCell("Total");

            Iterator itTabla = ((Albaran) auxAlbaranes.getValue()).getMaterialUtilizado().entrySet().iterator();
            while (itTabla.hasNext()) {
                Map.Entry aux = (Map.Entry) itTabla.next();
                table.addCell(aux.getKey().toString());
                table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getNombre());
                table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad() + "");
                table.addCell(((MaterialTrabajos) aux.getValue()).getCantidad() + "");
                auxPrecio += ((MaterialTrabajos) aux.getValue()).getCantidad()
                        * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad();
                table.addCell((((MaterialTrabajos) aux.getValue()).getCantidad()
                        * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad()) + "");
            }

            itTabla = ((Albaran) auxAlbaranes.getValue()).getTrabajoRealizado().entrySet().iterator();
            while (itTabla.hasNext()) {
                Map.Entry aux = (Map.Entry) itTabla.next();
                table.addCell("*");
                Trabajo tra = (Trabajo) aux.getValue();
                table.addCell(tra.getEmpleado().getNombre() + " " + tra.getEmpleado().getApellidos());
                table.addCell(tra.getEmpleado().getPrecioHora() + "");
                table.addCell(tra.getHoras() + "");
                auxPrecio += tra.getEmpleado().getPrecioHora() * tra.getHoras();
                table.addCell((tra.getEmpleado().getPrecioHora() * tra.getHoras()) + "");
            }
            doc.add(table);
            doc.add(new Paragraph("I.V.A: " + this.getGestoSAT().getIva() + "%"));
            doc.add(new Paragraph(
                    "Total I.V.A: " + df.format((this.getGestoSAT().getIva() / (float) 100) * auxPrecio)));
            doc.add(new Paragraph(
                    "Total: " + df.format(((this.getGestoSAT().getIva() / (float) 100) + 1) * auxPrecio)));
            doc.add(new Paragraph(" "));
        }

        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Tota factura: " + df.format(this.total)));

        doc.close();
        return "descargables/" + arch;
    } catch (IOException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (BadElementException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (DocumentException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}

From source file:GestoSAT.Presupuesto.java

License:Open Source License

public String presupuesto2PDF() {
    try {/*  w  w w. ja  v a 2 s.  c o m*/
        String arch = "Presupeusto" + (new Date()).getTime() + ".pdf";
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch));
        DecimalFormat df = new DecimalFormat("0.00");

        doc.open();
        File f = new File("logo");
        if (f.exists()) {
            Image img = Image.getInstance("logo");
            img.setAbsolutePosition(50, 735);
            img.scaleAbsolute(50, 50);
            doc.add(img);
            Paragraph p = new Paragraph(" ");
            p.setLeading((float) 75);
            doc.add(p);
        }
        doc.add(new Paragraph("PRESUPUESTO"));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos empresa"));
        Oficina ofi = this.getGestoSAT().getEmpleado().getOficina();
        doc.add(new Paragraph(
                ofi.getProvincia() + " " + ofi.getPoblacion() + " " + ofi.getCalle() + " " + ofi.getNumero()));
        doc.add(new Paragraph(ofi.getNombre()));
        doc.add(new Paragraph("NIF: " + ofi.getNif()));
        doc.add(new Paragraph("Tlf: " + ofi.getTlfFijo() + " " + ofi.getTlfMovil()));
        doc.add(new Paragraph("Fax: " + ofi.getFax()));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos de inters"));
        doc.add(new Paragraph(
                "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos()));
        doc.add(new Paragraph("Concepto: " + this.concepto));
        doc.add(new Paragraph("Fecha validez: " + this.validez));
        if (this.aceptado)
            doc.add(new Paragraph("Aceptado: SI"));
        else
            doc.add(new Paragraph("Aceptado: NO"));
        doc.add(new Paragraph("Adelanto: " + this.adelanto));
        doc.add(new Paragraph("Forma pago: " + this.formaPago));
        doc.add(new Paragraph("Tiempo estimado: " + this.plazo));
        doc.add(new Paragraph("Condiciones: " + this.condiciones));
        doc.add(new Paragraph("Seguro: " + this.seguro));
        doc.add(new Paragraph("Garantia: " + this.garantia));
        doc.add(new Paragraph(" "));

        float auxPrecio = 0;
        PdfPTable table = new PdfPTable(5);

        table.addCell("#");
        table.addCell("Nombre");
        table.addCell("Precio Ud / H");
        table.addCell("Uds / H");
        table.addCell("Total");

        Iterator itTabla = this.materialPresupuestado.entrySet().iterator();
        while (itTabla.hasNext()) {
            Map.Entry aux = (Map.Entry) itTabla.next();
            table.addCell(aux.getKey().toString());
            table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getNombre());
            table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad() + "");
            table.addCell(((MaterialTrabajos) aux.getValue()).getCantidad() + "");
            auxPrecio += ((MaterialTrabajos) aux.getValue()).getCantidad()
                    * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad();
            table.addCell((((MaterialTrabajos) aux.getValue()).getCantidad()
                    * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad()) + "");
        }

        itTabla = this.trabajoPresupuestado.entrySet().iterator();
        while (itTabla.hasNext()) {
            Map.Entry aux = (Map.Entry) itTabla.next();
            table.addCell("*");
            Trabajo tra = (Trabajo) aux.getValue();
            table.addCell(tra.getEmpleado().getNombre() + " " + tra.getEmpleado().getApellidos());
            table.addCell(tra.getEmpleado().getPrecioHora() + "");
            table.addCell(tra.getHoras() + "");
            auxPrecio += tra.getEmpleado().getPrecioHora() * tra.getHoras();
            table.addCell((tra.getEmpleado().getPrecioHora() * tra.getHoras()) + "");
        }
        doc.add(table);
        doc.add(new Paragraph("I.V.A: " + this.getGestoSAT().getIva() + "%"));
        doc.add(new Paragraph(
                "Total I.V.A: " + df.format((this.getGestoSAT().getIva() / (float) 100) * auxPrecio)));
        doc.add(new Paragraph(
                "Total: " + df.format((this.getGestoSAT().getIva() / (float) 100 + 1) * auxPrecio)));

        doc.close();
        return "descargables/" + arch;
    } catch (IOException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (BadElementException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (DocumentException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}

From source file:GestoSAT.Recibo.java

License:Open Source License

public String recibo2PDF() {
    try {//from  ww w . j  av  a2 s .co m
        String arch = "Recibo" + (new Date()).getTime() + ".pdf";
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream("/TomEE/webapps/ROOT/descargables/" + arch));
        DecimalFormat df = new DecimalFormat("0.00");

        doc.open();
        File f = new File("logo");
        if (f.exists()) {
            Image img = Image.getInstance("logo");
            img.setAbsolutePosition(50, 735);
            img.scaleAbsolute(50, 50);
            doc.add(img);
            Paragraph p = new Paragraph(" ");
            p.setLeading((float) 75);
            doc.add(p);
        }
        doc.add(new Paragraph("Recibo"));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos empresa"));
        Oficina ofi = this.getGestoSAT().getEmpleado().getOficina();
        doc.add(new Paragraph(
                ofi.getProvincia() + " " + ofi.getPoblacion() + " " + ofi.getCalle() + " " + ofi.getNumero()));
        doc.add(new Paragraph("NIF: " + ofi.getNif()));
        doc.add(new Paragraph("Tlf: " + ofi.getTlfFijo() + " " + ofi.getTlfMovil()));
        doc.add(new Paragraph("Fax: " + ofi.getFax()));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Datos de inters"));
        doc.add(new Paragraph(
                "Cliente: " + this.getCliente().getNombre() + " " + this.getCliente().getApellidos()));
        doc.add(new Paragraph("Concepto: " + this.factura.getConcepto()));
        doc.add(new Paragraph("Lugar de entrga: " + this.provincia + " " + this.poblacion + " " + this.calle
                + " " + this.escalera + " " + this.piso + " " + this.puerta));
        doc.add(new Paragraph("Albaranes "));

        doc.add(new Paragraph(" "));

        Iterator itAlbaranes = this.factura.getAlbaranes().entrySet().iterator();
        while (itAlbaranes.hasNext()) {
            Map.Entry auxAlbaranes = (Map.Entry) itAlbaranes.next();
            // Leer albaranes
            float auxPrecio = 0;
            PdfPTable table = new PdfPTable(5);

            table.addCell("#");
            table.addCell("Nombre");
            table.addCell("Precio Ud / H");
            table.addCell("Uds / H");
            table.addCell("Total");

            Iterator itTabla = ((Albaran) auxAlbaranes.getValue()).getMaterialUtilizado().entrySet().iterator();
            while (itTabla.hasNext()) {
                Map.Entry aux = (Map.Entry) itTabla.next();
                table.addCell(aux.getKey().toString());
                table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getNombre());
                table.addCell(((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad() + "");
                table.addCell(((MaterialTrabajos) aux.getValue()).getCantidad() + "");
                auxPrecio += ((MaterialTrabajos) aux.getValue()).getCantidad()
                        * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad();
                table.addCell((((MaterialTrabajos) aux.getValue()).getCantidad()
                        * ((MaterialTrabajos) aux.getValue()).getStock().getPrecioUnidad()) + "");
            }

            itTabla = ((Albaran) auxAlbaranes.getValue()).getTrabajoRealizado().entrySet().iterator();
            while (itTabla.hasNext()) {
                Map.Entry aux = (Map.Entry) itTabla.next();
                table.addCell("*");
                Trabajo tra = (Trabajo) aux.getValue();
                table.addCell(tra.getEmpleado().getNombre() + " " + tra.getEmpleado().getApellidos());
                table.addCell(tra.getEmpleado().getPrecioHora() + "");
                table.addCell(tra.getHoras() + "");
                auxPrecio += tra.getEmpleado().getPrecioHora() * tra.getHoras();
                table.addCell((tra.getEmpleado().getPrecioHora() * tra.getHoras()) + "");
            }
            doc.add(table);
            doc.add(new Paragraph("I.V.A: " + this.getGestoSAT().getIva() + "%"));
            doc.add(new Paragraph(
                    "Total I.V.A: " + df.format((this.getGestoSAT().getIva() / (float) 100) * auxPrecio)));
            doc.add(new Paragraph(
                    "Total: " + df.format(((this.getGestoSAT().getIva() / (float) 100) + 1) * auxPrecio)));
            doc.add(new Paragraph(" "));
        }

        doc.add(new Paragraph(" "));
        doc.add(new Paragraph("Tota factura: " + df.format(this.factura.getTotal())));

        doc.close();
        return "descargables/" + arch;
    } catch (IOException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (BadElementException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    } catch (DocumentException ex) {
        Logger.getLogger(Entrada.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}