Example usage for com.itextpdf.text.pdf PdfRectangle PdfRectangle

List of usage examples for com.itextpdf.text.pdf PdfRectangle PdfRectangle

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfRectangle PdfRectangle.

Prototype

public PdfRectangle(float llx, float lly, float urx, float ury) 

Source Link

Usage

From source file:org.orbisgis.core_export.GeoSpatialPDF.java

License:Open Source License

/**
 * This method is used to georeference the pdf.
 * Note : The CRS is not yet supported.//from   www  .  jav  a2  s .  c o m
 *
 * @param writer
 * @param mt
 * @throws IOException
 * @throws DocumentException
 */
public void georefPdf(PdfWriter writer, MapTransform mt) throws IOException, DocumentException {

    PdfStructureTreeRoot tree = writer.getStructureTreeRoot();

    //the part of the document where maps are displayed
    float mapWidth = width;
    float mapHeight = height;
    float mapLX = 0;
    float mapLY = 0;

    //ViewPort Dictionary
    PdfDictionary viewPortDict = new PdfDictionary();
    viewPortDict.put(PdfName.TYPE, new PdfName("Viewport"));
    viewPortDict.put(PdfName.BBOX, new PdfRectangle(mapLX, mapLY, mapLX + mapWidth, mapLY + mapHeight));
    viewPortDict.put(PdfName.NAME, new PdfString("Layers"));

    //Measure dictionary
    PdfDictionary measureDict = new PdfDictionary();
    measureDict.put(PdfName.TYPE, new PdfName("Measure"));
    measureDict.put(PdfName.SUBTYPE, new PdfName("GEO"));

    //Bounds
    PdfArray bounds = new PdfArray();
    bounds.add(new PdfNumber(0));
    bounds.add(new PdfNumber(0));
    bounds.add(new PdfNumber(1));
    bounds.add(new PdfNumber(0));
    bounds.add(new PdfNumber(1));
    bounds.add(new PdfNumber(1));
    bounds.add(new PdfNumber(0));
    bounds.add(new PdfNumber(1));

    measureDict.put(new PdfName("Bounds"), bounds);

    //GPTS
    Envelope adjustedBbox = mt.getAdjustedExtent();

    if (!adjustedBbox.isNull()) {

        //ly lx ly ux uy ux uy lx
        PdfArray gptsTable = new PdfArray();
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMinY()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMinX()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMinY()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMaxX()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMaxY()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMaxX()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMaxY()).toString()));
        gptsTable.add(new PdfNumber(((Double) adjustedBbox.getMinX()).toString()));

        measureDict.put(new PdfName("GPTS"), gptsTable);

        //The CRS will be added when the mapcontext will support it.

        //            //GCS Geospatial Coordinate system
        //            PdfDictionary gcsDict = new PdfDictionary();
        //            if (context.getBbox().getCrs() != null) {
        //
        //                if (context.getBbox().getCrs().getType() != null) {
        //                    gcsDict.put(PdfName.TYPE, new PdfName(context.getBbox().getCrs().getType()));
        //                } else {
        //                    LOGGER.warn("No type of crs : the pdf cannot be georeferenced");
        //                    return;
        //                }
        //
        //                if (context.getBbox().getCrs().getEpsg() != 0) {
        //                    gcsDict.put(new PdfName("EPSG"), new PdfNumber(context.getBbox().getCrs().getEpsg()));
        //                } else {
        //                    LOGGER.warn("No epsg : the pdf cannot be georeferenced");
        //                    return;
        //                }
        //
        //
        //            } else {
        //                LOGGER.warn("No crs :  the pdf cannot be georeferenced");
        //
        //            }
        //
        //            measureDict.put(new PdfName("GCS"), gcsDict);
    } else {
        LOGGER.warn("Envelope of bbox null : the pdf cannot be georeferenced");

    }

    //PDU : array of units
    PdfArray pdu = new PdfArray();
    pdu.add(new PdfName("KM"));
    pdu.add(new PdfName("SQKM"));
    pdu.add(new PdfName("DEG"));

    measureDict.put(new PdfName("PDU"), pdu);

    //LPTS
    PdfArray lptsTable = new PdfArray();
    lptsTable.add(new PdfNumber(0));
    lptsTable.add(new PdfNumber(0));
    lptsTable.add(new PdfNumber(1));
    lptsTable.add(new PdfNumber(0));
    lptsTable.add(new PdfNumber(1));
    lptsTable.add(new PdfNumber(1));
    lptsTable.add(new PdfNumber(0));
    lptsTable.add(new PdfNumber(1));

    measureDict.put(new PdfName("LPTS"), lptsTable);

    viewPortDict.put(new PdfName("Measure"), measureDict);

    PdfStructureElement top = new PdfStructureElement(tree, new PdfName("VP"));
    top.putAll(viewPortDict);
}

From source file:org.sejda.impl.itext5.CropTask.java

License:Open Source License

private Set<PdfRectangle> getPdfRectangles(Set<RectangularBox> areas) {
    Set<PdfRectangle> retVal = new LinkedHashSet<PdfRectangle>();
    for (RectangularBox box : areas) {
        retVal.add(new PdfRectangle(box.getLeft(), box.getBottom(), box.getRight(), box.getTop()));
    }//from   w  ww .  ja v a2s .c o m
    return retVal;
}