Example usage for com.lowagie.text Rectangle getLeft

List of usage examples for com.lowagie.text Rectangle getLeft

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle getLeft.

Prototype

public float getLeft() 

Source Link

Document

Returns the lower left x-coordinate.

Usage

From source file:org.mapfish.print.config.layout.HeaderFooter.java

License:Open Source License

public void render(final Rectangle rectangle, PdfContentByte dc, PJsonObject params, RenderingContext context) {
    try {// ww  w  . j  a  v a 2s  .  co  m
        final PdfPTable table = PDFUtils.buildTable(items, params, context,
                1/*multiple items are arranged by lines*/, null);
        if (table != null) {
            table.setTotalWidth(rectangle.getWidth());
            table.writeSelectedRows(0, -1, rectangle.getLeft(), rectangle.getTop(), dc);
        }
    } catch (DocumentException e) {
        context.addError(e);
    }
}

From source file:org.mapfish.print.map.MapChunkDrawer.java

License:Open Source License

public void renderImpl(Rectangle rectangle, PdfContentByte dc) {
    final PJsonObject parent = context.getGlobalParams();
    PJsonArray layers = parent.getJSONArray("layers");
    String srs = parent.getString("srs");

    if (!context.getConfig().isScalePresent(transformer.getScale())) {
        throw new InvalidJsonValueException(params, "scale", transformer.getScale());
    }//from w  ww  . j a  v a2 s  . c  om

    Transformer mainTransformer = null;
    if (!Double.isNaN(overviewMap)) {
        //manage the overview map
        mainTransformer = context.getLayout().getMainPage().getMap().createTransformer(context, params);
        transformer.zoom(mainTransformer, (float) (1.0 / overviewMap));
        transformer.setRotation(0); //overview always north up!
        context.setStyleFactor((float) (transformer.getPaperW() / mainTransformer.getPaperW() / overviewMap));
        layers = parent.optJSONArray("overviewLayers", layers);
    }

    transformer.setMapPos(rectangle.getLeft(), rectangle.getBottom());
    if (rectangle.getWidth() < transformer.getPaperW() - 0.2) {
        throw new RuntimeException("The map width on the paper is wrong");
    }
    if (rectangle.getHeight() < transformer.getPaperH() - 0.2) {
        throw new RuntimeException("The map height on the paper is wrong (" + rectangle.getHeight() + "!="
                + transformer.getPaperH() + ")");
    }

    //create the readers/renderers
    List<MapReader> readers = new ArrayList<MapReader>(layers.size());
    for (int i = 0; i < layers.size(); ++i) {
        PJsonObject layer = layers.getJSONObject(i);
        if (mainTransformer == null || layer.optBool("overview", true)) {
            final String type = layer.getString("type");
            MapReader.create(readers, type, context, layer);
        }
    }

    //check if we cannot merge a few queries
    for (int i = 1; i < readers.size();) {
        MapReader reader1 = readers.get(i - 1);
        MapReader reader2 = readers.get(i);
        if (reader1.testMerge(reader2)) {
            readers.remove(i);
        } else {
            ++i;
        }

    }

    //draw some background
    if (backgroundColor != null) {
        dc.saveState();
        try {
            dc.setColorFill(backgroundColor);
            dc.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(),
                    rectangle.getHeight());
            dc.fill();
        } finally {
            dc.restoreState();
        }
    }

    //Do the rendering.
    //
    //Since we need to load tiles in parallel from the
    //servers, what follows is not trivial. We don't write directly to the PDF's
    //DirectContent, we always go through the ParallelMapTileLoader that will
    //make sure that everything is added to the PDF in the correct order.
    //
    //All uses of the DirectContent (dc) or the PDFWriter is forbiden outside
    //of renderOnPdf methods and when they are used, one must take a lock on
    //context.getPdfLock(). That is done for you when renderOnPdf is called, but not done
    //in the readTile method. That's why PDFUtils.getImage needs to do it when
    //creating the template.
    //
    //If you don't follow those rules, you risk to have random inconsistency
    //in your PDF files and/or infinite loops in iText.
    ParallelMapTileLoader parallelMapTileLoader = new ParallelMapTileLoader(context, dc);
    dc.saveState();
    try {
        final PdfLayer mapLayer = new PdfLayer(name, context.getWriter());
        transformer.setClipping(dc);

        //START of the parallel world !!!!!!!!!!!!!!!!!!!!!!!!!!!

        for (int i = 0; i < readers.size(); i++) {
            final MapReader reader = readers.get(i);

            //mark the starting of a new PDF layer
            parallelMapTileLoader.addTileToLoad(new MapTileTask.RenderOnly() {
                public void renderOnPdf(PdfContentByte dc) throws DocumentException {
                    PdfLayer pdfLayer = new PdfLayer(reader.toString(), context.getWriter());
                    mapLayer.addChild(pdfLayer);
                    dc.beginLayer(pdfLayer);
                }
            });

            //render the layer
            reader.render(transformer, parallelMapTileLoader, srs, i == 0);

            //mark the end of the PDF layer
            parallelMapTileLoader.addTileToLoad(new MapTileTask.RenderOnly() {
                public void renderOnPdf(PdfContentByte dc) throws DocumentException {
                    dc.endLayer();
                }
            });
        }
    } finally {
        //wait for all the tiles to be loaded
        parallelMapTileLoader.waitForCompletion();

        //END of the parallel world !!!!!!!!!!!!!!!!!!!!!!!!!!

        dc.restoreState();
    }

    if (mainTransformer != null) {
        //only for key maps: draw the real map extent
        drawMapExtent(dc, mainTransformer);
        context.setStyleFactor(1.0f);
    }
}

From source file:org.mapfish.print.scalebar.ScalebarDrawer.java

License:Open Source License

public void renderImpl(Rectangle rectangle, PdfContentByte dc) {
    dc.saveState();//from  www . j  a  v  a2s  .  co m
    try {
        //sets the transformation for drawing the labels and do it
        final AffineTransform rotate = getRotationTransform(block.getBarDirection());
        final AffineTransform labelTransform = AffineTransform.getTranslateInstance(rectangle.getLeft(),
                rectangle.getBottom());
        labelTransform.concatenate(rotate);
        labelTransform.translate(leftLabelMargin, maxLabelHeight);
        dc.transform(labelTransform);
        dc.setColorStroke(block.getColorVal());
        dc.setFontAndSize(pdfFont.getCalculatedBaseFont(false), pdfFont.getSize());
        drawLabels(dc);

        dc.restoreState();
        dc.saveState();

        //sets the transformation for drawing the bar and do it
        final AffineTransform lineTransform = AffineTransform.getTranslateInstance(rectangle.getLeft(),
                rectangle.getBottom());
        lineTransform.concatenate(rotate);
        lineTransform.translate(leftLabelMargin, labelDistance + maxLabelHeight);
        dc.transform(lineTransform);
        dc.setLineWidth((float) block.getLineWidth());
        dc.setColorStroke(block.getColorVal());
        drawBar(dc);
    } finally {
        dc.restoreState();
    }
}

From source file:org.revager.export.PDFCellEventExtRef.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
    PdfContentByte cb = canvas[PdfPTable.LINECANVAS];

    // cb.reset();

    Rectangle attachmentRect = new Rectangle(rect.getLeft() - 25, rect.getTop() - 25,
            rect.getRight() - rect.getWidth() - 40, rect.getTop() - 10);

    String fileDesc = file.getName() + " (" + translate("File Attachment") + ")";

    try {// w  ww . j a va 2 s . c  o m
        PdfAnnotation attachment = PdfAnnotation.createFileAttachment(writer, attachmentRect, fileDesc, null,
                file.getAbsolutePath(), file.getName());
        writer.addAnnotation(attachment);
    } catch (IOException e) {
        /*
         * just do not add a reference if the file was not found or another
         * error occured.
         */
    }

    // cb.setColorStroke(new GrayColor(0.8f));
    // cb.roundRectangle(rect.getLeft() + 4, rect.getBottom(),
    // rect.getWidth() - 8, rect.getHeight() - 4, 4);

    cb.stroke();
}

From source file:questions.ocg.AddOptionalWatermark.java

public static void main(String[] args) throws DocumentException, IOException {
    PdfReader reader = new PdfReader(RESOURCE);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
    Image image1 = Image.getInstance(IMAGE_PRINTED);
    Image image2 = Image.getInstance(IMAGE_NOT_PRINTED);
    PdfLayer watermark_printed = new PdfLayer("printed", stamper.getWriter());
    watermark_printed.setOn(false);/*from   ww  w.j ava2  s  . c om*/
    watermark_printed.setOnPanel(false);
    watermark_printed.setPrint("print", true);
    PdfLayer watermark_not_printed = new PdfLayer("not_printed", stamper.getWriter());
    watermark_not_printed.setOn(true);
    watermark_not_printed.setOnPanel(false);
    watermark_not_printed.setPrint("print", false);
    for (int i = 0; i < stamper.getReader().getNumberOfPages();) {
        PdfContentByte cb = stamper.getUnderContent(++i);
        Rectangle rectangle = stamper.getReader().getPageSizeWithRotation(i);
        cb.beginLayer(watermark_printed);
        float AbsoluteX = rectangle.getLeft() + (rectangle.getWidth() - image1.getPlainWidth()) / 2;
        float AbsoluteY = rectangle.getBottom() + (rectangle.getHeight() - image1.getPlainHeight()) / 2;
        image1.setAbsolutePosition(AbsoluteX, AbsoluteY);
        cb.addImage(image1);
        cb.endLayer();
        cb.beginLayer(watermark_not_printed);
        AbsoluteX = rectangle.getLeft() + (rectangle.getWidth() - image2.getPlainWidth()) / 2;
        AbsoluteY = rectangle.getBottom() + (rectangle.getHeight() - image2.getPlainHeight()) / 2;
        image2.setAbsolutePosition(AbsoluteX, AbsoluteY);
        cb.addImage(image2);
        cb.endLayer();
    }
    stamper.close();
}