<
groupId
>
org.apache.poi
</
groupId
>
<
artifactId
>
poi-scratchpad
</
artifactId
>
<
version
>
4.1.1
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.lowagie
</
groupId
>
<
artifactId
>
itext
</
artifactId
>
<
version
>
2.1.7
</
version
>
</
dependency
>
复制代码
2、java实现
if(fileName.endsWith("ppt")){
resObj = upload(file,flag)
FilesUtil f = new FilesUtil()
String pptPath = resObj.get("msg").toString()
String[] pptArr = pptPath.split(".ppt")
String arr = pptArr[0]
List<String> result = converPPTtoImage(pptPath, arr+"/", "jpg", 8)
resObj.put("msg",FILE_PATH + fileName.substring(0, fileName.lastIndexOf("."))+".pdf")
resObj.put("fileName",fileName.substring(0, fileName.lastIndexOf("."))+".pdf")
f.imageToPdf(result,FILE_PATH + fileName.substring(0, fileName.lastIndexOf("."))+".pdf")
复制代码
public File imageToPdf(List<String> imageUrllist, String mOutputPdfFileName) {
Document doc = new Document(PageSize.A4, 20, 20, 20, 20)
try {
PdfWriter.getInstance(doc, new FileOutputStream(mOutputPdfFileName))
doc.open()
for (int i = 0
doc.newPage()
Image png1 = Image.getInstance(imageUrllist.get(i))
float heigth = png1.getHeight()
float width = png1.getWidth()
int percent = getPercent2(heigth, width)
png1.setAlignment(Image.MIDDLE)
png1.scalePercent(percent + 3)
doc.add(png1)
} catch (FileNotFoundException e) {
e.printStackTrace()
} catch (DocumentException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}finally {
doc.close()
File mOutputPdfFile = new File(mOutputPdfFileName)
if (!mOutputPdfFile.exists()) {
mOutputPdfFile.deleteOnExit()
return null
return mOutputPdfFile
private int getPercent2(float h, float w) {
int p = 0
float p2 = 0.0f
p2 = 530 / w * 100
p = Math.round(p2)
return p
复制代码