Example usage for com.itextpdf.text Rectangle getBottom

List of usage examples for com.itextpdf.text Rectangle getBottom

Introduction

In this page you can find the example usage for com.itextpdf.text Rectangle getBottom.

Prototype

public float getBottom() 

Source Link

Document

Returns the lower left y-coordinate.

Usage

From source file:araword.classes.HeaderFooter.java

/**
 * Increase the page number./*from  ww w  .  j ava2s  .co m*/
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
@Override
public void onStartPage(PdfWriter writer, Document document) {
    pagenumber++;
    System.out.println("ON Start Page PDF");
    Rectangle rect = writer.getBoxSize("art");

    /* header     
    ColumnText.showTextAligned(writer.getDirectContent(),                      
            com.itextpdf.text.Element.ALIGN_RIGHT, header[0],
              rect.getRight(), rect.getTop(), 0);
     */
    Font font = new Font();
    font.setSize(8);
    if (G.licensePDF) {
        ColumnText.showTextAligned(writer.getDirectContent(), com.itextpdf.text.Element.ALIGN_CENTER,
                new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA")), font),
                (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
        ColumnText.showTextAligned(writer.getDirectContent(), com.itextpdf.text.Element.ALIGN_CENTER,
                new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA2")), font),
                (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 9, 0);
    }

}

From source file:at.laborg.briss.CropManager.java

License:Open Source License

private static void cropMultipliedFile(File source, CropJob cropJob)
        throws FileNotFoundException, DocumentException, IOException {

    PdfReader reader = new PdfReader(source.getAbsolutePath());
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(cropJob.getDestinationFile()));
    stamper.setMoreInfo(cropJob.getSourceMetaInfo());

    PdfDictionary pageDict;/*w ww.  j a  va 2 s  . c o  m*/
    int newPageNumber = 1;
    for (int origPageNumber = 1; origPageNumber <= cropJob.getSourcePageCount(); origPageNumber++) {
        SingleCluster cluster = cropJob.getClusterCollection().getSingleCluster(origPageNumber);

        // if no crop was selected do nothing
        if (cluster.getRatiosList().size() == 0) {
            newPageNumber++;
            continue;
        }

        for (Float[] ratios : cluster.getRatiosList()) {

            pageDict = reader.getPageN(newPageNumber);

            List<Rectangle> boxes = new ArrayList<Rectangle>();
            boxes.add(reader.getBoxSize(newPageNumber, "media"));
            boxes.add(reader.getBoxSize(newPageNumber, "crop"));
            int rotation = reader.getPageRotation(newPageNumber);

            Rectangle scaledBox = calculateScaledRectangle(boxes, ratios, rotation);

            PdfArray scaleBoxArray = new PdfArray();
            scaleBoxArray.add(new PdfNumber(scaledBox.getLeft()));
            scaleBoxArray.add(new PdfNumber(scaledBox.getBottom()));
            scaleBoxArray.add(new PdfNumber(scaledBox.getRight()));
            scaleBoxArray.add(new PdfNumber(scaledBox.getTop()));

            pageDict.put(PdfName.CROPBOX, scaleBoxArray);
            pageDict.put(PdfName.MEDIABOX, scaleBoxArray);
            // increment the pagenumber
            newPageNumber++;
        }
        int[] range = new int[2];
        range[0] = newPageNumber - 1;
        range[1] = cropJob.getSourcePageCount() + (newPageNumber - origPageNumber);
        SimpleBookmark.shiftPageNumbers(cropJob.getSourceBookmarks(), cluster.getRatiosList().size() - 1,
                range);
    }
    stamper.setOutlines(cropJob.getSourceBookmarks());
    stamper.close();
    reader.close();
}

From source file:at.laborg.briss.CropManager.java

License:Open Source License

private static Rectangle calculateScaledRectangle(List<Rectangle> boxes, Float[] ratios, int rotation) {
    if (ratios == null || boxes.size() == 0)
        return null;
    Rectangle smallestBox = null;
    // find smallest box
    float smallestSquare = Float.MAX_VALUE;
    for (Rectangle box : boxes) {
        if (box != null) {
            if (smallestBox == null) {
                smallestBox = box;//from  ww w  .j ava 2 s.  c  o m
            }
            if (smallestSquare > box.getWidth() * box.getHeight()) {
                // set new smallest box
                smallestSquare = box.getWidth() * box.getHeight();
                smallestBox = box;
            }
        }
    }
    if (smallestBox == null)
        return null; // no useable box was found

    // rotate the ratios according to the rotation of the page
    float[] rotRatios = rotateRatios(ratios, rotation);

    // use smallest box as basis for calculation
    Rectangle scaledBox = new Rectangle(smallestBox);

    scaledBox.setLeft(smallestBox.getLeft() + (smallestBox.getWidth() * rotRatios[0]));
    scaledBox.setBottom(smallestBox.getBottom() + (smallestBox.getHeight() * rotRatios[1]));
    scaledBox.setRight(smallestBox.getLeft() + (smallestBox.getWidth() * (1 - rotRatios[2])));
    scaledBox.setTop(smallestBox.getBottom() + (smallestBox.getHeight() * (1 - rotRatios[3])));

    return scaledBox;
}

From source file:at.laborg.briss.utils.DocumentCropper.java

License:Open Source License

private static PdfArray createScaledBoxArray(final Rectangle scaledBox) {
    PdfArray scaleBoxArray = new PdfArray();
    scaleBoxArray.add(new PdfNumber(scaledBox.getLeft()));
    scaleBoxArray.add(new PdfNumber(scaledBox.getBottom()));
    scaleBoxArray.add(new PdfNumber(scaledBox.getRight()));
    scaleBoxArray.add(new PdfNumber(scaledBox.getTop()));
    return scaleBoxArray;
}

From source file:com.chaschev.itext.CanvasBuilder.java

License:Apache License

public CanvasBuilder drawGrayRectangle(Rectangle rectangle, BaseColor color) {
    return saveState()
            .rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight())
            .setColorStroke(color).setLineWidth(0.1f).stroke().restoreState();
}

From source file:com.chaschev.itext.RectangleBuilder.java

License:Apache License

public RectangleBuilder copyPositionsFrom(Rectangle other) {
    rectangle.setLeft(other.getLeft());//from  ww w .j a  v  a 2  s . c  o  m
    rectangle.setRight(other.getRight());
    rectangle.setTop(other.getTop());
    rectangle.setBottom(other.getBottom());

    return this;
}

From source file:com.education.freelancer.MainActivity.java

private void setSignatureStamp(PdfStamper stamper, AcroFields acroFields, String signId) {
    String DIRECTORY = Environment.getExternalStorageDirectory().getPath() + "/DigitSign/";
    String StoredPath = DIRECTORY + signId + ".png";
    AcroFields.FieldPosition f = acroFields.getFieldPositions(signId).get(0);
    int page = f.page;
    Rectangle rect = f.position;
    File imgFile = new File(StoredPath);
    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    if (myBitmap == null) {
        return;//from w  w  w. j  av  a2 s  .c  o m
    }
    // myBitmap=getResizedBitmap(myBitmap,160);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    myBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    Image img = null;
    try {
        img = Image.getInstance(stream.toByteArray());
        img.scaleToFit(rect.getWidth(), rect.getHeight());
        img.setAbsolutePosition(rect.getLeft(), rect.getBottom());
        stamper.getOverContent(page).addImage(img);
        imgFile.delete();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.github.wolfposd.imsqti2pdf.HeaderFooter.java

License:Open Source License

private void pageNumberFooter(PdfWriter writer, Rectangle rect) {
    Chunk c = new Chunk(
            String.format(LocaleStrings.getString("page"), writer.getPageNumber(), _maximumPageNumber));
    c.setFont(new Font(FontFamily.HELVETICA, 10));
    Phrase pagephrase = new Phrase(c);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, pagephrase,
            rect.getRight() - 60, rect.getBottom() - 30, 0);
}

From source file:com.github.wolfposd.imsqti2pdf.HeaderFooter.java

License:Open Source License

private void sumSymboltoFooter(PdfWriter writer, Rectangle rect) {
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, _sumSymbol, rect.getLeft() - 10,
            rect.getBottom() - 30, 0);
}

From source file:com.planfeed.others.HeaderFooter.java

License:Apache License

public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, header, rect.getRight(),
            rect.getTop(), 0);/*from  w  ww .  j  av  a  2s  .c om*/

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase(String.format("page %d", pagenumber)), (rect.getLeft() + rect.getRight()) / 2,
            rect.getBottom() - 18, 0);
}