Example usage for org.apache.pdfbox.pdmodel.font PDType0Font load

List of usage examples for org.apache.pdfbox.pdmodel.font PDType0Font load

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.font PDType0Font load.

Prototype

public static PDType0Font load(PDDocument doc, InputStream input) throws IOException 

Source Link

Document

Loads a TTF to be embedded and subset into a document as a Type 0 font.

Usage

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.PDFBoxFont.java

License:EUPL

private PDFont generateTTF(String fonttype, PDFBOXObject pdfObject) throws IOException {

    ttfFontDesc = fonttype;//  w ww .  j a va  2  s  .co  m
    String fontName = fonttype.replaceFirst("TTF:", "");
    String fontPath = this.settings.getWorkingDirectory() + File.separator + "fonts" + File.separator
            + fontName;

    logger.debug("Font from: \"" + fontPath + "\".");

    PDFAsFontCache fontCache = pdfObject.getSigBlockFontCache();

    if (fontCache.contains(fontPath)) {
        logger.debug("Using cached font.");
        return fontCache.getFont(fontPath);
    }

    //      FontInfoCache fontInfo = getFontInfo(fontPath);
    //      
    //      if(fontInfo != null) {
    //      
    //         PDFont font = findCachedFont(pdfObject, fontInfo);
    //
    //         if (font != null) {
    //            return font;
    //         }
    //      } 

    logger.debug("Instantiating new font.");

    /*
          SignatureProfileSettings signatureProfileSettings = TableFactory
    .createProfile(pdfObject.getStatus().getRequestedSignature().getSignatureProfileID(), pdfObject.getStatus().getSettings());
            
          boolean requirePDFA3 = signatureProfileSettings.isPDFA3();
    */
    PDType0Font font = PDType0Font.load(pdfObject.getDocument(), new FileInputStream(fontPath));
    fontCache.addFont(fontPath, font);

    return font;

}

From source file:Bulletin.Bulletin3.java

public Bulletin3(String Path, Periode p, int scale, dataBase myDB) {
    this.headHeight = 100;
    this.document = new myPdf(Path);
    this.myDB = myDB;
    this.P = p;//from  www  .  j av  a 2s  . co  m
    try {
        fontPlain = PDType0Font.load(document.document,
                getClass().getResourceAsStream("/Resources/DejaVuSansCondensed.ttf"));
        fontBold = PDType0Font.load(document.document,
                getClass().getResourceAsStream("/Resources/DejaVuSansCondensed-Bold.ttf"));
    } catch (IOException ex) {
        Logger.getLogger(Bulletin3.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cdiscisa.StreamUtil.java

private static void imprimirDiplomas(ArrayList<Participante> listaParticipantes, Curso c, Directorio d,
            String chkDipFirma, String chkDipLogo, String savePath, Map<String, String> dosc, String instructor,
            Map<String, String> abreviaturas) throws IOException {

        ListIterator<Participante> it = listaParticipantes.listIterator();
        Participante p1 = null;//from   w w  w  .j  av  a  2  s  . c o  m
        Participante p2 = null;
        String abrev_curso = "";

        // Create a document and add a page to it
        PDDocument document = new PDDocument();
        PDDocument documentSingle;

        InputStream file = null;

        BufferedImage logo = null;
        BufferedImage firma = null;

        try {

            //logo = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/logo.png").getFile());
            //logo = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/logo.png");
            logo = ImageIO.read(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/logo.png"));
            //logo = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/logo.png");

            if (instructor.equalsIgnoreCase("Ing. Jorge Antonio Razn Gutierrez")) {
                //firma = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/firmaCoco.png").getFile());
                firma = ImageIO
                        .read(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/firmaCoco.png"));
            } else if (instructor.equalsIgnoreCase("Manuel Anguiano Razn")) {
                firma = ImageIO.read(
                        cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/firmaManuel.png"));
                //firma = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/firmaManuel.png").getFile());
            } else {
                firma = ImageIO
                        .read(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/firmaJorge.png"));
                //firma = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/firmaJorge.png").getFile());
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error al cargar la imagen del logo o la firma \nfile: "
                    + String.valueOf(logo) + "\n" + String.valueOf(firma) + "\n" + ex.toString());
        }

        PDImageXObject firmaObject = null;
        PDImageXObject logoObject = null;

        try {
            if (chkDipLogo.equalsIgnoreCase("true")) {
                //logoObject = PDImageXObject.createFromFile(logo, document);                
                logoObject = LosslessFactory.createFromImage(document, logo);
            }

            if (chkDipFirma.equalsIgnoreCase("true")) {
                // firmaObject = PDImageXObject.createFromFile(firma, document);
                firmaObject = LosslessFactory.createFromImage(document, firma);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error al crear objetos de logo o firma \nfile: "
                    + String.valueOf(logoObject) + "\n" + String.valueOf(firmaObject) + "\n" + ex.toString());
        }

        try {
            file = cdiscisa.Cdiscisa.class.getClassLoader()
                    .getResourceAsStream("files/n_diploma_simple_vacio_nf_nl_nr.pdf");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,
                    "Error al cargar el el diploma single base. \ndiploma: files/n_diploma_simple_vacio_nf_nl_nr.pdf \nfile: "
                            + String.valueOf(file) + "\n" + ex.toString());
        }

        documentSingle = PDDocument.load(file);

        PDPage pageSingle = (PDPage) documentSingle.getDocumentCatalog().getPages().get(0);
        COSDictionary pageDictSingle = pageSingle.getCOSObject();
        COSDictionary newPageSingleDict = new COSDictionary(pageDictSingle);
        PDPage templatePageSingle = new PDPage(newPageSingleDict);

        // Create a document and add a page to it

        PDDocument documentDoble;

        InputStream file2 = null;

        try {
            file2 = cdiscisa.Cdiscisa.class.getClassLoader()
                    .getResourceAsStream("files/n_diploma_doble_vacio_nf_nl_nr.pdf");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,
                    "Error al cargar el el diploma doble base. \ndiploma: n_diploma_doble_vacio_nf_nl_nr.pdf\nfile: "
                            + String.valueOf(file2) + "\n" + ex.toString());
        }

        documentDoble = PDDocument.load(file2);

        PDPage pageDoble = (PDPage) documentDoble.getDocumentCatalog().getPages().get(0);
        COSDictionary pageDobleDict = pageDoble.getCOSObject();
        COSDictionary newPageDobleDict = new COSDictionary(pageDobleDict);

        PDPage templatePageDoble = new PDPage(newPageDobleDict);

        InputStream isFont1 = null, isFont2 = null, isFont3 = null;

        try {
            isFont1 = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/Calibri.ttf");
            isFont2 = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/CalibriBold.ttf");
            isFont3 = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/Pristina.ttf");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,
                    "Error al cargar el una fuente \nisFont1: " + String.valueOf(isFont1) + "\nisFont2: "
                            + String.valueOf(isFont2) + "\nisFont3: " + String.valueOf(isFont3) + "\n"
                            + ex.toString());
        }
        PDFont calibri = null;
        PDFont calibriBold = null;
        PDFont pristina = null;

        calibri = PDType0Font.load(document, isFont1);
        calibriBold = PDType0Font.load(document, isFont2);
        pristina = PDType0Font.load(document, isFont3);

        if (listaParticipantes.size() % 2 == 0 && listaParticipantes.size() >= 2) {

            while (it.hasNext()) {
                p1 = it.next();
                p2 = it.next();

                imprimirDiplomaDoble(p1, p2, c, d, document, templatePageDoble, calibri, calibriBold, pristina,
                        logoObject, firmaObject, instructor);
            }
        } else {
            if (listaParticipantes.size() > 1) {
                //Lista es impar y contiene mas de 2 participantes.
                while (it.hasNext()) {

                    if (it.nextIndex() == listaParticipantes.size() - 1) {
                        p1 = it.next();
                        imprimirDiplomaArriba(p1, c, d, document, templatePageSingle, calibri, calibriBold,
                                pristina, logoObject, firmaObject, instructor);
                        break;
                    }

                    p1 = it.next();
                    p2 = it.next();

                    imprimirDiplomaDoble(p1, p2, c, d, document, templatePageDoble, calibri, calibriBold, pristina,
                            logoObject, firmaObject, instructor);
                }
            } else if (listaParticipantes.size() == 1) {
                p1 = it.next();
                imprimirDiplomaArriba(p1, c, d, document, templatePageSingle, calibri, calibriBold, pristina,
                        logoObject, firmaObject, instructor);
            }

        }

        Format formatter = new SimpleDateFormat("ddMMMYYYY", new Locale("es", "MX"));
        String formatedDate = formatter.format(c.fecha_inicio);

        String abrev = abreviaturas.get(c.nombre_curso);

        if (c.walmart) {
            document.save(savePath + File.separator + "Diplomas_" + d.formato + "_" + d.unidad + "_"
                    + d.determinante + "_" + abrev + "_" + formatedDate + ".pdf");
            document.close();
            dosc.put(savePath + File.separator + "Diplomas_" + d.formato + "_" + d.unidad + "_" + d.determinante
                    + "_" + abrev + "_" + formatedDate + ".pdf", d.determinante);
        } else {
            document.save(savePath + File.separator + "Diplomas_" + d.determinante + "_" + abrev + "_"
                    + formatedDate + ".pdf");
            document.close();
            dosc.put(savePath + File.separator + "Diplomas_" + d.determinante + "_" + abrev + "_" + formatedDate
                    + ".pdf", d.determinante);
        }
    }

From source file:cdiscisa.StreamUtil.java

private static void imprimirUnaConstancia(ArrayList<Participante> listaParticipantes, Curso c, Directorio d,
            String chkConstFirma, String chkConstLogo, String savePath, Map<String, String> dosc, String instructor,
            Map<String, String> abreviaturas) throws IOException {

        String contanciaTemplate = "";

        switch (c.nombre_curso) {
        case "PREVENCIN Y COMBATE DE INCENDIOS I":
            contanciaTemplate = "files/certificado_vacio_incendio_basico_nf_nl.pdf";
            break;
        case "BUSQUEDA Y RESCATE":
            contanciaTemplate = "files/certificado_vacio_busq_rescate_nf_nl.pdf";
            break;
        case "EVACUACIN, BUSQUEDA Y RESCATE":
            contanciaTemplate = "files/certificado_vacio_evac_busq_resc_nf_nl.pdf";
            break;
        case "EVACUACIN":
            contanciaTemplate = "files/certificado_vacio_evacuacion_nf_nl.pdf";
            break;
        case "PREVENCIN Y COMBATE DE INCENDIOS II":
            contanciaTemplate = "files/certificado_vacio_incendio_intermedio_nf_nl.pdf";
            break;
        case "PREVENCIN Y COMBATE DE INCENDIOS III":
            contanciaTemplate = "files/certificado_vacio_incendio_avanzado_nf_nl.pdf";
            break;
        case "FORMACION DE BRIGADAS MULTIFUNCIONALES DE EMERGENCIA":
            contanciaTemplate = "files/certificado_vacio_multi_nf_nl.pdf";
            break;
        case "FORMACIN DE BRIGADA MULTIFUNCIONAL DE EMERGENCIA":
            contanciaTemplate = "files/certificado_vacio_multi_nf_nl.pdf";
            break;
        case "FORMACION DE BRIGADA MULTIFUNCIONAL DE EMERGENCIAS":
            contanciaTemplate = "files/certificado_vacio_multi_nf_nl.pdf";
            break;
        case "PRIMEROS AUXILIOS":
            contanciaTemplate = "files/certificado_vacio_primeros_auxilios_nf_nl.pdf";
            break;
        default:/*from w w w .  jav a2  s .c om*/
            contanciaTemplate = "files/cerificado_vacio.pdf";
            break;
        }

        InputStream file = null;
        try {
            file = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream(contanciaTemplate);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error al cargar el certificado base. \nconstancia: "
                    + contanciaTemplate + "\nfile: " + String.valueOf(file) + "\n" + ex.toString());
        }
        PDDocument document = PDDocument.load(file);
        PDPage page1 = (PDPage) document.getDocumentCatalog().getPages().get(0);
        PDPage page2 = (PDPage) document.getDocumentCatalog().getPages().get(1);

        PDPageContentStream contentStream = new PDPageContentStream(document, page1, true, true);
        PDPageContentStream contentStream2 = new PDPageContentStream(document, page2, true, true);

        float pageWidth = page1.getMediaBox().getWidth();

        BufferedImage logo = null;
        BufferedImage firma = null;

        try {
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

            //logo = new File(classLoader.getResource("files/logo.png").getFile());
            //logo = StreamUtil.stream2file(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/logo.png"));
            logo = ImageIO.read(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/logo.png"));

            if (instructor.equalsIgnoreCase("Ing. Jorge Antonio Razn Gutierrez")) {
                firma = ImageIO
                        .read(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/firmaCoco.png"));
                //firma = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/firmaCoco.png").getFile());
            } else if (instructor.equalsIgnoreCase("Manuel Anguiano Razn")) {
                firma = ImageIO.read(
                        cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/firmaManuel.png"));
                //firma = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/firmaManuel.png").getFile());
            } else {
                firma = ImageIO
                        .read(cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/firmaJorge.png"));
                //firma = new File(cdiscisa.Cdiscisa.class.getClassLoader().getResource("files/firmaJorge.png").getFile());
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error al cargar la imagen del logo o la firma \nfile: "
                    + String.valueOf(logo) + "\n" + String.valueOf(firma) + "\n" + ex.toString());
        }

        PDImageXObject firmaObject = null;
        PDImageXObject logoObject = null;

        try {
            if (chkConstFirma.equalsIgnoreCase("true")) {
                firmaObject = LosslessFactory.createFromImage(document, firma);
                //firmaObject = PDImageXObject.createFromFile(firma, document);
            }
            if (chkConstLogo.equalsIgnoreCase("true")) {
                logoObject = LosslessFactory.createFromImage(document, logo);
                //logoObject = PDImageXObject.createFromFile(logo, document);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error al crear objetos de logo o firma \nfile: "
                    + String.valueOf(logoObject) + "\n" + String.valueOf(firmaObject) + "\n" + ex.toString());
        }

        InputStream isFont1 = null, isFont2 = null;
        try {
            isFont1 = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/Calibri.ttf");
            isFont2 = cdiscisa.Cdiscisa.class.getClassLoader().getResourceAsStream("files/CalibriBold.ttf");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error al cargar el una fuente \nisFont1: "
                    + String.valueOf(isFont1) + "\nisFont2: " + String.valueOf(isFont2) + "\n" + ex.toString());
        }

        PDFont calibri = PDType0Font.load(document, isFont1);
        PDFont calibriBold = PDType0Font.load(document, isFont2);

        contentStream.beginText();
        DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, new Locale("es", "MX"));

        contentStream.setFont(calibri, 9);
        contentStream.setNonStrokingColor(Color.BLACK);

        contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 465, 656));
        contentStream.showText(df.format(new Date()));

        contentStream.setFont(calibriBold, 11);

        contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 135, 585));
        contentStream.showText(c.razon_social);

        contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 120, (float) 572.5));
        if (c.walmart) {
            contentStream.showText(d.determinante + " " + d.unidad);
        } else if (d.sucursal.isEmpty() || d.sucursal.equalsIgnoreCase("")) {
            contentStream.endText();
            contentStream.addRect(30, 572, 150, 10);
            contentStream.setNonStrokingColor(Color.WHITE);
            contentStream.fill();
            contentStream.beginText();
            contentStream.setNonStrokingColor(Color.BLACK);
        } else {
            contentStream.showText(d.sucursal);
        }

        if (!c.walmart) {
            contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 527));
            contentStream.showText(d.RFC);
            contentStream.setFont(calibri, 11);
            contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 72, 527));
            contentStream.showText("RFC: ");
            contentStream.setFont(calibriBold, 11);
        }
        /*
        if (c.walmart){
        contentStream.showText(p1.determinante + " " + d.unidad);
        } else if (d.sucursal.isEmpty() || d.sucursal.equalsIgnoreCase("")){
        contentStream.endText();
        contentStream.addRect(100, 590, 400, 20);
        contentStream.setNonStrokingColor(Color.WHITE);
        contentStream.fill();
        contentStream.beginText();
        contentStream.setNonStrokingColor(Color.BLACK);
        } else{
        contentStream.showText(d.sucursal);
        }
            
        */

        float charWidth = calibriBold.getStringWidth(d.direccion) / 1000 * 11;
        //System.out.println(charWidth + " " + d.direccion.length() + " " +  d.direccion);

        if (charWidth <= 400) {
            contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 549));
            contentStream.showText(d.direccion);
        } else {
            contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 552));
            contentStream.showText(d.direccion.substring(0, d.direccion.indexOf(" ", 82)));
            contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 541));
            contentStream.showText(d.direccion.substring(d.direccion.indexOf(" ", 82) + 1, d.direccion.length()));
        }

        charWidth = calibriBold.getStringWidth(c.nombre_curso) / 1000 * 11;

        float xPosition = (pageWidth - charWidth) / 2;

        contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 490));
        contentStream.showText(c.nombre_curso);

        contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 160, 465));
        contentStream.showText(c.fecha_certificado);

        contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 160, (float) 450.5));
        contentStream.showText(c.horas_texto);

        ListIterator<Participante> it = listaParticipantes.listIterator();

        float y = 0;
        while (it.hasNext()) {
            Participante p = it.next();

            if (p.determinante.equalsIgnoreCase(d.determinante)) {
                contentStream.setFont(calibri, 11);

                charWidth = calibri.getStringWidth(p.nombre + " " + p.apellidos) / 1000 * 11;
                //System.out.println(charWidth + " " + p.nombre + " " + p.apellidos);

                if (charWidth > 165) {
                    contentStream.setFont(calibri, 9);
                    contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 135, (float) 376.5 - y));
                    contentStream.showText(p.nombre + " " + p.apellidos);

                    contentStream.setFont(calibri, 11);

                } else {
                    contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 135, (float) 376.5 - y));
                    contentStream.showText(p.nombre + " " + p.apellidos);
                }

                charWidth = calibri.getStringWidth(p.area_puesto) / 1000 * 11;
                //System.out.println(charWidth + " " + p.area_puesto);

                if (charWidth > 112) {
                    contentStream.setFont(calibri, 9);
                    contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 360, (float) 376.5 - y));
                    contentStream.showText(p.area_puesto);

                } else {
                    contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, 360, (float) 376.5 - y));
                    contentStream.showText(p.area_puesto);
                }

                y = y + (float) 12.7;

            }
        }

        contentStream.endText();
        float nameWidth;

        if (logoObject != null && !logoObject.isEmpty()) {
            contentStream.drawImage(logoObject, 30, 700, 156, 78);
        }
        if (firmaObject != null && !firmaObject.isEmpty()) {
            xPosition = (pageWidth - 100) / 2;
            contentStream.drawImage(firmaObject, xPosition, 55, 110, 42);

            contentStream.beginText();
            contentStream.setFont(calibriBold, 10);
            contentStream.setNonStrokingColor(Color.BLACK);

            nameWidth = calibriBold.getStringWidth(instructor) / 1000 * 10;
            xPosition = (pageWidth - nameWidth) / 2 + 9;
            contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 55));
            contentStream.showText(instructor);

            if (instructor.equalsIgnoreCase("Manuel Anguiano Razn")) {
                nameWidth = calibriBold.getStringWidth(c.registro_manuel) / 1000 * 10;
                xPosition = (pageWidth - nameWidth) / 2 + 9;
                contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 40));
                contentStream.showText(c.registro_manuel);
            } else if (instructor.equalsIgnoreCase("Ing. Jorge Antonio Razn Gutierrez")) {
                nameWidth = calibriBold.getStringWidth(c.registro_coco) / 1000 * 10;
                xPosition = (pageWidth - nameWidth) / 2 + 9;
                contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 40));
                contentStream.showText(c.registro_coco);
            } else {
                nameWidth = calibriBold.getStringWidth(c.registro_jorge) / 1000 * 10;
                xPosition = (pageWidth - nameWidth) / 2 + 9;
                contentStream.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 40));
                contentStream.showText(c.registro_jorge);
            }

            contentStream.endText();
        }

        // Make sure that the content stream is closed:
        contentStream.close();

        contentStream2.beginText();

        contentStream2.setFont(calibri, 11);
        contentStream2.setNonStrokingColor(Color.BLACK);

        contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 465, 656));
        contentStream2.showText(df.format(new Date()));

        contentStream2.setFont(calibriBold, 11);

        contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 135, 585));
        contentStream2.showText(c.razon_social);

        contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 120, (float) 572.5));
        if (c.walmart) {
            contentStream2.showText(d.determinante + " " + d.unidad);
        } else {
            contentStream2.showText(d.sucursal);
            contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 527));
            contentStream2.showText(d.RFC);
            contentStream2.setFont(calibri, 11);
            contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 73, 527));
            contentStream2.showText("RFC: ");
            contentStream2.setFont(calibriBold, 11);
        }

        charWidth = calibriBold.getStringWidth(d.direccion) / 1000 * 11;
        //System.out.println(charWidth + " " + d.direccion.length() + " " +  d.direccion);

        if (charWidth <= 400) {
            contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 549));
            contentStream2.showText(d.direccion);
        } else {
            contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 555));
            contentStream2.showText(d.direccion.substring(0, d.direccion.indexOf(" ", 82)));
            contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 120, 540));
            contentStream2.showText(d.direccion.substring(d.direccion.indexOf(" ", 82) + 1, d.direccion.length()));
        }

        charWidth = calibriBold.getStringWidth(c.nombre_curso) / 1000 * 11;

        pageWidth = page2.getMediaBox().getWidth();
        xPosition = (pageWidth - charWidth) / 2;

        contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 490));
        contentStream2.showText(c.nombre_curso);

        contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 160, 465));
        contentStream2.showText(c.fecha_certificado);

        contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, 160, (float) 450.5));
        contentStream2.showText(c.horas_texto);

        contentStream2.endText();

        if (logoObject != null && !logoObject.isEmpty()) {
            contentStream2.drawImage(logoObject, 30, 700, 156, 78);
        }
        if (firmaObject != null && !firmaObject.isEmpty()) {
            xPosition = (pageWidth - 100) / 2;
            contentStream2.drawImage(firmaObject, xPosition, 55, 110, 42);

            contentStream2.beginText();
            contentStream2.setFont(calibriBold, 10);
            contentStream2.setNonStrokingColor(Color.BLACK);

            nameWidth = calibriBold.getStringWidth(instructor) / 1000 * 10;
            xPosition = (pageWidth - nameWidth) / 2 + 9;
            contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 55));
            contentStream2.showText(instructor);

            if (instructor.equalsIgnoreCase("Manuel Anguiano Razn")) {
                nameWidth = calibriBold.getStringWidth(c.registro_manuel) / 1000 * 10;
                xPosition = (pageWidth - nameWidth) / 2 + 9;
                contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 40));
                contentStream2.showText(c.registro_manuel);
            } else if (instructor.equalsIgnoreCase("Ing. Jorge Antonio Razn Gutierrez")) {
                nameWidth = calibriBold.getStringWidth(c.registro_coco) / 1000 * 10;
                xPosition = (pageWidth - nameWidth) / 2 + 9;
                contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 40));
                contentStream2.showText(c.registro_coco);
            } else {
                nameWidth = calibriBold.getStringWidth(c.registro_jorge) / 1000 * 10;
                xPosition = (pageWidth - nameWidth) / 2 + 9;
                contentStream2.setTextMatrix(new Matrix(1, 0, 0, 1, xPosition, 40));
                contentStream2.showText(c.registro_jorge);
            }
            contentStream2.endText();
        }

        contentStream2.close();

        //"Capacitacion_BAE_Centro de Huinala_2631_MULTI_19ago2015"

        //Capacitacin + formato tienda + nombre sucursal + numero sucursal + nombre curso + ddmmaaaa

        Format formatter = new SimpleDateFormat("ddMMMYYYY", new Locale("es", "MX"));
        String formatedDate = formatter.format(c.fecha_inicio);

        String abrev = abreviaturas.get(c.nombre_curso);

        // Save the results and ensure that the document is properly closed:
        if (c.walmart) {
            document.save(savePath + File.separator + "Certificado_" + d.formato + "_" + d.unidad + "_"
                    + d.determinante + "_" + abrev + "_" + formatedDate + ".pdf");
            document.close();
            dosc.put(savePath + File.separator + "Certificado_" + d.formato + "_" + d.unidad + "_" + d.determinante
                    + "_" + abrev + "_" + formatedDate + ".pdf", d.determinante);
        } else {
            document.save(savePath + File.separator + "Certificado_" + d.determinante + "_" + abrev + "_"
                    + formatedDate + ".pdf");
            document.close();
            dosc.put(savePath + File.separator + "Certificado_" + d.determinante + "_" + abrev + "_" + formatedDate
                    + ".pdf", d.determinante);
        }

    }

From source file:com.devnexus.ting.web.controller.PdfUtils.java

License:Apache License

public PdfUtils(float margin, String title) throws IOException {
    this.margin = margin;
    doc = new PDDocument();
    baseFont = PDType0Font.load(doc, PdfUtils.class.getResourceAsStream("/fonts/Arial.ttf"));
    headerFont = PDType1Font.HELVETICA_BOLD;
    subHeaderFont = PDType1Font.HELVETICA_BOLD;
    devnexusLogo = PDDocument.load(PdfUtils.class.getResourceAsStream("/fonts/devnexus-logo.pdf"));

    this.currentPage = new PDPage();
    this.pages.add(currentPage);
    this.doc.addPage(currentPage);

    final PDRectangle mediabox = currentPage.getMediaBox();
    this.width = mediabox.getWidth() - 2 * margin;

    float startX = mediabox.getLowerLeftX() + margin;
    float startY = mediabox.getUpperRightY() - margin;

    this.initialHeightCounter = startY;
    this.heightCounter = startY;

    LOGGER.info(String.format(/*  w  w w. j  av  a 2 s. co m*/
            "Margin: %s, width: %s, startX: %s, "
                    + "startY: %s, heightCounter: %s, baseFontSize: %s, headerFontSize: %s",
            margin, width, startX, startY, heightCounter, baseFont, headerFont));

    contents = new PDPageContentStream(doc, currentPage);

    // Add Logo

    final LayerUtility layerUtility = new LayerUtility(doc);
    final PDFormXObject logo = layerUtility.importPageAsForm(devnexusLogo, 0);
    final AffineTransform affineTransform = AffineTransform.getTranslateInstance(100, startY - 50);
    affineTransform.scale(2d, 2d);
    layerUtility.appendFormAsLayer(currentPage, logo, affineTransform, "devnexus-logo");
    this.heightCounter -= 100;

    this.contents.beginText();

    this.contents.setFont(headerFont, headerFontSize);
    this.currentLeading = this.lineSpacing * baseFontSize;
    this.contents.setLeading(this.currentLeading);

    contents.newLineAtOffset(50, heightCounter);

    println(title);

    this.contents.setFont(baseFont, baseFontSize);
    this.currentLeading = this.lineSpacing * baseFontSize;
    this.contents.setLeading(this.currentLeading);

    println();

}

From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer.java

License:Apache License

private PDFont findFallbackFont(IFontTextDrawerEnv env) throws IOException {
    /*//from  w w  w  .  j ava  2  s  .  c om
     * We search for the right font in the system folders... We try to use
     * LucidaSansRegular and if not found Arial, because this fonts often exists. We
     * use the Java default font as fallback.
     * 
     * Normally this method is only used and called if a default font misses some
     * special characters, e.g. Hebrew or Arabic characters.
     */
    String javaHome = System.getProperty("java.home", ".");
    String javaFontDir = javaHome + "/lib/fonts";
    String windir = System.getenv("WINDIR");
    if (windir == null)
        windir = javaFontDir;
    File[] paths = new File[] { new File(new File(windir), "fonts"),
            new File(System.getProperty("user.dir", ".")), new File("/Library/Fonts"),
            new File("/usr/share/fonts/truetype"), new File("/usr/share/fonts/truetype/dejavu"),
            new File("/usr/share/fonts/truetype/liberation"), new File("/usr/share/fonts/truetype/noto"),
            new File(javaFontDir) };
    File foundFontFile = null;
    for (String fontFileName : new String[] { "LucidaSansRegular.ttf", "arial.ttf", "Arial.ttf",
            "DejaVuSans.ttf", "LiberationMono-Regular.ttf", "NotoSerif-Regular.ttf" }) {
        for (File path : paths) {
            File arialFile = new File(path, fontFileName);
            if (arialFile.exists()) {
                foundFontFile = arialFile;
                break;
            }
        }
        if (foundFontFile != null)
            break;
    }
    /*
     * If we did not find any font, we can't do anything :(
     */
    if (foundFontFile == null)
        return null;
    return PDType0Font.load(env.getDocument(), foundFontFile);
}

From source file:info.informationsea.venn.graphics.VennDrawPDF.java

License:Open Source License

public static <T> void draw(VennFigure<T> vennFigure, PDDocument doc) throws IOException {
    // based on https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java?revision=1703059&view=markup
    PDFont font = PDType0Font.load(doc, VennDrawPDF.class.getResourceAsStream("../fx/mplus-1p-regular.ttf"));

    Rectangle2D drawRect = vennFigure.drawRect(str -> stringBoundingBox(font, str, FONT_SIZE));
    PDRectangle pageSize = new PDRectangle((float) drawRect.getWidth() + MARGIN * 2,
            (float) drawRect.getHeight() + MARGIN * 2);
    PDPage page = new PDPage(pageSize);
    doc.addPage(page);/*from w ww  . j  a  v a2  s. com*/

    VennDrawPDF.draw(vennFigure, doc, page, font, pageSize);

    // PDF/A1b support
    /*
    // add XMP metadata
    XMPMetadata xmp = XMPMetadata.createXMPMetadata();
            
    try
    {
    DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
    dc.setTitle("Venn Diagram");
    dc.setSource("VennDraw "+ VersionResolver.getVersion());
    dc.setDescription("Venn Diagram");
            
    PDFAIdentificationSchema id = xmp.createAndAddPFAIdentificationSchema();
    id.setPart(1);
    id.setConformance("B");
            
    XmpSerializer serializer = new XmpSerializer();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(xmp, baos, true);
            
    PDMetadata metadata = new PDMetadata(doc);
    metadata.importXMPMetadata(baos.toByteArray());
    doc.getDocumentCatalog().setMetadata(metadata);
    } catch(BadFieldValueException|TransformerException  e) {
    throw new RuntimeException(e);
    }
            
    // sRGB output intent
    InputStream colorProfile = VennDrawPDF.class.getResourceAsStream(
        "sRGB Color Space Profile.icm");
    PDOutputIntent intent = new PDOutputIntent(doc, colorProfile);
    intent.setInfo("sRGB IEC61966-2.1");
    intent.setOutputCondition("sRGB IEC61966-2.1");
    intent.setOutputConditionIdentifier("sRGB IEC61966-2.1");
    intent.setRegistryName("http://www.color.org");
    doc.getDocumentCatalog().addOutputIntent(intent);
    */
}

From source file:org.fit.cssbox.render.PDFRenderer.java

License:Open Source License

/**
 * Tries to load a font from the system database.
 * @param fontFamily/*from   www .  ja v  a 2  s.com*/
 * @param isItalic
 * @param isBold
 * @return the font or {@code null} when not found
 */
private PDFont loadTTF(String fontFamily, boolean isItalic, boolean isBold) {
    PDFont font = null;
    try {
        URI uri = fontDB.findFontURI(fontFamily, isBold, isItalic);
        if (uri != null)
            font = PDType0Font.load(doc, new File(uri));
    } catch (IOException e) {
        font = null;
    }
    return font;
}

From source file:pl.vane.pdf.factory.PDFFactory.java

License:Open Source License

private static Map<Integer, PDFont> loadFonts(List<PDFFont> fontList, PDDocument document) throws IOException {
    Map<Integer, PDFont> fonts = new HashMap<Integer, PDFont>();

    for (PDFFont data : fontList) {
        File f = new File(data.getPath());
        PDFont font = PDType0Font.load(document, f);
        fonts.put(data.getId(), font);/*  ww w .  j a v a  2  s  . c  o m*/
    }

    return fonts;
}

From source file:projekt.CustomRenderer.java

public void raport_lokalny() throws IOException, ClassNotFoundException, SQLException {

    loginController login = new loginController();
    String zapytanie = "select count(*) as Aktualne from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Aktualne' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";
    String zapytanie1 = "select count(*) as FORTEST from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'FORTEST' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";
    String zapytanie2 = "select count(*) as Zakonczone from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Zakonczone' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8",
            "root", "");
    PreparedStatement statment;//from   ww  w  .ja v a  2  s. c o  m
    ResultSet result;
    double odp = 0, odp1 = 0, odp2 = 0;
    statment = con.prepareStatement(zapytanie);
    result = statment.executeQuery();
    if (result.next()) {
        odp = result.getDouble("Aktualne");
    }
    statment = con.prepareStatement(zapytanie1);
    result = statment.executeQuery();
    if (result.next()) {
        odp1 = result.getDouble("FORTEST");
    }
    statment = con.prepareStatement(zapytanie2);
    result = statment.executeQuery();
    if (result.next()) {
        odp2 = result.getDouble("Zakonczone");
    }
    //tu tez zmienic na id
    statment = con.prepareStatement(
            "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '"
                    + login.uzytkownikID + "'");
    result = statment.executeQuery();
    String bbc = "";
    if (result.next()) {
        bbc = result.getString(1);
    }

    DefaultCategoryDataset set2 = new DefaultCategoryDataset();
    set2.setValue(odp, "", "Aktualne");
    set2.setValue(odp1, "", "FORTEST");
    set2.setValue(odp2, "", "Zakonczone");
    JFreeChart chart = ChartFactory.createBarChart(
            "Wszystkie zadania z projektow za ktore odpowiada " + result.getString(1), "Zadania", "Ilosc", set2,
            PlotOrientation.VERTICAL, false, true, false);

    final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.blue, Color.pink, Color.cyan,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);
    renderer.setPositiveItemLabelPosition(p);
    plot.setRenderer(renderer);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsJPEG(out, chart, 450, 600);
    DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    Date data = new Date();
    String fileName = "Raport lokalny " + dataformat1.format(data) + ".pdf";
    try {
        PDRectangle PAGE_SIZE = PDRectangle.A4;
        PDDocument doc = new PDDocument();
        PDFont font = PDType0Font.load(doc,
                getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf"));
        PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf"));
        PDPage page = new PDPage(PAGE_SIZE);
        PDPage page1 = new PDPage(PAGE_SIZE);
        doc.addPage(page);
        PDPageContentStream content = new PDPageContentStream(doc, page);
        //naglowek strona 1
        Naglowek1(content, dataformat, data);
        //stopka strona1
        Stopka(content, doc);
        content.beginText();
        content.setFont(font1, 48);
        content.moveTextPositionByAmount(135, 550);
        content.showText("Raport lokalny");
        content.endText();

        content.beginText();
        content.setFont(font, 22);
        content.moveTextPositionByAmount(30, 250);
        content.showText("Wersja systemu : 1.0");
        content.newLine();
        content.moveTextPositionByAmount(0, 35);
        content.showText("Autor raportu : " + result.getString("osoba"));
        content.endText();
        content.close();

        PDPageContentStream content1 = new PDPageContentStream(doc, page1);

        PDPage page2 = new PDPage(PAGE_SIZE);
        doc.addPage(page2);
        PDPageContentStream content2 = new PDPageContentStream(doc, page2);
        Naglowek1(content2, dataformat, data);
        //stopka strona2
        Stopka(content2, doc);
        content2.beginText();
        content2.setFont(font, 14);
        content2.moveTextPositionByAmount(30, 775);
        content2.showText("Wszystkie projekty za ktre odpowiada: " + result.getString(1));
        statment = con.prepareStatement(
                "Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty where idUzytkownika='"
                        + login.uzytkownikID + "'");
        result = statment.executeQuery();
        content2.newLine();
        int liczba = 615;
        content2.moveTextPositionByAmount(0, -15);
        while (result.next()) {
            content2.newLine();
            content2.moveTextPositionByAmount(0, -22);
            liczba += 22;
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));

            content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString(1));
            content2.newLine();
            content2.moveTextPositionByAmount(0, -17);
            liczba += 22;
            content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: "
                    + result.getString("Koniec"));

        }
        content2.endText();
        //          content2.setLineWidth(2);
        //        content2.moveTo(10, liczba + 5);
        //        content2.lineTo(10, liczba +5);
        //        content2.closeAndStroke();
        DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd");
        statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '"
                + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'");
        result = statment.executeQuery();
        int aktualne = 0, zakonczone = 0;
        if (result.next()) {
            aktualne = result.getInt("Aktualne");
        }
        statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '"
                + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'");
        result = statment.executeQuery();
        if (result.next()) {
            zakonczone = result.getInt("Zakonczone");
        }

        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("Aktualne", aktualne);
        pieDataset.setValue("Zakonczone", zakonczone);
        JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projekt za ktore odpowiada" + bbc, // Title
                pieDataset, // Dataset
                true, // Show legend
                true, // Use tooltips
                false // Configure chart to generate URLs?
        );

        PiePlot plot1 = (PiePlot) chart1.getPlot();
        plot1.setSectionPaint("Aktualne", Color.blue);
        plot1.setSectionPaint("Zakonczone", Color.yellow);
        plot1.setExplodePercent("Aktualne", 0.10);
        plot1.setSimpleLabels(true);

        PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
                new DecimalFormat("0"), new DecimalFormat("0%"));
        plot1.setLabelGenerator(gen);

        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
        ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600);
        PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray()));

        content2.close();
        PDPage page3 = new PDPage(PAGE_SIZE);
        doc.addPage(page3);
        PDPageContentStream content3 = new PDPageContentStream(doc, page3);
        Naglowek1(content3, dataformat, data);
        //stopka strona2
        Stopka(content3, doc);
        content3.drawImage(img1, 50, 50);
        content3.close();
        PDPage page4 = new PDPage(PAGE_SIZE);
        doc.addPage(page4);
        PDPageContentStream content4 = new PDPageContentStream(doc, page4);
        Naglowek1(content4, dataformat, data);
        //stopka strona2
        Stopka(content4, doc);
        content4.beginText();
        content4.setFont(font, 14);
        content4.moveTextPositionByAmount(30, 780);
        content4.showText("Wszystkie zadania w projektach za ktore odpowiada:" + bbc);
        statment = con.prepareStatement(
                "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, ' ' , y.nazwisko) as 'UZY' FROM zadania , (select Nazwa from projekty where idUzytkownika = '"
                        + login.uzytkownikID
                        + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '"
                        + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12"); //poprawic
        result = statment.executeQuery();
        content4.newLine();
        int nw = 850;
        content4.moveTextPositionByAmount(0, -15);
        nw -= 15;
        while (result.next()) {
            content4.newLine();
            nw -= 22;
            content4.moveTextPositionByAmount(0, -22);
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));
            content4.showText("Nazwa : " + result.getString("zadania.Nazwa"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: "
                    + result.getString("zadania.Status_zadania"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Projekt: " + result.getString("zadania.projekt")
                    + " Przydzielona osoba do zadania: " + result.getString("UZY"));

        }

        content4.endText();
        content4.close();
        statment = con.prepareStatement(
                "SELECT count(*) as 'liczba' FROM `zadania` where idUzytkownika='" + login.uzytkownikID + "'"); //poprawic
        result = statment.executeQuery();
        if (result.next()) {
        }
        statment = con.prepareStatement(
                "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, \" \", y.nazwisko) as \"UZY\" FROM zadania , (select Nazwa from projekty where idUzytkownika = '"
                        + login.uzytkownikID
                        + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '"
                        + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12,"
                        + result.getInt(1) + "");
        result = statment.executeQuery();
        PDPage page5 = new PDPage(PAGE_SIZE);
        doc.addPage(page5);
        PDPageContentStream content5 = new PDPageContentStream(doc, page5);
        Naglowek1(content5, dataformat, data);
        //stopka strona2
        Stopka(content5, doc);
        content5.beginText();
        content5.setFont(font, 14);
        content5.moveTextPositionByAmount(30, 700);
        while (result.next()) {
            content5.newLine();
            nw -= 22;
            content5.moveTextPositionByAmount(0, -22);
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));
            content5.showText("Nazwa : " + result.getString("zadania.Nazwa"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: "
                    + result.getString("zadania.Status_zadania"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Projekt: " + result.getString("zadania.projekt")
                    + " Przydzielona osoba do zadania: " + result.getString("UZY"));
        }
        content5.endText();
        content5.close();
        doc.addPage(page1);
        //naglowek strona 2
        Naglowek1(content1, dataformat, data);
        //stopka strona2
        Stopka(content1, doc);
        PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray()));
        content1.drawImage(img, 50, 50);
        content1.close();
        doc.save(fileName);
        doc.close();

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}