Example usage for com.itextpdf.text.pdf BaseFont EMBEDDED

List of usage examples for com.itextpdf.text.pdf BaseFont EMBEDDED

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BaseFont EMBEDDED.

Prototype

boolean EMBEDDED

To view the source code for com.itextpdf.text.pdf BaseFont EMBEDDED.

Click Source Link

Document

if the font has to be embedded

Usage

From source file:Registration_Tenant.java

private void saveToPdf() {
    try {/*from ww  w .j  a  va  2  s . co m*/
        String gend = "";
        Document doc = new Document();
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }
        FileOutputStream fos = new FileOutputStream(
                path + "\\registration\\" + lastNameTextField.getText().trim() + ", "
                        + firstNameTextField.getText().trim() + "RegistrationResidentForm.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("RegistrationResidentForm.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);

            byte[] cc = null;
            if (file != null) {
                File thisFile = new File(file);
                cc = Files.readAllBytes(thisFile.toPath());
            }
            if (cc != null) {
                Image image1 = Image.getInstance(cc);
                image1.scaleAbsolute(95, 105);
                image1.setAbsolutePosition(465f, 635f);
                content.addImage(image1);
            }

            //Text over the existing page
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            //last name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, lastNameTextField.getText().trim(), 175, 610, 0);
            //first name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, firstNameTextField.getText().trim(), 325, 610,
                    0);
            //middle name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, middleNameTextField.getText().trim(), 470, 610,
                    0);
            //college
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, collegeTextField.getText().trim(), 180, 582, 0);
            //Course and year
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    courseTextField.getText().trim() + " - " + yearTextField.getText().trim(), 180, 568, 0);
            //department
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, departmentTextField.getText().trim(), 400, 582,
                    0);
            String g;
            if (male.isSelected()) {
                g = "Male";//6
            } else {
                g = "Female";//6
            }
            //Sex
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, g, 400, 568, 0);
            //Home address
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, homeAddressTextArea.getText(), 110, 540, 0);
            //resident mobile no1
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, MobileNumber1.getText().trim(), 187, 485, 0);
            //resident mobile no2
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, MobileNumber2.getText().trim(), 187, 470, 0);
            //student email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, email.getText().trim(), 397, 485, 0);
            //fathers name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fatherNameTextField.getText().trim(), 110, 443,
                    0);
            //fathers area code
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fACodeTextField.getText().trim(), 300, 443, 0);
            //father landline
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fphoneNumberTextField.getText().trim(), 355, 443,
                    0);
            //father mobile
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fMobileNumberTextField.getText().trim(), 490,
                    443, 0);
            //father email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fEmailTextField.getText().trim(), 110, 430, 0);
            //mother name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, motherNameTextField.getText().trim(), 110, 402,
                    0);
            //mother area code
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mACodeTextField.getText().trim(), 300, 402, 0);
            //mother landline
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mphoneNumberTextField.getText().trim(), 355, 402,
                    0);
            //mother mobile
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mMobileNumberTextField.getText().trim(), 490,
                    402, 0);
            //mother email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mEmailTextField.getText().trim(), 110, 387, 0);
            //guardian name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, guardianNameTextField.getText().trim(), 170, 335,
                    0);
            //guardian contact number
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, gContactNumber1.getText().trim(), 470, 335, 0);
            //guardian address
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, guardianAddress.getText().trim(), 125, 322, 0);
            //guardian relation
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, relationToGuardian.getText().trim(), 170, 307,
                    0);
            content.setFontAndSize(bf, 12);
            //room details
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "Room No.: " + roomNumberTextField.getSelectedItem().toString().trim() + " - "
                            + roomTypeTextField.getText().trim(),
                    355, 235, 0);
            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
        fos.close();
        pdfWriter.close();
    } catch (DocumentException ex) {
        //            Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (IOException ex) {
        //            Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:JT.java

public void createPdf(String filename) throws DocumentException, IOException {
    // step 1//  w  ww .  jav a  2s.c om
    Document document = new Document();
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3

    BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\vuTimes.ttf", BaseFont.IDENTITY_H,
            BaseFont.EMBEDDED);
    Font font = new Font(bf, 15);
    document.open();
    // step 4
    String pa = "H? v tn         : L Ng?c Long\n" + "MSSV                : 20142659\n"
            + "?? ti               : Xy dng chng trnh qun l th vin";
    pa += "\n\nTr?ng ?i H?c Bch Khoa H Ni          Cng Ha - X Hi - Ch Ngha - Vit Nam\n"
            + "      Th vin T Quang Bu                              ?c Lp - T Do - Hnh Phc";
    pa += "\n\n                                         TM KIM S?CH THEO xxx";

    document.add(new Paragraph(pa, font));

    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate tp = cb.createTemplate(jTable1.getWidth(), jTable1.getHeight());
    Graphics2D g2;

    g2 = tp.createGraphicsShapes(jTable1.getWidth(), jTable1.getHeight());
    jTable1.print(g2);
    float x = 50, y = 300;

    g2.dispose();
    cb.addTemplate(tp, x, y);

    // step 5
    document.close();
}

From source file:Registration_Transient.java

private void saveToPdf() {
    try {//  w  w  w  .  ja v  a  2  s  . c o  m

        com.itextpdf.text.Document doc = new com.itextpdf.text.Document();
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }
        FileOutputStream fos = new FileOutputStream(path + "\\transient\\" + lastNameTextField.getText().trim()
                + ", " + firstNameTextField.getText().trim() + "TransientForm.pdf");
        PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("TransientForm.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);
        //doc.open();
        //doc.add(new Paragraph(contents.getText().trim() + "-markram"));
        float varPosition = 0;
        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);
            //Text over the existing page
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            varPosition = 15;
            //last name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    lastNameTextField.getText().trim() + ", " + firstNameTextField.getText().trim(), 100,
                    661 + varPosition, 0);
            //first name 
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()), 400,
                    661 + varPosition, 0);

            if (residentNameCheckBox.isSelected()) {
                content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        residentComboBox.getSelectedItem().toString(), 125, 633 + varPosition, 0);
                content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        residentComboBox.getSelectedItem().toString(), 470, 633 + varPosition, 0);
            } else {
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 125, 633 + varPosition, 0);
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 470, 633 + varPosition, 0);
            }

            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mobileNoTextField.getText(), 135,
                    590 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, emailTextField.getText(), 400, 590 + varPosition,
                    0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, addressTextField.getText(), 175,
                    577 + varPosition, 0);
            varPosition = 35;
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, roomReservedTextField.getText(), 135,
                    507 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateArrivalChooserCombo.getText(), 135,
                    493 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateDepartureChooserCombo.getText(), 435,
                    493 + varPosition, 0);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestSpinner.getValue().toString(), 180,
                    478 + varPosition, 0);
            for (int count = 0; count < guestTable.getRowCount(); count++) {
                float x = 50;
                if (count <= 3) {
                    content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                            guestTable.getValueAt(count, 0).toString(), x, 435 + varPosition, 0);
                    varPosition -= 13;
                    if (count == 3) {
                        varPosition = 35;
                    }
                } else if (count >= 4 & count <= 7) {
                    content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                            guestTable.getValueAt(count, 0).toString(), x + 200, 435 + varPosition, 0);
                    varPosition -= 13;
                    if (count == 7) {
                        varPosition = 35;
                    }
                } else {
                    content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                            guestTable.getValueAt(count, 0).toString(), x + 400, 435 + varPosition, 0);
                    varPosition -= 13;
                }

            }
            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
    } catch (DocumentException ex) {
        //            Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (IOException ex) {
        //            Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:Billing_v2.java

public boolean saveStatementOfAccountToPDF(ArrayList<String> info) {
    try {//from  w ww .  j a  va  2  s  . c  o m
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }

        com.itextpdf.text.Document doc = new com.itextpdf.text.Document();
        FileOutputStream fos = new FileOutputStream(
                path + "\\residentStatementOfAccount\\" + info.get(0) + "statementOfAccounts.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("statementOfAccounts.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);

        java.util.Date date = new SimpleDateFormat("yyyy-MM-dd").parse(info.get(6));

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            //month
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MMMM").format(date), 205,
                    625, 0);
            //name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0), 125, 610, 0);
            //roomNumber
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1), 130, 598, 0);
            //monthly rate
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2), 205, 560, 0);
            //Shuttle rate
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(3), 205, 545, 0);
            //gadget rate
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(4), 205, 530, 0);
            //additional fee
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(5), 205, 518, 0);
            //total amount
            Double totalAmount = Double.parseDouble(info.get(2)) + Double.parseDouble(info.get(3))
                    + Double.parseDouble(info.get(4));
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, totalAmount + "", 205, 490, 0);
            //due date

            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MONTH, Calendar.MONTH - 1);
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(7), 130, 463, 0);

            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
        fos.close();
        pdfWriter.close();

        return true;
    } catch (DocumentException | ParseException ex) {
        //            Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
        return false;
    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
        return false;
    } catch (IOException ex) {
        //            Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
        return false;
    }
}

From source file:Almacen.Responsiva.java

private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed
    // TODO add your handling code here:
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from   w  ww  .  j  av  a2s  .c  o  m
        String empleado = "";
        String puesto = "";
        if (t_datos.getRowCount() > 0) {
            //consulta
            Query q = session.createSQLQuery(
                    "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado="
                            + t_id_empleado.getText() + ";");
            q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
            List lista = q.list();

            for (int i = 0; i < lista.size(); i++) {
                java.util.HashMap map = (java.util.HashMap) lista.get(i);
                empleado = (String) map.get("empleado");
                puesto = (String) map.get("puesto");
            }

            Date fecha = new Date();
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
            String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto",
                    "Septiembre", "Octubre", "Noviembre", "Diciembre" };
            Calendar fecha1 = new GregorianCalendar();
            int anio = fecha1.get(Calendar.YEAR);
            int mes = fecha1.get(Calendar.MONTH);
            int dia = fecha1.get(Calendar.DAY_OF_MONTH);
            //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
            String valor = dateFormat.format(fecha);
            File folder = new File("reportes/Responsivas");
            folder.mkdirs();
            PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf");
            PdfStamper stamp = new PdfStamper(reader,
                    new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"));
            PdfContentByte cb = stamp.getUnderContent(1);
            PdfContentByte cb2 = stamp.getUnderContent(2);
            AcroFields fdfDoc = stamp.getAcroFields();
            // Creo una fuente
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

            cb.beginText();
            //dia
            try {
                if (dia < 9)
                    fdfDoc.setField("Dia", "0" + String.valueOf(dia));
                else
                    fdfDoc.setField("Dia", String.valueOf(dia));
            } catch (Exception e) {
                fdfDoc.setField("Dia", "error");
            }
            //mes
            try {
                fdfDoc.setField("Mes", Mes[mes]);
            } catch (Exception e) {
                fdfDoc.setField("Mes", "");
            }
            //ao
            try {
                fdfDoc.setField("Anio", String.valueOf(anio));
            } catch (Exception e) {
                fdfDoc.setField("Anio", "");
            }
            //nombre
            try {
                fdfDoc.setField("Nombre", empleado);
            } catch (Exception e) {
                fdfDoc.setField("Nombre", "");
            }
            //puesto
            try {
                fdfDoc.setField("Puesto", puesto);
            } catch (Exception e) {
                fdfDoc.setField("Puesto", "");
            }

            //tabla de herramientas
            float tam[] = new float[] { 250, 50, 180 };
            Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
            PDF reporte = new PDF();
            PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT);
            tabla.setTotalWidth(tam);
            BaseColor cabecera = BaseColor.GRAY;
            BaseColor contenido = BaseColor.WHITE;
            int centro = Element.ALIGN_CENTER;
            int izquierda = Element.ALIGN_LEFT;
            int derecha = Element.ALIGN_RIGHT;

            tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

            for (int i = 0; i < t_datos.getRowCount(); i++) {
                tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0,
                        1, Rectangle.RECTANGLE));

                tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido,
                        centro, 0, 1, Rectangle.RECTANGLE));
                if (t_datos.getValueAt(i, 3) != null)
                    tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda,
                            0, 1, Rectangle.RECTANGLE));
                else
                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
            }

            tabla.completeRow();
            tabla.writeSelectedRows(0, -1, 70, 720, cb2);
            cb.endText();
            stamp.close();
            reporte.cerrar();
            reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf");
        } else {
            JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva");
        }
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null) {
        if (session.isOpen()) {
            session.close();
        }
    }
}

From source file:avalonscrollmaker20.AnothakScribe.java

License:Open Source License

private void makeFonts() {
    try {/* w w  w  .  j av  a  2s  .c o  m*/
        String fontURL = this.getClass().getResource("resources/Avalon - Lierseth.ttf").toString();
        BaseFont bf = BaseFont.createFont(fontURL, "", BaseFont.EMBEDDED);
        f_phraseSymbol = new Font(bf, 70);
        f_phraseSymbolBreath = new Font(bf, 55);

        fontURL = this.getClass().getResource("resources/HARNGTON.TTF").toString();
        bf = BaseFont.createFont(fontURL, "", BaseFont.EMBEDDED);
        f_phraseCommon = new Font(bf, 25);
        f_phraseCommonBreath = new Font(bf, 15);

        fontURL = this.getClass().getResource("resources/ENDOR___.ttf").toString();
        bf = BaseFont.createFont(fontURL, "", BaseFont.EMBEDDED);
        f_school = new Font(bf, 30);
        f_schoolPure = new Font(bf, 25);

        fontURL = this.getClass().getResource("resources/neverworld.ttf").toString();
        bf = BaseFont.createFont(fontURL, "", BaseFont.EMBEDDED);
        f_title = new Font(bf, 40);
        //f_titlePhrase = new Font( bf, 10 );
        f_code = new Font(bf, 50);
        f_code.setColor(new BaseColor(128, 128, 128, 16));

        fontURL = this.getClass().getResource("resources/evanescent.ttf").toString();
        bf = BaseFont.createFont(fontURL, "", BaseFont.EMBEDDED);
        f_keu = new Font(bf, 40);
    } catch (Exception ex) {
        System.err.println(ex + "\nProgram closing.");
        System.exit(2);
    }
}

From source file:bouttime.report.boutsheet.BoutSheetReport.java

License:Open Source License

/**
 * Generate a bout sheet report that has no data in it (only the image).
 * The length is the given number of pages.
 * //w  ww .ja va  2s .c om
 * @param numPages
 * @return True if the report was generated.
 */
public boolean generateBlank(Dao dao, Integer numPages) {
    // step 1: creation of a document-object
    // rotate to make page landscape
    Document document = new Document(PageSize.A4.rotate());

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        writer.setPageEvent(this);

        // step 3: we open the document
        document.open();

        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

        BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
        float pageWidth = cb.getPdfDocument().getPageSize().getWidth();
        float midPage = pageWidth / 2;

        setHeaderString(dao);

        int count = 1;
        while (true) {
            drawBout(cb, bf, 35, midPage - 35, null);
            drawBout(cb, bf, midPage + 35, pageWidth - 35, null);

            if (++count > numPages) {
                break;
            }

            document.newPage();
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    } catch (IOException ioe) {
        logger.error("IO Exception", ioe);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.boutsheet.BoutSheetReport.java

License:Open Source License

/**
 * Generate a bout sheet report for the given list of bouts.
 * It is assumed that the list is in the desired order (no sorting is done here).
 *
 * @param list//from  w w w . j ava2s.c  o  m
 * @return True if the report was generated.
 */
public boolean generateReport(Dao dao, List<Bout> list) {

    // step 1: creation of a document-object
    // rotate to make page landscape
    Document document = new Document(PageSize.A4.rotate());

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        writer.setPageEvent(this);

        // step 3: we open the document
        document.open();

        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

        BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
        float pageWidth = cb.getPdfDocument().getPageSize().getWidth();
        float midPage = pageWidth / 2;

        setHeaderString(dao);

        int count = 0;
        for (Bout b : list) {
            boolean rightSide = false;
            if ((count++ % 2) == 0) {
                if (count > 2) {
                    // We could put this after Bout 2 is added, but
                    // that could leave a blank last page.
                    document.newPage();
                }

                // Bout 1 (Left side)
                drawBout(cb, bf, 35, midPage - 35, b);
            } else {
                // Bout 2 (Right side)
                drawBout(cb, bf, midPage + 35, pageWidth - 35, b);
                rightSide = true;
            }

            // Print the watermark, if necessary
            boolean doWatermark = false;
            String gClass = b.getGroup().getClassification();
            String wmValues = dao.getBoutsheetWatermarkValues();
            if ((wmValues != null) && !wmValues.isEmpty()) {
                String[] tokens = wmValues.split(",");
                for (String s : tokens) {
                    if (s.trim().equalsIgnoreCase(gClass)) {
                        doWatermark = true;
                        break;
                    }
                }
            }
            if (doWatermark) {
                int rotation = 45;
                PdfContentByte ucb = writer.getDirectContentUnder();
                BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
                ucb.saveState();
                ucb.setColorFill(BaseColor.LIGHT_GRAY);
                ucb.beginText();
                ucb.setFontAndSize(helv, 86);
                float centerWidth = document.getPageSize().getWidth() / 4;
                if (rightSide) {
                    centerWidth = centerWidth * 3;
                }
                ucb.showTextAligned(Element.ALIGN_CENTER, gClass, centerWidth,
                        document.getPageSize().getHeight() / 2, rotation);
                ucb.endText();
                ucb.restoreState();
            }
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    } catch (IOException ioe) {
        logger.error("IO Exception", ioe);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.bracketsheet.BracketSheetUtil.java

License:Open Source License

public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string)
        throws DocumentException, IOException {

    if (bf == null) {
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
    }//from www .j a v a2  s  .  co m

    cb.setFontAndSize(bf, fontSize);

    cb.beginText();
    cb.setTextMatrix(x, y);
    cb.showText(string);
    cb.endText();
    cb.stroke();
}

From source file:bouttime.report.bracketsheet.BracketSheetUtil.java

License:Open Source License

public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string,
        boolean strikethrough) throws DocumentException, IOException {

    if (bf == null) {
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
    }/*  w w w .j  a v  a 2  s  . co m*/

    drawString(cb, bf, x, y, fontSize, string);
    if (strikethrough) {
        float halfHeight = (bf.getAscentPoint(string, fontSize)) / 2;
        float width = bf.getWidthPointKerned(string, fontSize);
        drawHorizontalLine(cb, x, y + halfHeight, width, 1.5f, 0);
    }
}