分类: Java
2010-10-11 14:00:09
package test.pdf; import java.awt.Color; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.Image; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfWriter; /** * * */ public class Simple5 { @SuppressWarnings("deprecation") public static void main(String[] args) throws DocumentException, IOException { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream("E:/HelloWorld.pdf")); doc.open(); doc.add(new Paragraph("image")); Image image = Image.getInstance("D:\\workspace\\fwk\\TestPdf\\src\\test\\pdf\\qq1.jpg"); //将图片设置为背景 image.setAlignment(Image.UNDERLYING); doc.add(image); Image image2 = Image.getInstance("D:\\workspace\\fwk\\TestPdf\\src\\test\\pdf\\qq2.jpg"); //设置图片的宽度 高度 image2.scaleAbsolute(50, 120); //设置图片在页面中的位置 image2.setAbsolutePosition(50, 200); doc.add(image2); Image image3 = Image.getInstance("D:\\workspace\\fwk\\TestPdf\\src\\test\\pdf\\qq3.jpg"); //设置图片的缩放百分比 image3.scalePercent(50); //设置图片的旋转角度 image3.setRotation(30); doc.add(image3); doc.close(); } }