excel有多个sheet,用openoffice转化成pdf后。第一个sheet和第二个sheet之间出现几页空白。还有最后一个sheet后面也有几页空白。
不给你听
最近登录:2020/01/10 17:14
不给你听的其他提问
怎么在IE8下面兼容background-size
229 阅读
git 如何 删除文件
1K+ 阅读
linux下启动openoffice报错
1K+ 阅读
poi获取自适应高度之后的行高
3K+ 阅读
类似问题
用java将excel生成图片
1055 阅读
Linux下办公软件OpenOffice五大特点介绍
659 阅读
php 实例化 com失败
221 阅读
Linux办公一条龙之电子表格Calc(组图)
441 阅读
转换Office文档过慢,出现卡进程的情况
7543 阅读
java中,使用openoffice如何给pdf加密
530 阅读
如何实现odt转换成doc
3650 阅读
关于在不同的机器上调用openoffice服务的问题
6269 阅读
使用 OpenOffice 和 iText 生成 PDF
2686 阅读
出现空白的原因在于。excel中的某些行的内容长度超过了pdf页面的长度。只要注意一下excel中每一行的长度。就可以解决问题
1
public static File office2PDF_File(String sourceFile, String destFile) {
File file = null;
String OpenOffice_HOME = System.getProperty("openodffice.url");
if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '/') {
OpenOffice_HOME += "/";
}
Process pro = null;
try {
String command = OpenOffice_HOME
+ "program/soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"\"-nofirststartwizard\"";
pro = Runtime.getRuntime().exec(command);
OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
String outputFilePath = generateDefaultOutputFilePath(sourceFile);
File inputFile = new File(sourceFile);
if (inputFile.exists()) {
File outputFile = new File(outputFilePath);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
file = new File(destFile);
converter.convert(inputFile, outputFile);
}
connection.disconnect();
pro.destroy();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
pro.destroy();
}
return file;
}
用这个试试