当前位置: 首页>>代码示例>>Java>>正文


Java Image.setAnnotation方法代码示例

本文整理汇总了Java中com.lowagie.text.Image.setAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java Image.setAnnotation方法的具体用法?Java Image.setAnnotation怎么用?Java Image.setAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.Image的用法示例。


在下文中一共展示了Image.setAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
 * Adds some annotated images to a PDF file.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2:
	// we create a writer that listens to the document
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("annotated_images.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: we add some content
	Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	jpeg.setAnnotation(new Annotation("picture", "This is my dog", 0, 0, 0, 0));
	jpeg.setAbsolutePosition(100f, 550f);
	document.add(jpeg);
	Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
	wmf.setAnnotation(new Annotation(0, 0, 0, 0, "http://www.lowagie.com/iText"));
	wmf.setAbsolutePosition(100f, 200f);
	document.add(wmf);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:27,代码来源:AnnotatedImageTest.java

示例2: addImage

import com.lowagie.text.Image; //导入方法依赖的package包/类
protected void addImage(Image img) throws EmptyStackException {
    // if there is an element on the stack...
    Object current = stack.pop();
    // ...and it's a Chapter or a Section, the Image can be
    // added directly
    if (current instanceof Chapter
            || current instanceof Section
            || current instanceof Cell) {
        ((TextElementArray) current).add(img);
        stack.push(current);
        return;
    }
    // ...if not, we need to to a lot of stuff
    else {
        Stack newStack = new Stack();
        while (!(current instanceof Chapter
                || current instanceof Section || current instanceof Cell)) {
            newStack.push(current);
            if (current instanceof Anchor) {
                img.setAnnotation(new Annotation(0, 0, 0,
                        0, ((Anchor) current).getReference()));
            }
            current = stack.pop();
        }
        ((TextElementArray) current).add(img);
        stack.push(current);
        while (!newStack.empty()) {
            stack.push(newStack.pop());
        }
        return;
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:33,代码来源:SAXiTextHandler.java

示例3: main

import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
 * Creates documents with some simple annotations.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document1 = new Document(PageSize.A4, 10, 10, 10, 10);
	Document document2 = new Document(PageSize.A4, 10, 10, 10, 10);

	// step 2:
	PdfWriter writer1 = PdfWriter.getInstance(document1, PdfTestBase.getOutputStream("SimpleAnnotations1.pdf"));
	PdfWriter writer2 = PdfWriter.getInstance(document2, PdfTestBase.getOutputStream("SimpleAnnotations2.pdf"));
	// step 3:
	writer2.setPdfVersion(PdfWriter.VERSION_1_5);
	document1.open();
	document2.open();
	// step 4:
	document1.add(new Paragraph("Each square on this page represents an annotation."));
	// document1
	PdfContentByte cb1 = writer1.getDirectContent();
	Annotation a1 = new Annotation("authors",
			"Maybe it's because I wanted to be an author myself that I wrote iText.", 250f, 700f, 350f, 800f);
	document1.add(a1);
	Annotation a2 = new Annotation(250f, 550f, 350f, 650f, new URL("http://www.lowagie.com/iText/"));
	document1.add(a2);
	Annotation a3 = new Annotation(250f, 400f, 350f, 500f, "http://www.lowagie.com/iText");
	document1.add(a3);
	Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.gif");
	image.setAnnotation(a3);
	document1.add(image);
	Annotation a4 = new Annotation(250f, 250f, 350f, 350f, PdfAction.LASTPAGE);
	document1.add(a4);
	// draw rectangles to show where the annotations were added
	cb1.rectangle(250, 700, 100, 100);
	cb1.rectangle(250, 550, 100, 100);
	cb1.rectangle(250, 400, 100, 100);
	cb1.rectangle(250, 250, 100, 100);
	cb1.stroke();
	// more content
	document1.newPage();
	for (int i = 0; i < 5; i++) {
		document1.add(new Paragraph("blahblahblah"));
	}
	document1.add(new Annotation("blahblah", "Adding an annotation without specifying coordinates"));
	for (int i = 0; i < 3; i++) {
		document1.add(new Paragraph("blahblahblah"));
	}
	document1.newPage();
	document1.add(new Chunk("marked chunk").setLocalDestination("mark"));
	
	File videoFile = new File(PdfTestBase.RESOURCES_DIR + "cards.mpg");
	File license = new File("LICENSE");

	// document2
	document2.add(new Paragraph("Each square on this page represents an annotation."));
	PdfContentByte cb2 = writer2.getDirectContent();
	Annotation a5 = new Annotation(100f, 700f, 200f, 800f, videoFile.getAbsolutePath(), "video/mpeg", true);
	document2.add(a5);
	Annotation a6 = new Annotation(100f, 550f, 200f, 650f, "SimpleAnnotations1.pdf", "mark");
	document2.add(a6);
	Annotation a7 = new Annotation(100f, 400f, 200f, 500f, "SimpleAnnotations1.pdf", 2);
	document2.add(a7);
	Annotation a8 = new Annotation(100f, 250f, 200f, 350f, license.getAbsolutePath(), null, null, null);
	document2.add(a8);
	// draw rectangles to show where the annotations were added
	cb2.rectangle(100, 700, 100, 100);
	cb2.rectangle(100, 550, 100, 100);
	cb2.rectangle(100, 400, 100, 100);
	cb2.rectangle(100, 250, 100, 100);
	cb2.stroke();

	// step 5: we close the document
	document1.close();
	document2.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:78,代码来源:SimpleAnnotationsTest.java


注:本文中的com.lowagie.text.Image.setAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。