x-easypdf v2.7.8 version released, new PDF converter

x-easypdf is based on the secondary encapsulation of pdfbox, which greatly reduces the threshold for use, and constructs pdf in a componentized form. Simple and easy to use, you can complete pdf related operations with only one line of code.

The contents of this update are as follows:

New features:

  1. Document replacer XEasyPdfDocumentReplacer optimizes text replacement logic
  2. Added pdf converter XEasyPdfConvertor, supports doc/docx/jpg/tiff/markdown/html/mhtml/rtf/odt/txt/mobi and other formats to convert to pdf, need to add aspose-words dependency
  3. Document XEasyPdfDocument adds a method to enable reset context
  4. The page XEasyPdfPage adds a new method to enable reset context

Original changes:

  1. The page parameter class XEasyPdfPageParam is changed to a private class

Bug fixes: none

New feature description:

This time, a new pdf converter, XEasyPdfConvertor, provides a series of conversion methods to pdf, which need to rely on aspose-words (change to a paid software, and a watermark will be generated when using the trial version), which can be combined with the method of text replacement to realize the conversion of word to pdf template. The function of template export can be realized by referring to the following methods:

1. Use word to make a template:

2. Use a pdf converter to convert to a pdf template (please handle the watermark yourself):

Add the repository and dependencies to the pom file:

<!--添加仓库-->
<repositories>
        <repository>
            <id>AsposeJavaAPI</id>
            <name>Aspose Java API</name>
            <url>https://repository.aspose.com/repo/</url>
        </repository>
</repositories>
<!--添加依赖-->
<dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words</artifactId>
        <version>22.4</version>
        <type>pom</type>
</dependency>

Conversion code:

// word源文件路径
String source = "C:\\Users\\Administrator\\Desktop\\test.doc";
// pdf文件路径
String dest = "C:\\Users\\Administrator\\Desktop\\test.pdf";
// 转换
XEasyPdfConvertor.toPdf(source, dest);

The effect is as follows:

3. Replace the template:

@Test
    public void testFill(){
        // 模板文件路径
        String sourcePath = "C:\\Users\\Administrator\\Desktop\\test.pdf";
        // 替换后的文件路径
        String filePath = "C:\\Users\\Administrator\\Desktop\\testFill.pdf";
        // 字体文件路径,与模板文件字体保持一致,非必须
        String fontPath = "C:\\Windows\\Fonts\\simsun.ttc,0";
        // 定义替换字典(key为待替换字符串,value为替换后的字符串)
        Map<String, String> map = new HashMap<>(9);
        map.put("title", "测试报告");
        map.put("date", "2022-04-10");
        map.put("depart", "呼吸外科");
        map.put("no", "0001");
        map.put("name", "张三");
        map.put("sex", "男");
        map.put("age", "10");
        map.put("sign", "李某某");
        map.put("signTime", "2022-04-10 12:00:00");
        // 读取模板文件并替换保存
        XEasyPdfHandler.Document
                .load(sourcePath)
                .replacer()
                .setFontPath(fontPath)
                .enableReplaceCOSArray()
                .replaceText(map)
                .finish(filePath);
    }

The effect is as follows:

Guess you like

Origin www.oschina.net/news/190479/x-easypdf-2-7-8-released