Example usage for com.itextpdf.text.pdf PdfName NAME

List of usage examples for com.itextpdf.text.pdf PdfName NAME

Introduction

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

Prototype

PdfName NAME

To view the source code for com.itextpdf.text.pdf PdfName NAME.

Click Source Link

Document

A name

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 w  w  w.  java2 s .  co 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);
}