GithubHelp home page GithubHelp logo

demo-pdf's People

Contributors

qusongtao 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  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  avatar  avatar  avatar  avatar

demo-pdf's Issues

dom解析慢的问题

楼主你好:
我在使用你这个开源项目的时候遇到了一个问题,就是我的ftl文件非常大,用你的Dom解析很慢,需要几十秒钟。您的代码如下:
`/**

  • 按模板和参数生成html字符串,再转换为flying-saucer识别的Document
  • @param templateName freemarker模板名称
  • @param variables freemarker模板参数
  • @return Document
    */
    private static Document generateDoc(FreeMarkerConfigurer configurer, String templateName,
    Map<String, Object> variables) {
    Template tp;
    try {
    tp = configurer.getConfiguration().getTemplate(templateName);
    } catch (IOException e) {
    LOGGER.error(e.getMessage(), e);
    return null;
    }
    StringWriter stringWriter = new StringWriter();
    try (BufferedWriter writer = new BufferedWriter(stringWriter)) {
    try {
    tp.process(variables, writer);
    writer.flush();
    } catch (TemplateException e) {
    LOGGER.error("模板不存在或者路径错误", e);
    } catch (IOException e) {
    LOGGER.error("IO异常", e);
    }
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(stringWriter.toString().getBytes()));
    } catch (Exception e) {
    LOGGER.error(e.getMessage(), e);
    return null;
    }
    }调用方式: Document doc = generateDoc(configurer, templateName, map);
    renderer.setDocument(doc, null); -----------------------我改用了如下方式---------------------StringWriter writer = new StringWriter();
    Template template = configurer.getConfiguration().getTemplate(templateName);
    template.process(map, writer);
    writer.flush();
    String html = writer.toString();
    renderer.setDocumentFromString(html);`
    解析时间缩短至 ms 级别。

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.