本文整理汇总了Java中com.lowagie.text.Image.setRotationDegrees方法的典型用法代码示例。如果您正苦于以下问题:Java Image.setRotationDegrees方法的具体用法?Java Image.setRotationDegrees怎么用?Java Image.setRotationDegrees使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.setRotationDegrees方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printImage
import com.lowagie.text.Image; //导入方法依赖的package包/类
/** Print an iText image */
private void printImage(Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws DocumentException {
if(image!=null) {
float boxWidth = Math.abs(x2-x1)+1;
float boxHeight = Math.abs(y2-y1)+1;
log.debug("Print Image (Size w="+image.getPlainWidth()+",h="+image.getPlainHeight()+") wthin BOX (w="+boxWidth+",h="+boxHeight+") FitMethod = "+fitMethod);
// Clip the image based on the bounding box
if(fitMethod==FIT_METHOD_CLIP) {
if( (boxWidth < image.getPlainWidth()) || (boxHeight < image.getPlainHeight()) ) {
// @TODO - Clip image
log.warn("IMAGE CLIPPING REQUIRED, but not implemented - default to 'SCALE'...");
fitMethod=FIT_METHOD_SCALE;
}
}
// Stretch/shrink both the X/Y to fit the bounding box
if(fitMethod==FIT_METHOD_FILL) {
log.debug("Scale image to fill box");
image.scaleToFit(x2-x1, y2-y1);
}
// Stretch/shrink preserving the aspect ratio to fit the bounding box
if(fitMethod==FIT_METHOD_SCALE) {
float multipler = Math.min(boxWidth / image.getPlainWidth(), boxHeight /image.getPlainHeight());
log.debug("Need to scale image by " + (Math.floor(multipler*10000)/100) + "%");
image.scalePercent(multipler*100);
}
log.debug("Print image at (" + x1 + "," + y1 +")");
image.setAbsolutePosition(x1,y1);
image.setRotationDegrees(rotate);
cb.addImage(image);
//Phrase text = new Phrase(new Chunk(image, 0, 0));
//ColumnText ct = new ColumnText(cb);
//ct.setSimpleColumn(text, x1, y1, x2, y2, 10, alignment);
//ct.go();
}
}
示例2: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* General example using cell events.
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf"));
// step3
document.open();
// step4
CellEventsTest event = new CellEventsTest();
Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
im.setRotationDegrees(30);
PdfPTable table = new PdfPTable(4);
table.addCell("text 1");
PdfPCell cell = new PdfPCell(im, true);
cell.setCellEvent(event);
table.addCell(cell);
table.addCell("text 3");
im.setRotationDegrees(0);
table.addCell(im);
table.setTotalWidth(300);
PdfContentByte cb = writer.getDirectContent();
table.writeSelectedRows(0, -1, 50, 600, cb);
table.setHeaderRows(3);
document.add(table);
// step5
document.close();
}
示例3: addTextVertical
import com.lowagie.text.Image; //导入方法依赖的package包/类
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception {
if (text==null) return;
if (text.indexOf("<span")>=0)
text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
Font font = PdfFont.getFont(bold);
BaseFont bf = font.getBaseFont();
float width = bf.getWidthPoint(text, font.getSize());
PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
template.beginText();
template.setColorFill(Color.BLACK);
template.setFontAndSize(bf, font.getSize());
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(font.getSize() + 2);
//make an Image object from the template
Image img = Image.getInstance(template);
img.setRotationDegrees(270);
//embed the image in a Chunk
Chunk ck = new Chunk(img, 0, 0);
if (cell.getPhrase()==null) {
cell.setPhrase(new Paragraph(ck));
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
} else {
cell.getPhrase().add(ck);
}
}
示例4: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* PdfTemplates can be wrapped in an Image.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Rectangle rect = new Rectangle(PageSize.A4);
rect.setBackgroundColor(new Color(238, 221, 88));
Document document = new Document(rect, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.NOT_EMBEDDED);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
template.sanityCheck();
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
Chunk ck = new Chunk(img, 0, 0);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
Paragraph p1 = new Paragraph("This is a template ");
p1.add(ck);
p1.add(" just here.");
p1.setLeading(img.getScaledHeight() * 1.1f);
document.add(p1);
document.add(table);
Paragraph p2 = new Paragraph("More templates ");
p2.setLeading(img.getScaledHeight() * 1.1f);
p2.setAlignment(Element.ALIGN_JUSTIFIED);
img.scalePercent(70);
for (int k = 0; k < 20; ++k)
p2.add(ck);
document.add(p2);
// step 5: we close the document
document.close();
}
示例5: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Generates a StudentCard
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Rectangle rect = new Rectangle(243, 153);
rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
Document document = new Document(rect, 10, 10, 10, 10);
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf"));
// step 3: we open the document
document.open();
// step 4:
Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE);
Paragraph p = new Paragraph("Ghent University", font);
p.setAlignment(Element.ALIGN_CENTER);
document.add(p);
PdfContentByte cb = writer.getDirectContent();
Font f = FontFactory.getFont(FontFactory.HELVETICA, 8);
PdfPTable outertable = new PdfPTable(3);
outertable.setTotalWidth(200);
outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
float[] outer = { 60, 25, 15 };
outertable.setWidths(outer);
PdfPTable innertable = new PdfPTable(2);
float[] inner = { 35, 65 };
innertable.setWidths(inner);
innertable.addCell(new Paragraph("name:", f));
innertable.addCell(new Paragraph("Bruno Lowagie", f));
innertable.addCell(new Paragraph("date of birth:", f));
innertable.addCell(new Paragraph("June 10th, 1970", f));
innertable.addCell(new Paragraph("Study Program:", f));
innertable.addCell(new Paragraph("master in civil engineering", f));
innertable.addCell(new Paragraph("option:", f));
innertable.addCell(new Paragraph("architecture", f));
outertable.addCell(innertable);
outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg"));
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("8010012529736");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
imageEAN.setRotationDegrees(90);
outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
outertable.addCell(imageEAN);
outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());
// step 5: we close the document
document.close();
}
示例6: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Example with vertical text in Cells.
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("VerticalText.pdf"));
// step3
document.open();
// step4
// make a PdfTemplate with the vertical text
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
// make an Image object from the template
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
document.add(table);
// step5
document.close();
}