Code Monkey home page Code Monkey logo

spring-boot-pdf's Introduction

Build Status

Spring Boot生成PDF文档

通过Spring Boot实现PDF文件导出功能,PDF文件生成使用itext的第三方库。集成freemarker使用,可以直接从html文件生成对应内容的pdf,这样就可以将pdf文件的视图和数据分离。这里还使用了AbstractView,通过ModelAndView的方式就可以下载PDF。

依赖的包

  • spring-boot 加载Spring MVC
  • Freemarker 生成html文本
  • itext 生成PDF
  • JUnit 进行单元测试
    dependencies {
        // tag::jetty[]
        compile("org.springframework.boot:spring-boot-starter-web") {
            exclude module: "spring-boot-starter-tomcat"
        }
        compile("org.springframework.boot:spring-boot-starter-jetty")
        // end::jetty[]
        // tag::actuator[]
        compile("org.springframework.boot:spring-boot-starter-actuator")
        compile("org.springframework.boot:spring-boot-starter-aop")
        compile("org.springframework:spring-context-support")
    
        compile	'com.itextpdf:itextpdf:5.5.8'
        compile	'com.itextpdf:itext-asian:5.2.0'
        compile	'com.itextpdf.tool:xmlworker:5.5.9'
    
        compile	'org.freemarker:freemarker:2.3.23'
        compile 'javax.servlet:javax.servlet-api:3.1.0'
    
        testCompile (group: 'junit', name: 'junit', version: '4.12')
        testCompile("org.springframework.boot:spring-boot-starter-test")
    }

运行相关

通过执行gradle bootRun来运行Spring Boot,运行起来之后,访问http://localhost:8888/download查看结果。

spring-boot-pdf's People

Contributors

liuwill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spring-boot-pdf's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.