/**
* 将图片转换成pdf文件
*imgFilePath 需要被转换的img所存放的位置。 例如imgFilePath="D:\\projectPath\\";
*pdfFilePath 转换后的pdf所存放的位置 例如pdfFilePath="D:\\projectPath\\";
* @param image
* @return
* @throws IOException
*/
public boolean imgToPdf(String imgFilePath, String pdfFilePath)throws IOException {
File file=new File(imgFilePath);
if(()){
Document document = new Document();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(pdfFilePath);
(document, fos);
// 添加PDF文档的某些信息,比如作者,主题等等
("arui");
("test pdf.");
// 设置文档的大小
(PageSize.A4);
// 打开文档
();
// 写入一段文字
//(new Paragraph("JUST TEST ..."));
// 读取一个图片
Image image = (imgFilePath);
float imageHeight=();
float imageWidth=();
int i=0;
while(imageHeight>500||imageWidth>500){
(100-i);
i++;
imageHeight=();
imageWidth=();
("imageHeight->"+imageHeight);
("imageWidth->"+imageWidth);
}
(Image.ALIGN_CENTER);
//
//设置图片的绝对位置
//
(0, 0);
//
(500, 400);
// 插入一个图片
(image);
} catch (DocumentException de) {
(());
} catch (IOException ioe) {
(());
}
();
();
();
return true;
}else{
return false;
}
}