當前位置: 首頁>>代碼示例>>Java>>正文


Java Image.setRotation方法代碼示例

本文整理匯總了Java中com.lowagie.text.Image.setRotation方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.setRotation方法的具體用法?Java Image.setRotation怎麽用?Java Image.setRotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lowagie.text.Image的用法示例。


在下文中一共展示了Image.setRotation方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getImage

import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:58,代碼來源:ElementFactory.java

示例2: main

import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
 * 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();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:55,代碼來源:RotatingTest.java

示例3: addFooterAndWater

import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
 *	添加水印、頁眉、頁腳
 * @param fileName 源文件路徑
 * @param savepath 目標文件路徑
 * @param waterMarkName 文字水印
 * @param pageHeade 頁眉
 * @param foot 頁腳
 * @return
 */
public static int addFooterAndWater(String fileName, String savepath, String waterMarkName, String pageHeade, String foot) {
	// 文檔總頁數
	int num = 0;

	Document document = new Document();
	try {
		PdfReader reader = new PdfReader(fileName);
		//BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
		BaseFont base = BaseFont.createFont(BaseFont.COURIER, "utf-8", BaseFont.EMBEDDED);

		num = reader.getNumberOfPages();
		PdfCopy copy = new PdfCopy(document, new FileOutputStream(savepath));
		document.open();
		for (int i = 0; i < num;) {
			PdfImportedPage page = copy.getImportedPage(reader, ++i);
			PageStamp stamp = copy.createPageStamp(page);
			Font f = new Font(base);

			// 添加頁腳,左側文字,右側頁碼
			ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(String.format("第 %d 頁/共 %d 頁", i, num),
					f), 550f, 28, 0);
			ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_LEFT, new Phrase(foot, f), 50f, 28, 0);

			// 添加頁眉 (文字頁眉,居中)
			ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(pageHeade, f), 150f, 800, 0);

			// 頁眉添加logo (圖片頁眉,居右)
			Image img = Image.getInstance("F:\\Tools\\pdf2swf工具\\resource/watermark.png");//"template/logo.png");// 選擇圖片
			img.setAlignment(1);
			img.scaleAbsolute(436 / 5, 96 / 5);// 控製圖片大小
			img.setAbsolutePosition(450f, 800);// 控製圖片位置
			stamp.getUnderContent().addImage(img);

			// 添加水印
			PdfContentByte under = stamp.getUnderContent();
			under.beginText();
			under.setColorFill(Color.LIGHT_GRAY);

			// 字符越長,字體越小,設置字體
			int fontSize = getFontSize(waterMarkName);
			under.setFontAndSize(base, fontSize);

			// 設置水印文字字體傾斜 開始
			float pageWidth = reader.getPageSize(i).getWidth();
			float pageHeight = reader.getPageSize(i).getHeight();

			// 水印文字成60度角傾斜,且頁麵居中展示
			//under.showTextAligned(Element.ALIGN_CENTER, waterMarkName, pageWidth / 2, pageHeight / 2, 60);

			img.setAlignment(1);
			img.scaleAbsolute(636 / 5, 126 / 5);// 控製圖片大小
			img.setAbsolutePosition(pageWidth / 2, pageHeight / 2);// 控製圖片位置
			img.setRotation(60);
			stamp.getUnderContent().addImage(img);

			// 字體設置結束
			under.endText();
			stamp.alterContents();
			copy.addPage(page);
		}
	} catch (Exception e) {
		e.printStackTrace();
		return -1;
	} finally {
		if (null != document) {
			document.close();
		}
	}
	System.out.println("pdf totalpages:" + num);
	return num;

}
 
開發者ID:pecker,項目名稱:kony-converter,代碼行數:82,代碼來源:OfficeToPdf.java


注:本文中的com.lowagie.text.Image.setRotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。