java创建空的PDF文件

创建空的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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值