Example usage for com.lowagie.text Document setMarginMirroring

List of usage examples for com.lowagie.text Document setMarginMirroring

Introduction

In this page you can find the example usage for com.lowagie.text Document setMarginMirroring.

Prototype

public boolean setMarginMirroring(boolean marginMirroring) 

Source Link

Document

Set the margin mirroring.

Usage

From source file:beans.ManagedBeanProducto.java

License:Open Source License

public String CreatePdf() throws IOException, DocumentException {
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    //System.out.println(" test: "+extContext);
    //System.out.println(" esta es la ruta" + extContext.getRealPath("//pdfs//"));
    // step 1//from ww  w .j  a v a2  s .co  m
    String ruta_pdfs = extContext.getRealPath("//pdfs//");
    Document document = new Document(PageSize.A4);
    document.setMargins(5, 5, 25, 25);
    document.setMarginMirroring(true);

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(ruta_pdfs + "//CB" + Producto.getIdProducto() + ".pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    Paragraph Titulo = new Paragraph(
            "PRODUCTO : " + Producto.getNombreProducto().substring(14).toUpperCase() + "\n\n");
    Titulo.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(Titulo);

    // EAN 13
    // document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();

    codeEAN.setCode(CodigoBarrasFinal());
    String nombre_producto = "";
    if (Producto.getNombreProducto().length() >= 41) {
        nombre_producto = Producto.getNombreProducto().substring(14, 41);
    } else {
        nombre_producto = Producto.getNombreProducto().substring(14);
    }
    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // document.add(codeEAN.createImageWithBarcode(cb,Color.BLUE , Color.BLUE));
    // codeEAN.setGuardBars(false);

    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // codeEAN.setGuardBars(false);
    Image imagen = codeEAN.createImageWithBarcode(cb, null, null);
    imagen.scaleAbsolute(87, 45);
    //document.add(imagen);

    PdfPTable table = new PdfPTable(5);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    // table.setTotalWidth(1800);
    PdfPCell cell;
    Phrase nombre = new Phrase(nombre_producto.toUpperCase(),
            new Font(Font.COURIER, 5, Font.BOLD, Color.BLACK));

    cell = new PdfPCell();
    cell.addElement(nombre);
    //cell.addElement(new Chunk("\n"));
    cell.addElement(imagen);
    //cell.addElement(new Chunk("\n"));

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    // EAN 8 "6987";
    // String inicio ="345";
    //  int intermedio =1000+Producto.getIdProducto();
    //  String fin ="0";
    // document.add(new Paragraph(Producto.getNombreProducto(),new Font(Font.COURIER, 4, Font.NORMAL)));
    // codeEAN.setCodeType(Barcode.EAN8);
    // codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    // codeEAN.setCode(inicio.concat(intermedio+fin));
    // document.add(codeEAN.createImageWithBarcode(cb, null, null));
    document.close();

    return "codigo_barras_productos";
}

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private PageStats generatePDF(List<SongNode> songList, File outputFile) throws IOException, DocumentException {
    logger.info("Starting export to PDF file {}.", outputFile.getAbsolutePath());

    // Initialize Writer
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
    PageStats pageStats = new PageStats();
    writer.setPageEvent(pageStats);/*from  w  w w. j  ava  2 s .c om*/

    // Initialize document
    document.setPageSize(PageSize.A4);
    document.setMargins(35 * POINTS_PER_MM, 10 * POINTS_PER_MM, 7 * POINTS_PER_MM, 7 * POINTS_PER_MM);
    document.setMarginMirroring(true);

    document.open();

    // Add QR codes
    Element qrCodeSection = buildQrCodeSection();
    document.add(qrCodeSection);

    // Line separator
    document.add(verseSpacing);
    document.add(new LineSeparator());
    document.add(verseSpacing);

    // Build TOC
    Chunk tocTitle = new Chunk("SONG BOOK - TABLE OF CONTENTS", songTitleFont);
    tocTitle.setLocalDestination("TOC");
    document.add(new Paragraph(tocTitle));
    for (int i = 0; i < songList.size(); i++) {
        SongNode songNode = songList.get(i);
        int chapterNumber = i + 1;
        Chunk tocEntry = new Chunk(chapterNumber + ". " + songNode.getTitle(), textFont);
        tocEntry.setLocalGoto("SONG::" + chapterNumber);
        document.add(new Paragraph(tocEntry));
    }
    document.newPage();
    pageStats.setSectionLength("TOC", pageStats.getCurrentPage() - 1);

    // Build document
    for (int i = 0; i < songList.size(); i++) {
        // Get song node
        SongNode songNode = songList.get(i);

        // Mark song start
        int songStartPage = pageStats.getCurrentPage();

        // Write song
        document.add(buildChapter(songNode, i + 1));
        document.newPage();

        // Record song length
        pageStats.setSectionLength(songNode.getTitle(), pageStats.getCurrentPage() - songStartPage);
    }

    // Close document
    document.close();

    logger.info("COMPLETED export to PDF file {}.", outputFile.getAbsolutePath());

    return pageStats;
}

From source file:lmcpointofsalessystem.PDFCustomers.java

public PDFCustomers(String tblName) throws IOException {
    try {//from  www  .j  a v  a2  s. c o m
        LMCPointofSalesSystem connect = new LMCPointofSalesSystem();
        con = connect.con;
        st = connect.s;
        Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);

        PdfWriter.getInstance(document, new FileOutputStream(tblName + ".pdf"));
        document.open();
        Image image = Image.getInstance("src/lmcpointofsalessystem/Assets/header3.png");
        document.add(image);
        document.setMarginMirroring(true);

        PdfPTable newheaderTable;
        newheaderTable = getDatas(tblName);
        newheaderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        document.add(newheaderTable);
        document.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:lmcpointofsalessystem.PDFCustomersEmployee.java

public PDFCustomersEmployee(String tblName) throws IOException {
    try {/*from  w w  w.ja  va  2s  .  com*/
        LMCPointofSalesSystem connect = new LMCPointofSalesSystem();
        con = connect.con;
        st = connect.s;
        Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);

        PdfWriter.getInstance(document, new FileOutputStream(tblName + ".pdf"));
        document.open();
        Image image = Image.getInstance("src/lmcpointofsalessystem/Assets/header3.png");
        document.add(image);
        document.setMarginMirroring(true);

        PdfPTable newheaderTable;
        newheaderTable = getDatas(tblName);
        newheaderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        document.add(newheaderTable);
        document.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:lmcpointofsalessystem.PDFOrders.java

public PDFOrders(String tblName) throws IOException {
    try {// w w  w .  j  av a2  s .  c  o  m
        LMCPointofSalesSystem connect = new LMCPointofSalesSystem();
        con = connect.con;
        st = connect.s;
        Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);

        PdfWriter.getInstance(document, new FileOutputStream(tblName + ".pdf"));
        document.open();
        Image image = Image.getInstance("src/lmcpointofsalessystem/Assets/header3.png");
        document.add(image);
        document.setMarginMirroring(true);

        PdfPTable newheaderTable;
        newheaderTable = getDatas(tblName);
        newheaderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        document.add(newheaderTable);
        document.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex);
    }
}