Java Code Examples for com.lowagie.text.Image#setRotation()

The following examples show how to use com.lowagie.text.Image#setRotation() . 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: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates an Image object based on a list of properties.
 * 
 * @param attributes
 * @return an Image
 */
public static Image getImage(Properties attributes) throws BadElementException, MalformedURLException, IOException {
	String value;

	value = attributes.getProperty(ElementTags.URL);
	if (value == null) {
		throw new MalformedURLException("The URL of the image is missing.");
	}
	Image image = Image.getInstance(value);

	value = attributes.getProperty(ElementTags.ALIGN);
	int align = 0;
	if (value != null) {
		if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(value)) {
			align |= Image.LEFT;
		} else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(value)) {
			align |= Image.RIGHT;
		} else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(value)) {
			align |= Image.MIDDLE;
		}
	}
	if ("true".equalsIgnoreCase(attributes.getProperty(ElementTags.UNDERLYING))) {
		align |= Image.UNDERLYING;
	}
	if ("true".equalsIgnoreCase(attributes.getProperty(ElementTags.TEXTWRAP))) {
		align |= Image.TEXTWRAP;
	}
	image.setAlignment(align);

	value = attributes.getProperty(ElementTags.ALT);
	if (value != null) {
		image.setAlt(value);
	}

	String x = attributes.getProperty(ElementTags.ABSOLUTEX);
	String y = attributes.getProperty(ElementTags.ABSOLUTEY);
	if (x != null && y != null) {
		image.setAbsolutePosition(Float.parseFloat(x + "f"), Float.parseFloat(y + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINWIDTH);
	if (value != null) {
		image.scaleAbsoluteWidth(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINHEIGHT);
	if (value != null) {
		image.scaleAbsoluteHeight(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.ROTATION);
	if (value != null) {
		image.setRotation(Float.parseFloat(value + "f"));
	}
	return image;
}
 
Example 2
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates an Image object based on a list of properties.
 * @param attributes
 * @return an Image
 */
public static Image getImage(Properties attributes)
		throws BadElementException, MalformedURLException, IOException {
	String value;

	value = attributes.getProperty(ElementTags.URL);
	if (value == null)
		throw new MalformedURLException("The URL of the image is missing.");
	Image image = Image.getInstance(value);

	value = attributes.getProperty(ElementTags.ALIGN);
	int align = 0;
	if (value != null) {
		if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(value))
			align |= Image.LEFT;
		else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(value))
			align |= Image.RIGHT;
		else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(value))
			align |= Image.MIDDLE;
	}
	if ("true".equalsIgnoreCase(attributes
			.getProperty(ElementTags.UNDERLYING)))
		align |= Image.UNDERLYING;
	if ("true".equalsIgnoreCase(attributes
			.getProperty(ElementTags.TEXTWRAP)))
		align |= Image.TEXTWRAP;
	image.setAlignment(align);

	value = attributes.getProperty(ElementTags.ALT);
	if (value != null) {
		image.setAlt(value);
	}

	String x = attributes.getProperty(ElementTags.ABSOLUTEX);
	String y = attributes.getProperty(ElementTags.ABSOLUTEY);
	if ((x != null) && (y != null)) {
		image.setAbsolutePosition(Float.parseFloat(x + "f"), Float
				.parseFloat(y + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINWIDTH);
	if (value != null) {
		image.scaleAbsoluteWidth(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINHEIGHT);
	if (value != null) {
		image.scaleAbsoluteHeight(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.ROTATION);
	if (value != null) {
		image.setRotation(Float.parseFloat(value + "f"));
	}
	return image;
}
 
Example 3
Source File: RotatingTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Rotating images.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("rotating.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add content
	Image jpg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	jpg.setAlignment(Image.MIDDLE);

	jpg.setRotation((float) Math.PI / 6);
	document.add(new Paragraph("rotate 30 degrees"));
	document.add(jpg);
	document.newPage();

	jpg.setRotation((float) Math.PI / 4);
	document.add(new Paragraph("rotate 45 degrees"));
	document.add(jpg);
	document.newPage();

	jpg.setRotation((float) Math.PI / 2);
	document.add(new Paragraph("rotate pi/2 radians"));
	document.add(jpg);
	document.newPage();

	jpg.setRotation((float) (Math.PI * 0.75));
	document.add(new Paragraph("rotate 135 degrees"));
	document.add(jpg);
	document.newPage();

	jpg.setRotation((float) Math.PI);
	document.add(new Paragraph("rotate pi radians"));
	document.add(jpg);
	document.newPage();

	jpg.setRotation((float) (2.0 * Math.PI));
	document.add(new Paragraph("rotate 2 x pi radians"));
	document.add(jpg);

	// step 5: we close the document
	document.close();
}