本文整理汇总了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;
}
示例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();
}
示例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;
}