com.lowagie.text.pdf.PdfRectangle Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfRectangle. 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: FieldPositioningEvents.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
@Override
public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) {
	rect.setBottom(rect.getBottom() - 3);
	PdfFormField field = (PdfFormField) genericChunkFields.get(text);
	if (field == null) {
		TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
		tf.setFontSize(14);
		try {
			field = tf.getTextField();
		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}
	} else {
		field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	}
	if (parent == null) {
		writer.addAnnotation(field);
	} else {
		parent.addKid(field);
	}
}
 
Example #2
Source File: FieldPositioningEvents.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
public void onGenericTag(PdfWriter writer, Document document,
		Rectangle rect, String text) {
	rect.setBottom(rect.getBottom() - 3);
	PdfFormField field = (PdfFormField) genericChunkFields.get(text);
	if (field == null) {
		TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
		tf.setFontSize(14);
		try {
			field = tf.getTextField();
		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}
	}
	else {
		field.put(PdfName.RECT,  new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	}
	if (parent == null)
		writer.addAnnotation(field);
	else
		parent.addKid(field);
}
 
Example #3
Source File: PolygonAnnotation.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static PdfRectangle createRec( final float[] coords ) {
  float minX = Integer.MAX_VALUE;
  float maxX = Integer.MIN_VALUE;
  float minY = Integer.MAX_VALUE;
  float maxY = Integer.MIN_VALUE;

  for ( int i = 0; i < coords.length; i += 2 ) {
    float x = coords[i];
    float y = coords[i + 1];
    if ( x < minX ) {
      minX = x;
    }
    if ( y < minY ) {
      minY = y;
    }

    if ( x > maxX ) {
      maxX = x;
    }
    if ( y > maxY ) {
      maxY = y;
    }
  }
  return new PdfRectangle( minX, minY, maxX, maxY );
}
 
Example #4
Source File: FieldPositioningEvents.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
 *      com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
	if (cellField == null || fieldWriter == null && parent == null) {
		throw new ExceptionConverter(new IllegalArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."));
	}
	cellField.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	if (parent == null) {
		fieldWriter.addAnnotation(cellField);
	} else {
		parent.addKid(cellField);
	}
}
 
Example #5
Source File: FieldPositioningEvents.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
	if (cellField == null || (fieldWriter == null && parent == null)) throw new ExceptionConverter(new IllegalArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."));
	cellField.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	if (parent == null)
		fieldWriter.addAnnotation(cellField);
	else
		parent.addKid(cellField);
}
 
Example #6
Source File: PdfAnnotationsImp.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
	PdfArray array = new PdfArray();
	int rotation = pageSize.getRotation() % 360;
	int currentPage = writer.getCurrentPageNumber();
	for (int k = 0; k < annotations.size(); ++k) {
		PdfAnnotation dic = (PdfAnnotation) annotations.get(k);
		int page = dic.getPlaceInPage();
		if (page > currentPage) {
			delayedAnnotations.add(dic);
			continue;
		}
		if (dic.isForm()) {
			if (!dic.isUsed()) {
				HashMap templates = dic.getTemplates();
				if (templates != null) {
					acroForm.addFieldTemplates(templates);
				}
			}
			PdfFormField field = (PdfFormField) dic;
			if (field.getParent() == null) {
				acroForm.addDocumentField(field.getIndirectReference());
			}
		}
		if (dic.isAnnotation()) {
			array.add(dic.getIndirectReference());
			if (!dic.isUsed()) {
				PdfRectangle rect = (PdfRectangle) dic.get(PdfName.RECT);
				if (rect != null) {
					switch (rotation) {
						case 90:
							dic.put(PdfName.RECT, new PdfRectangle(pageSize.getTop() - rect.bottom(), rect.left(), pageSize.getTop() - rect.top(), rect.right()));
							break;
						case 180:
							dic.put(PdfName.RECT, new PdfRectangle(pageSize.getRight() - rect.left(), pageSize.getTop() - rect.bottom(), pageSize.getRight() - rect.right(), pageSize.getTop() - rect.top()));
							break;
						case 270:
							dic.put(PdfName.RECT, new PdfRectangle(rect.bottom(), pageSize.getRight() - rect.left(), rect.top(), pageSize.getRight() - rect.right()));
							break;
					}
				}
			}
		}
		if (!dic.isUsed()) {
			dic.setUsed();
			try {
				writer.addToBody(dic, dic.getIndirectReference());
			} catch (IOException e) {
				throw new ExceptionConverter(e);
			}
		}
	}
	return array;
}
 
Example #7
Source File: PdfAnnotationsImp.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
    PdfArray array = new PdfArray();
    int rotation = pageSize.getRotation() % 360;
    int currentPage = writer.getCurrentPageNumber();
    for (int k = 0; k < annotations.size(); ++k) {
        PdfAnnotation dic = (PdfAnnotation)annotations.get(k);
        int page = dic.getPlaceInPage();
        if (page > currentPage) {
            delayedAnnotations.add(dic);
            continue;
        }
        if (dic.isForm()) {
            if (!dic.isUsed()) {
                HashMap templates = dic.getTemplates();
                if (templates != null)
                    acroForm.addFieldTemplates(templates);
            }
            PdfFormField field = (PdfFormField)dic;
            if (field.getParent() == null)
                acroForm.addDocumentField(field.getIndirectReference());
        }
        if (dic.isAnnotation()) {
            array.add(dic.getIndirectReference());
            if (!dic.isUsed()) {
                PdfRectangle rect = (PdfRectangle)dic.get(PdfName.RECT);
                if (rect != null) {
                	switch (rotation) {
                    	case 90:
                    		dic.put(PdfName.RECT, new PdfRectangle(
                    				pageSize.getTop() - rect.bottom(),
						rect.left(),
						pageSize.getTop() - rect.top(),
						rect.right()));
                    		break;
                    	case 180:
                    		dic.put(PdfName.RECT, new PdfRectangle(
                    				pageSize.getRight() - rect.left(),
						pageSize.getTop() - rect.bottom(),
						pageSize.getRight() - rect.right(),
						pageSize.getTop() - rect.top()));
                    		break;
                    	case 270:
                    		dic.put(PdfName.RECT, new PdfRectangle(
                    				rect.bottom(),
						pageSize.getRight() - rect.left(),
						rect.top(),
						pageSize.getRight() - rect.right()));
                    		break;
                	}
                }
            }
        }
        if (!dic.isUsed()) {
            dic.setUsed();
            try {
                writer.addToBody(dic, dic.getIndirectReference());
            }
            catch (IOException e) {
                throw new ExceptionConverter(e);
            }
        }
    }
    return array;
}