Example usage for com.lowagie.text Document bottomMargin

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

Introduction

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

Prototype


public float bottomMargin() 

Source Link

Document

Returns the bottom margin.

Usage

From source file:biblivre3.administration.reports.BaseBiblivreReport.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    try {//from  w  w w .  j  av a2 s.  c o m
        Rectangle page = document.getPageSize();

        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(this.getText("REPORTS_HEADER")));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth((page.width() / 2) - document.leftMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable date = new PdfPTable(1);
        PdfPCell dateCell = new PdfPCell(new Paragraph(dateFormat.format(generationDate)));
        dateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        dateCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        dateCell.setBorder(Rectangle.BOTTOM);
        date.addCell(dateCell);
        date.setTotalWidth((page.width() / 2) - document.rightMargin());
        date.writeSelectedRows(0, -1, (page.width() / 2),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable foot = new PdfPTable(1);
        Chunk pageNumber = new Chunk(String.valueOf(document.getPageNumber()));
        pageNumber.setFont(footerFont);
        cell = new PdfPCell(new Paragraph(pageNumber));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:br.org.acessobrasil.silvinha.util.HeaderAndFooter.java

License:Open Source License

/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 *///w  ww.ja  v a2 s. co m
public void onEndPage(PdfWriter writer, Document document) {

    try {
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(GERAL.RELATORIOS_ASES));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
        PdfPTable foot = new PdfPTable(1);
        cell = new PdfPCell(new Paragraph(String.valueOf(document.getPageNumber())));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:com.aryjr.nheengatu.pdf.PDFPageBreak.java

License:Open Source License

public PDFPageBreak(final PdfWriter writer, final Document document, final Tag headFirstPageTag,
        final Tag footFirstPageTag, final Tag headTag, final Tag footTag) throws DocumentException {
    this.headFirstPageTag = headFirstPageTag;
    this.footFirstPageTag = footFirstPageTag;
    this.headTag = headTag;
    this.footTag = footTag;

    final Rectangle page = document.getPageSize();
    if (headTag != null) {
        final PDFTable pdft = createTable(writer, document, headTag);
        pdft.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        headHeight = pdft.getTotalHeight();
    }//from  ww  w  .  jav  a2s  .c  om
    if (footTag != null) {
        final PDFTable pdft = createTable(writer, document, footTag);
        pdft.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        footHeight = pdft.getTotalHeight();
    }
    if (headFirstPageTag != null) {
        final PDFTable pdft = createTable(writer, document, headFirstPageTag);
        pdft.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        headFirstPageHeight = pdft.getTotalHeight();
    }
    if (footFirstPageTag != null) {
        final PDFTable pdft = createTable(writer, document, footFirstPageTag);
        pdft.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        footFirstPageHeight = pdft.getTotalHeight();
    }

    topMargin = document.topMargin();
    bottomMargin = document.bottomMargin();
    document.setMargins(document.leftMargin(), document.rightMargin(), topMargin + headFirstPageHeight,
            bottomMargin + footFirstPageHeight);

}

From source file:com.krawler.spring.exportFuctionality.ExportinvController.java

License:Open Source License

private static void addHeaderFooter(Document document, PdfWriter writer)
        throws DocumentException, ServiceException {
    fontSmallRegular.setColor(Color.BLACK);
    java.util.Date dt = new java.util.Date();
    String date = "yyyy-MM-dd";
    java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(date);
    String DateStr = dtf.format(dt);
    PdfPTable footer = new PdfPTable(1);
    PdfPCell footerSeparator = new PdfPCell(new Phrase(""));
    footerSeparator.setBorder(PdfPCell.BOX);
    footerSeparator.setPadding(0);/*from  w  w w .  j a  va  2s . com*/
    footerSeparator.setColspan(3);
    footer.addCell(footerSeparator);

    String PageDate = DateStr;
    PdfPCell pagerDateCell = new PdfPCell(new Phrase("Generated Date : " + PageDate, fontSmallRegular));
    pagerDateCell.setBorder(0);
    pagerDateCell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    footer.addCell(pagerDateCell);
    // -------- footer end   -----------
    try {
        Rectangle page = document.getPageSize();
        footer.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        footer.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:com.krawler.spring.exportFuctionality.ExportRecord.java

License:Open Source License

private void addHeaderFooter(Document document, PdfWriter writer) throws DocumentException, ServiceException {
    PdfPTable footer = new PdfPTable(1);
    PdfPCell footerSeparator = new PdfPCell(new Paragraph("THANK YOU FOR YOUR BUSINESS!", fontTblMediumBold));
    footerSeparator.setHorizontalAlignment(Element.ALIGN_CENTER);
    footerSeparator.setBorder(0);/*w  w  w.  j a v  a  2s. co  m*/
    footer.addCell(footerSeparator);

    try {
        Rectangle page = document.getPageSize();
        footer.setTotalWidth(page.getWidth() - document.leftMargin());
        footer.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:CPS.Core.TODOLists.PDFExporter.java

License:Open Source License

private Document prepareDocument(String filename, final String title, final String author, final String creator,
        final Rectangle pageSize) {

    System.out.println("DEBUG(PDFExporter): Creating document: " + filename);

    Document d = new Document();

    d.setPageSize(pageSize);/*  www.j a va 2s.  com*/
    // TODO alter page orientation?  maybe useful for seed order worksheet

    d.addTitle(title);
    d.addAuthor(author);
    //        d.addSubject( );
    //        d.addKeywords( );
    d.addCreator(creator);

    // left, right, top, bottom - scale in points (~72 points/inch)
    d.setMargins(35, 35, 35, 44);

    try {
        PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(filename));
        // add header and footer
        writer.setPageEvent(new PdfPageEventHelper() {
            public void onEndPage(PdfWriter writer, Document document) {
                try {
                    Rectangle page = document.getPageSize();

                    PdfPTable head = new PdfPTable(3);
                    head.getDefaultCell().setBorderWidth(0);
                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    head.addCell(new Phrase(author, fontHeadFootItal));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    head.addCell(new Phrase(title, fontHeadFootReg));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    head.addCell("");

                    head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                    head.writeSelectedRows(0, -1, document.leftMargin(),
                            page.getHeight() - document.topMargin() + head.getTotalHeight(),
                            writer.getDirectContent());

                    PdfPTable foot = new PdfPTable(3);

                    foot.getDefaultCell().setBorderWidth(0);
                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    foot.addCell(new Phrase(creator, fontHeadFootItal));

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    foot.addCell("");

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    foot.addCell(new Phrase("Page " + document.getPageNumber(), fontHeadFootReg));

                    foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                    foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                            writer.getDirectContent());
                } catch (Exception e) {
                    throw new ExceptionConverter(e);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

    return d;
}

From source file:cz.incad.kramerius.rest.api.k5.client.pdf.PDFResource.java

License:Open Source License

private static StreamingOutput streamingOutput(final File file, final String format) {
    return new StreamingOutput() {
        public void write(OutputStream output) throws IOException, WebApplicationException {
            try {
                Rectangle formatRect = formatRect(format);
                Document document = new Document(formatRect);
                PdfWriter.getInstance(document, output);
                document.open();//w  ww.  jav  a 2  s .  c  om

                Image image = Image.getInstance(file.toURI().toURL());

                image.scaleToFit(
                        document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(),
                        document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin());
                document.add(image);

                document.close();

            } catch (Exception e) {
                throw new WebApplicationException(e);
            } finally {
                if (file != null)
                    file.delete();
            }
        }
    };
}

From source file:dinamica.AbstractPDFOutput.java

License:LGPL

/**
 * Calcula si una tabla (mas un espacio extra) cabe en lo que queda de pagina.
 * Este metodo compensa la desaparicion del metodo fitsPage que IText tenia
 * hasta la version 2.0.6, y es necesario en reportes tipo master/detail o parent/child,
 * fue necesario crear este metodo para poder usar el ultimo IText (v2.1.2).
 * @param doc Document ya inicializado/*from  w w  w  .j av  a 2  s .  com*/
 * @param docWriter PdfWriter ya inicializado
 * @param tbl La tabla, su ancho debe haber sido definido con setTotalWidth, es decir usando
 * un ancho absoluto, no porcentajes, de otro modo este metodo no hara un calculo correcto, por
 * una limitacion de IText.
 * @param extra Espacio extra para el calculo si se desea, sino pase cero.
 * @return
 */
protected boolean fitsPage(Document doc, PdfWriter docWriter, PdfPTable tbl, int extra) {

    float a = tbl.getTotalHeight() + extra;
    float b = doc.bottom(doc.bottomMargin());
    float c = docWriter.getVerticalPosition(true);

    return ((c - b) > a);

}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

private int saveSheet(Document document, int listCount, ReportModel model)
        throws DocumentException, IOException, SaveReportException {

    model.updatePages(0);/*from w  ww .  j a  v  a 2s . c  om*/

    ReportPage pageFormat = model.getReportPage();
    Paper paper = pageFormat.getPaper();
    Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()),
            Math.round((float) paper.getHeight()));

    if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) {
        pageSize = pageSize.rotate();
    }
    document.setPageSize(pageSize);
    document.setMargins(Math.round((float) pageFormat.getLeftMargin(Units.PT)),
            Math.round((float) pageFormat.getRightMargin(Units.PT)),
            Math.round((float) pageFormat.getTopMargin(Units.PT)),
            Math.round((float) pageFormat.getBottomMargin(Units.PT)));
    Rectangle viewPageSize = new Rectangle(
            document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(),
            document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin());

    if (listCount > 0) {
        document.newPage();
    }
    listCount++;

    //float columnMargin = (float) Units.PT.setXPixels(model.getColumnModel().getColumnMargin());

    ReportPrintable printable = new ReportPrintable(model);
    int pageCount = printable.calcCountPage(model.getReportPage());
    Map<Integer, PageClip> clips = printable.getPageClips();

    int leftCol;
    int topRow;
    int rightCol;
    int bottomRow;

    for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
        PageClip pageClip = clips.get(pageIndex);
        if (pageClip == null)
            break;

        leftCol = pageClip.getLeftCol();
        rightCol = pageClip.getRightCol();

        topRow = pageClip.getTopRow();
        bottomRow = pageClip.getBottomRow();

        int columnCount = rightCol - leftCol;

        float[] widths = new float[columnCount + 1];
        widths[0] = 1;
        for (int c = 0; c < columnCount; c++) {
            ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c);
            widths[c + 1] = (float) Math.round(column.getNativeWidth());
        }

        PdfPTable table = createPdfTable(columnCount + 1, widths, viewPageSize);

        fillTable(model, leftCol, topRow, rightCol, bottomRow, table);

        document.add(table);

        if (pageIndex < clips.size()) {
            document.newPage();
        }

    }
    return listCount;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static void setPie(PdfWriter writer, Document document, String rep_pie) {
    try {/*  www.ja  v  a2  s.  c  o m*/
        PdfContentByte cb = writer.getDirectContent();
        /*cb.setLineWidth(2);
        cb.moveTo(60, document.bottomMargin()-5);
        cb.lineTo(document.right() - document.left()-70, document.bottomMargin()-5);
        */
        PdfPTable pie = new PdfPTable(1);
        pie.setTotalWidth(document.right() - document.left() - 120);
        pie.addCell(Addons.setCeldaPDF(rep_pie, Font.HELVETICA, 9, Font.BOLD, Element.ALIGN_CENTER, 0));
        pie.addCell(Addons.setCeldaPDF("Pg " + String.valueOf(writer.getPageNumber()), Font.HELVETICA, 9,
                Font.BOLD, Element.ALIGN_RIGHT, 0));
        pie.addCell(Addons.setCeldaPDF(
                "Reporte diseado por: Jorge Mueses Cevallos.      Mvil: 095204832     mail:jorge_mueses@yahoo.com",
                Font.HELVETICA, 5, Font.BOLD, Element.ALIGN_LEFT, 0));
        pie.writeSelectedRows(0, -1, 60, document.bottomMargin() - 10, cb);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}