Java Code Examples for com.itextpdf.text.Rectangle#setTop()

The following examples show how to use com.itextpdf.text.Rectangle#setTop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnifiedPagesizeMerging.java    From testarea-itext5 with GNU Affero General Public License v3.0 5 votes vote down vote up
Rectangle enhanceBy(Rectangle source, Rectangle addition)
{
    Rectangle result = new Rectangle(source);
    if (addition.getLeft() < result.getLeft())
        result.setLeft(addition.getLeft());
    if (addition.getRight() > result.getRight())
        result.setRight(addition.getRight());
    if (addition.getBottom() < result.getBottom())
        result.setBottom(addition.getBottom());
    if (addition.getTop() > result.getTop())
        result.setTop(addition.getTop());
    return result;
}
 
Example 2
Source File: CropManager.java    From Briss-2.0 with GNU General Public License v3.0 5 votes vote down vote up
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;
            }
            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;
}
 
Example 3
Source File: RectangleHandler.java    From Briss-2.0 with GNU General Public License v3.0 5 votes vote down vote up
public static Rectangle calculateScaledRectangle(final List<Rectangle> boxes, final Float[] ratios, final 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;
            }
            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;
}
 
Example 4
Source File: RemoveHeaderFooter.java    From testarea-itext5 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/32448118/issue-in-removing-header-and-footer-in-pdf-using-itext-pdf">
 * Issue in Removing Header and Footer in PDF using iText PDF
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/xznwx4ogemsgd42/spec.pdf?dl=0">
 * spec.pdf
 * </a>
 * <p>
 * removes header and footer based on the configuration
 * </p>
 * <p>
 * This is the original code by the OP whith minor changes to render it runnable
 * in this testarea project.
 * </p>
 * <p>
 * Issues observed on landscape pages of the test file can be prevented by using
 * <code>stamper.setRotateContents(false)</code>, see below.
 * </p>
 */
public static void cleanUpContent(PdfReader reader,String targetPDFFile, float upperY, float lowerY, boolean highLightColor) throws Exception
{
    OutputStream outputStream = new FileOutputStream(targetPDFFile);
    PdfStamper stamper = new PdfStamper(reader, outputStream);
    //stamper.setRotateContents(false);
    List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();

    for (int i = 1; i <= reader.getNumberOfPages(); i++)
    {
        Rectangle pageRect = reader.getCropBox(i);  
        Rectangle headerRect= new Rectangle(pageRect);
        headerRect.setBottom(headerRect.getTop()-upperY);               
        Rectangle footerRect= new Rectangle(pageRect);
        footerRect.setTop(footerRect.getBottom()+lowerY);   

        if(highLightColor)
        {
            cleanUpLocations.add(new PdfCleanUpLocation(i, headerRect,BaseColor.GREEN));
            cleanUpLocations.add(new PdfCleanUpLocation(i, footerRect,BaseColor.GREEN));
        }
        else
        {
            cleanUpLocations.add(new PdfCleanUpLocation(i, headerRect));
            cleanUpLocations.add(new PdfCleanUpLocation(i, footerRect));
        }
    }   
    PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
    try
    {
        cleaner.cleanUp();
    }
    catch(Exception e)
    {
         e.printStackTrace();
    }

    stamper.close();
    reader.close();
    outputStream.flush();
    outputStream.close();
}