Example usage for com.lowagie.text PageSize A4

List of usage examples for com.lowagie.text PageSize A4

Introduction

In this page you can find the example usage for com.lowagie.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.lowagie.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:test.itext.xml2pdf.Main.java

License:Open Source License

public static void main(String args[]) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sample.pdf"));
    //      writer.setPageEvent(new SimpleLetter());
    StringBuffer sb = new StringBuffer();
    sb.append("<p><u><em><strong>Product Description</strong></em></u></p>");
    sb.append(/* ww  w  .  j a v a 2 s  .c om*/
            "<p style=\"text-align: justify\">Face the biggest test in soccer and come out on top with FIFA 08. Bringing home the silverware is harder than ever before as you make critical selection decisions and battle bookings, injuries and fatigue to produce a winning team. Defeat the toughest opposition with your in-form players &ndash; overpower teams with quick movement off the ball and varying attacks. Select from fully-licensed teams, raise your game with the help of the crowd and start your quest for glory.</p>");
    sb.append("<p style=\"text-align: justify\"><strong>Starting the game</strong></p>");
    sb.append(
            "<p style=\"text-align: justify\">Highlight &ldquo;EA SPORTS FIFA 08&rdquo; in the games menu on your phone. Press &ldquo;Select&rdquo; (or &ldquo;OK&rdquo; on the D-Pad) to start the game. You are prompted to choose sound either on or off. After you make your selection, the EA Mobile splash screen appears followed by EA SPORTS FIFA 08 title sequence and the Main Menu.<br />");
    sb.append("&nbsp;</p>");
    sb.append("<p style=\"text-align: justify\"><strong>Main Menu</strong></p>");
    sb.append("<ul>");
    sb.append("<li>Play &ndash; Start a game.</li>");
    sb.append(
            "<li>Options &ndash; View the available game options: sound, vibration, match length, difficulty, etc</li>");
    sb.append("<li>Help &ndash; View detailed instructions and information on how to play the game.</li>");
    sb.append("<li>About &ndash; Display copyright information and customer service information.</li>");
    sb.append("<li>More Games &ndash; Display link to more EA Mobile games.</li>");
    sb.append("<li>Exit &ndash; Exit the game.</li>");
    sb.append("</ul>");
    Reader reader = new StringReader(sb.toString());
    XmlParser.parse(document, reader, new Main.MyTagMap());
}

From source file:tk.diginspect.main.SoOFSignatories.java

public void createPDF() {
    doc = new Document(PageSize.A4);
    try {/*from  w  w  w.  j a va2s.c  om*/
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/RFO";
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        String strFinalname, strFilename2, strFilenames;
        String filename = sp.getString("EstablishmentName", null);
        String strfilename = filename.replaceAll("\\W+", "-");
        String inspector = sp.getString("FDRO1", null);
        String inspby = inspector.replaceAll("\\W+", "-");
        File file = new File(dir, strfilename + "-" + strFile + "-" + inspby + ".pdf");

        strFilename2 = strfilename + "-" + strFile + "-" + inspby;
        strFilenames = strFilename2 + ".pdf";
        strFinalname = path + "/" + strFilenames;
        savePreferences("fileName", strFinalname);

        FileOutputStream fOut = new FileOutputStream(file);
        PdfWriter.getInstance(doc, fOut);
        doc.open();

        FDALetterhead();

        // General Info Table
        float[] table1columnWidths = { 1f, 1f, 1f, 1f };
        PdfPTable table1 = new PdfPTable(table1columnWidths);
        table1.setWidthPercentage(110f);
        table1.setSpacingAfter(20f);
        insertCell(table1, "INSPECTION REPORT", Element.ALIGN_CENTER, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "Name of Establishment", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("EstablishmentName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Plant/Office Address", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PlantOfficeAddress", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Warehouse Address", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("WarehouseAddress", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Owner", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Owner", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Telephone Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("TelNumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Fax No", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("FaxNumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Classification", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);

        String Classification = sp.getString("MainClass", null) + ", " + sp.getString("SecClass", null) + ", "
                + sp.getString("ThirdClass", null) + ", " + sp.getString("FourthClass", "");

        insertCell(table1, Classification, Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Product/s:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Products", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Manner of Notification", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Notification", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Purpose of Inspection", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Inspection", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Registered Pharmacist / Authorized Representative / Person", Element.ALIGN_LEFT, 4,
                "#8EBAFF", 1, 0);
        insertCell(table1, "Name", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PharmacistName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Reg. No. (PRC-ID)", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcID", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Date Issued", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcDateIssued", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Validity", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcValidity", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Position", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PharmacistPosition", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Person/s Interviewed", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("InterviewedName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Position", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("InterviewedPosition", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "License to Operate", Element.ALIGN_LEFT, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTONumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Renewal", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTORenewalDate", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Validity", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTOValidity", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Payment of Appropriate Fee", Element.ALIGN_LEFT, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "OR Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("ORNum", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Amount", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, "Php " + sp.getString("ORAmount", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Date of Payment", Element.ALIGN_LEFT, 0, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("ORDate", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "RSN", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 1);
        insertCell(table1, sp.getString("RSN", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 1);
        doc.add(table1);

        footer();

        // 2nd Page
        doc.newPage();
        FDALetterhead();

        PdfPTable table2 = new PdfPTable(1);
        table2.setWidthPercentage(110f);
        table2.setSpacingAfter(20f);
        insertCell(table2, "Observation Findings:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell1(table2, sp.getString("ObservationFindings", ""), 1, 1, 600f);
        doc.add(table2);
        footer();

        // 3rd Page
        doc.newPage();
        FDALetterhead();

        PdfPTable table3 = new PdfPTable(1);
        table3.setWidthPercentage(110f);
        table3.setSpacingAfter(20f);

        insertCell(table3, "Directives:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 1);

        nested(table3, 0.1f, 2f, R.string.directives1, sp.getBoolean("Directives1", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives2, sp.getBoolean("Directives2", false), Element.ALIGN_LEFT);
        nested(table3, 0.2f, 2f, R.string.directives3, sp.getBoolean("Directives3", false),
                Element.ALIGN_RIGHT);
        nested(table3, 0.2f, 2f, R.string.directives4, sp.getBoolean("Directives4", false),
                Element.ALIGN_RIGHT);
        nested(table3, 0.1f, 2f, R.string.directives5, sp.getBoolean("Directives5", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives6, sp.getBoolean("Directives6", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives7, sp.getBoolean("Directives7", false), Element.ALIGN_LEFT);

        String Directives8 = getResources().getString(R.string.directives8);
        PdfPCell cellDirectives8 = new PdfPCell(new Paragraph(Font.TIMES_ROMAN, Directives8));
        cellDirectives8.setPaddingLeft(50);
        cellDirectives8.setPaddingTop(5);
        cellDirectives8.setPaddingBottom(5);
        cellDirectives8.setPaddingRight(5);
        cellDirectives8.setBorderWidthTop(0);
        cellDirectives8.setBorderWidthBottom(0);
        table3.addCell(cellDirectives8);

        String Directives = sp.getString("Directives8", null);
        boolean Directives9 = false, Directives10 = false;
        if (Directives.equals(R.string.directives9)) {
            Directives9 = true;
            Directives10 = false;
        } else if (Directives.equals(R.string.directives10)) {
            Directives9 = false;
            Directives10 = true;
        } else {
            Directives9 = false;
            Directives10 = false;
        }

        nested(table3, 0.3f, 2f, R.string.directives9, Directives9, Element.ALIGN_RIGHT);
        nested(table3, 0.3f, 2f, R.string.directives10, Directives10, Element.ALIGN_RIGHT);

        insertCell(table3, "Inspected By:", Element.ALIGN_CENTER, 1, "#8EBAFF", 1, 0);

        PdfPTable signature1 = new PdfPTable(2);

        sig(signature1, "FDRO1");
        sig(signature1, "FDRO2");

        insertCell(signature1, sp.getString("FDRO1", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, sp.getString("FDRO2", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, "Food-Drug Regulation Officer", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Food-Drug Regulation Officer", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Date: " + dateStarted, Element.ALIGN_LEFT, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Time: " + timeS, Element.ALIGN_LEFT, 1, "#FFFFFF", 1, 0);

        sig(signature1, "EstRep1");
        sig(signature1, "EstRep2");
        insertCell(signature1, sp.getString("EstRep1", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, sp.getString("EstRep2", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, "Establishments Representative", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);
        insertCell(signature1, "Establishments Representative", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);

        PdfPCell nesthousing1 = new PdfPCell(signature1);
        table3.addCell(nesthousing1);

        doc.add(table3);
        footer();

        // 4th Page
        doc.newPage();
        FDALetterhead();
        PdfPTable table4 = new PdfPTable(1);
        table4.setWidthPercentage(110f);
        table4.setSpacingAfter(20f);

        insertCell(table4, "(FDA USE ONLY)", Element.ALIGN_CENTER, 1, "#8EBAFF", 1, 1);
        insertCell(table4, "Compliance Made by the Company", Element.ALIGN_LEFT, 1, "#FFFFFF", 0, 0);
        nested(table4, 0.1f, 2f, R.string.CAPA, false, Element.ALIGN_LEFT);
        nested(table4, 0.2f, 2f, R.string.Accepted, false, Element.ALIGN_RIGHT);
        nested(table4, 0.2f, 2f, R.string.NotAccepted, false, Element.ALIGN_RIGHT);
        insertCell(table4, "Recommendation (to Licensing) :", Element.ALIGN_LEFT, 1, "#FFFFFF", 0, 0);
        insertCell1(table4, "", 0, 0, 100f);

        PdfPTable signature2 = new PdfPTable(2);

        insertCell1(signature2, "", 0, 0, 50f);
        insertCell1(signature2, "", 0, 0, 50f);

        insertCell(signature2, "Print Name & Signature of FDRO/s", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature2, "Date", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);

        insertCell(signature2, "Reviewed by:", Element.ALIGN_LEFT, 2, "#8EBAFF", 1, 1);

        insertCell1(signature2, "", 0, 0, 50f);
        insertCell1(signature2, "", 0, 0, 50f);

        insertCell(signature2, "Print Name & Signature of Team Leader/Supervisor", Element.ALIGN_CENTER, 1,
                "#FFFFFF", 1, 1);
        insertCell(signature2, "Date", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);

        PdfPCell nesthousing2 = new PdfPCell(signature2);
        table4.addCell(nesthousing2);

        doc.add(table4);
        footer();

    } catch (DocumentException de) {
        Log.e("PDFCreator", "DocumentException:" + de);
    } catch (FileNotFoundException e) {
        Log.e("PDFCreator", "ioException:" + e);
    } finally {
        doc.close();
    }
}

From source file:tztBackoffice.Print.java

private void print(File path, JTable table) {
    // het document vormaat wort aangemaakt
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter writer;//  w w w  .j  a v  a 2  s. c  o m
    try {
        // check eidigt op .pdf
        String pathd = "" + paths;
        if (!pathd.endsWith(".pdf")) {
            writer = PdfWriter.getInstance(document, new FileOutputStream(path + ".pdf"));
        } else {
            writer = PdfWriter.getInstance(document, new FileOutputStream(path));
        }
        // het document wordt geopend
        document.open();
        // de writer wordt aangemaakt
        PdfContentByte cb = writer.getDirectContent();
        // de staat wordt opgeslagen
        cb.saveState();
        // graphics worden aangemaakt
        Graphics2D g2 = cb.createGraphics(500, 500);
        // de clip wordt weggeschreven
        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 500, 500);

        // de tabel wordt geprint in de graphics
        table.print(g2);
        g2.setClip(oldClip);

        // graphics word gesloten
        g2.dispose();
        cb.restoreState();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage() + "Er is een fout opgetreden");
    } finally {
        document.close();
    }
}

From source file:UI.ImageList.java

private void print() {
    Document document = new Document(PageSize.A4.rotate());
    try {//from ww w.ja  va  2  s  . c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("jTable.pdf"));

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.saveState();
        Graphics2D g2 = cb.createGraphicsShapes(500, 500);

        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 500, 500);

        jTable1.print(g2);
        g2.setClip(oldClip);

        g2.dispose();
        cb.restoreState();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java

private void saveAsPdfBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsPdfBtnActionPerformed
    Document document = new Document(PageSize.A4.rotate());
    String[] headers = new String[] { "Name", "TimeStamp", "Resp Rate", "Heart Rate", "Blood Pressure",
            "Temperature", "Status" };
    String filename = fileNameTxt.getText();
    try {/*  w  w  w . java 2  s .c  o  m*/
        if (!filename.equals("")) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));

            document.open();
            PdfContentByte cb = writer.getDirectContent();

            cb.saveState();
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 8, Font.BOLD)));
                table.addCell(cell);

            }
            table.completeRow();

            table.spacingBefore();
            table.spacingAfter();
            document.add(table);
            Graphics2D g2 = cb.createGraphicsShapes(500, 500);
            //cb.showTextAligned(PdfContentByte.ALIGN_CENTER, g2, 200, 300, 0);

            Shape oldClip = g2.getClip();
            g2.clipRect(0, 0, 700, 500);

            vitalSignjTable.print(g2);
            g2.setClip(oldClip);

            g2.dispose();
            cb.restoreState();
            JOptionPane.showMessageDialog(null, "file saved", "Saved", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "enter the filename", "FileName", JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:util.PDFconverter.java

public static void createPDF(String[] header, String[][] data, String path, String tittle,
        float[] columnWidths) {
    try {//from w w  w . j  a  v a2s  .c o  m
        Document doc = new Document();

        PdfWriter.getInstance(doc, new FileOutputStream(path));

        doc.open();
        doc.setPageSize(PageSize.A4);
        doc.setMargins(10, 10, 10, 10);
        Font litle = new Font(Font.COURIER, 7, Font.NORMAL);
        Font norm = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
        Font normBold = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
        Font TitleFont = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);

        doc.add(Chunk.NEWLINE);
        Paragraph judul = new Paragraph(tittle, TitleFont);
        judul.setAlignment(Element.ALIGN_CENTER);
        doc.add(judul);

        //          Paragraph tgl = new Paragraph("tanggal " + tanggal + "\n", TitleFont);            
        //          tgl.setAlignment(Element.ALIGN_CENTER);
        //          doc.add(tgl);
        doc.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(header.length);
        table.setWidthPercentage(100f);

        for (String head : header) {
            table.addCell(new PdfPCell(new Phrase(head, normBold)));
        }

        for (String[] obj : data) {
            for (int i = 0; i < header.length; i++) {
                table.addCell(new PdfPCell(new Phrase(obj[i], norm)));
            }

        }

        //float[] columnWidths = new float[] {10f, 20f, 30f, 10f};
        table.setWidths(columnWidths);

        doc.add(table);

        //            Paragraph stamp = new Paragraph(new Chunk("this report has generated with QCMS by " + System.getProperty("user.name") + " on " + new Date(), litle));
        //            stamp.setAlignment(Element.ALIGN_BOTTOM);
        //            stamp.setAlignment(Element.ALIGN_CENTER);
        //            doc.add(stamp);
        //
        //            Paragraph tanda = new Paragraph(new Chunk("Mengetahui,", norm));
        //            tanda.setSpacingBefore(100);
        //            tanda.setAlignment(Element.ALIGN_RIGHT);
        //            tanda.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(tanda);
        //
        //            Paragraph nama = new Paragraph(new Chunk("MANAGER Dept.RnQ", norm));
        //            nama.setSpacingBefore(30);
        //            nama.setAlignment(Element.ALIGN_RIGHT);
        //            nama.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(nama);
        doc.close();
    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(PDFconverter.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:view.ViewCodigobarras.java

public void gerarCodigoBarras(ArrayList<String> pListaCodigos) {

    System.out.println("Barcode Linha de Cdigo ");

    // criando um objeto da classe Document
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {//w  w w. j  a  va  2s . c om

        //Aqui comeamos a utilizar as classes do iText: o documento
        //criado acima ser
        //direcionado para um arquivo PDF.
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("C://Codigo_Barra_Java_Linha_Codigo.pdf"));

        //abrindo o documento.
        document.open();

        //adicionando um novo paragrafo.
        for (int i = 0; i < pListaCodigos.size(); i++) {
            document.add(new Paragraph("CDIGOS DE BARRA"));

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

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

            //Comecando a configurar o cod de barras
            PdfContentByte cb = writer.getDirectContent();

            BarcodeEAN codeEAN = new BarcodeEAN();

            //O iText suporta os principais tipos de cdigo de barra, como Barcode39,
            //  Barcode128 (128, 128_UCC, 128_RAW),  BarcodeEAN (EAN13, EAN8, UPCA, UPCE), EANSUP, etc
            if (jcbTipoCodigo.getSelectedItem().toString() == "EAN13") {
                codeEAN.setCodeType(codeEAN.EAN13);
            } else if ("EAN8".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.EAN8);
            } else if ("UPCA".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.UPCA);
            } else if ("UPCE".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.UPCE);
            }

            codeEAN.setCode("1234567890123");

            Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);

            document.add(new Phrase(new Chunk(imageEAN, 0, 0)));
        }
        //abrir o arquivo
        File file = new File("C://Codigo_Barra_Java_Linha_Codigo.pdf");
        try {
            Desktop.getDesktop().open(file);
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, e);
        }
        file.deleteOnExit();

    } catch (Exception de) {
        de.printStackTrace();

    }
    document.close();

}

From source file:views.HacerPedido.java

private void print() {
    Document document = new Document(PageSize.A4.rotate());
    String username = System.getProperty("user.name");

    //String filepath = "/Users/alejandro/NetBeansProjects/QRGenerator/qrCode.png";
    String filepath = "/Users/" + username + "/Desktop/jajasaludosss.pdf";
    try {//from   w  w  w  . jav a  2s . c o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filepath));

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.saveState();
        Graphics2D g2 = cb.createGraphicsShapes(500, 500);

        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 500, 500);

        tablaPedidos.print(g2);
        g2.setClip(oldClip);

        g2.dispose();
        cb.restoreState();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:vistas.reportes.procesos.rptAsistenciaEntrada.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*  ww  w.j  a v a 2  s .c om*/
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.HELVETICA, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONTROL DE ASISTENCIA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("FECHA: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.HELVETICA, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaInicio, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.HELVETICA, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptAsistenciaEntrada().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:vistas.reportes.procesos.rptAsistenciaTotal.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario, boolean isSelectedComp, boolean isSelectedHoraM)
        throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*from   w ww . j  a va  2 s.c  o m*/
    Image cabecera = Image.getInstance("img/cabecera.png");
    cabecera.setAlignment(1);
    documento.add(cabecera);
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "DEPENDENCIA:      ";
    } else if (tipo == "G") {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    } else if (tipo == "P") {
        nombreGrupoOficina = "DEPENDENCIA:      ";
    }
    Font font = new Font(Font.HELVETICA, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONTROL DE ASISTENCIA",
            new Font(Font.HELVETICA, 12, Font.BOLD));
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelFechaInicio = new Chunk("FECHA INICIO:        ", font);
    Chunk labelFechaFin = new Chunk("       FECHA FIN: ", font);
    //Chunk labelUsuario = new Chunk("USUARIO: ",font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.HELVETICA, 10));
    Chunk nombreFechaInicio = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaInicio, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreFechaFin = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaFin, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    //Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.HELVETICA,10));

    Paragraph pNombreReporte = new Paragraph(nombreReporte);
    pNombreReporte.setAlignment(1);
    documento.add(pNombreReporte);
    documento.add(ReporteUtil.darEspaciado(25));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    if (tipo == "P") {
        Chunk labelDniEmpleado = new Chunk("DNI:                           ", font);
        Chunk labelNombreEmpleado = new Chunk("NOMBRE:                ", font);
        Empleado empleado = ec.buscarPorDni(dnis.get(0));
        Chunk nombreDni = new Chunk(empleado.getNroDocumento(), new Font(Font.HELVETICA, 10));
        Chunk nombreEmpleado = new Chunk(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno()
                + " " + empleado.getNombre(), new Font(Font.HELVETICA, 10));
        documento.add(new Paragraph(ReporteUtil.unirChunks(labelNombreEmpleado, nombreEmpleado)));
        documento.add(ReporteUtil.darEspaciado(15));
        documento.add(new Paragraph(ReporteUtil.unirChunks(labelDniEmpleado, nombreDni)));
        documento.add(ReporteUtil.darEspaciado(15));
    }
    documento.add(new Paragraph(
            ReporteUtil.unirChunks(labelFechaInicio, nombreFechaInicio, labelFechaFin, nombreFechaFin)));
    documento.add(ReporteUtil.darEspaciado(15));

    //documento.add(new Paragraph(ReporteUtil.unirChunks(labelFechaFin,nombreFechaFin)));
    //documento.add(ReporteUtil.darEspaciado(15));
    //documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario,nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptAsistenciaTotal().crearTabla(dnis, fechaInicio, fechaFin, isSelectedComp,
            isSelectedHoraM, tipo);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}