创建空的PDF文件
导入maven所需依赖,非maven项目就去百度找下jar包引进去
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.24</version>
</dependency>
创建一个CreatNullPDF.java类写入方法
/**
* 创建一个空的PDF
*/
// 需要下 apache pdfbox包和apache.commons.loggin乌,下载地址:http://pdfbox.apache.org/download.cgi 和 http://commons.apache.org/proper/commons-logging/download_logging.cgi
// 在本示例中下载使用的是:pdfbox-2.0.7.jar
// 将下载的pdfbox-2.0.7.jar添加到Eclipse项目依懒库中。
// 右键点击:"java_apache_pdf_box"->"Bulid Path"->"Add External Artchives...",然后选笃下载的"pdfbox-2.0.7.jar"和"commons-logging-1.2.jar"文件
public class CreatNullPDF {
public static void main(String args[]) throws IOException {
creatPDF("E:","abc");
}
public static boolean creatPDF(String url,String name){
boolean is=false;
try {
// Creating PDF document object
PDDocument document = new PDDocument();
// Add an empty page to it
document.addPage(new PDPage());
// Saving the document
document.save(url+"/"+name+".pdf");
System.out.println(name+"文件创建成功!");
// Closing the document
document.close();
is=true;
}catch (Exception e){
is=false;
System.out.println(name+"文件创建出错!");
}
return is;
}
}//原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/javaexamples/create_empty_pdf_document.html
原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/javaexamples/create_empty_pdf_document.html