- import java.io.IOException;
- import com.itextpdf.text.Rectangle;
- import com.itextpdf.text.DocumentException;
- import java.io.FileOutputStream;
- import com.itextpdf.text.Document;
- import com.itextpdf.text.Image;
- import com.itextpdf.text.pdf.PdfWriter;
- /**
- *
- * @Title ImageToPDF.java
- * @Package com.pde.pdp.ffc.util
- * @Description 文件转换工具 ImageToPDF
- * @date 2012-4-10下午02:57:54
- * @author guods
- * @version V1.0
- */
- public class ImageToPdf extends FileConvertUtilAbstract {
- public boolean convert(String imagePath,String filePath) {
- boolean result = false;
- Document document = null;
- Image image = null;
- try {
- image = Image.getInstance(imagePath);
- Rectangle ret = new Rectangle(image.getWidth() + 60,
- image.getHeight() + 60);
- document = new Document(ret, 30, 30, 30, 30);
- PdfWriter.getInstance(document, new FileOutputStream(filePath));
- document.setPageSize(ret);
- document.open();
- document.add(image);
- result = true;
- } catch (DocumentException de) {
- result = false;
- } catch (IOException ioe) {
- result = false;
- }finally{
- if(document!=null)
- document.close();
- }
- return result;
- }
- }
复制代码 |