|
23 | 23 | * [3.6.3 按照base64添加水印](#363-按照base64添加水印)
|
24 | 24 | * [3.7 itext7编辑pdf](#37-itext7编辑pdf)
|
25 | 25 | * [3.7.1 按照文件路径编辑pdf](#371-按照文件路径编辑pdf)
|
26 |
| - * [3.7.2 按照base64编辑pdf](#372-按照base64编辑pdf) |
| 26 | + * [3.7.2 按照base64编辑pdf](#372-按照base64编辑pdf) |
| 27 | + * [3.8 使用Itext7 HTML转PDF文件](#38-使用Itext7 HTML转PDF文件) |
| 28 | + * [3.8.1 按照base64方式](#381-按照base64方式) |
27 | 29 | * [4. 待办事项](#4-待办事项)
|
28 | 30 | * [5. 注意事项](#5-注意事项)
|
29 | 31 | * [6. 参考链接](#6-参考链接)
|
@@ -420,6 +422,39 @@ WorkableConverter converter = new WorkableConverter();
|
420 | 422 | ```
|
421 | 423 |
|
422 | 424 |
|
| 425 | +### 3.8 使用Itext7 HTML转PDF文件 |
| 426 | + |
| 427 | +增加ItextConverter策略; |
| 428 | + |
| 429 | +#### 3.8.1 按照base64方式 |
| 430 | + |
| 431 | +```java |
| 432 | + |
| 433 | +public class ItextConverterTest { |
| 434 | + @Test |
| 435 | + public void testItextConverter() throws ConvertFailedException, IOException { |
| 436 | + WorkableConverter converter = new WorkableConverter(); |
| 437 | + converter.setConverterType(HtmlToPdfByItextConverterManager.getInstance()); |
| 438 | + ConvertPattern pattern = ConvertPatternManager.getInstance(); |
| 439 | + EditorRequire editorRequire = new EditorRequire(); |
| 440 | + editorRequire.setContent("<html><div>你好,word</div></html>"); |
| 441 | + pattern.setEditorRequire(editorRequire); |
| 442 | + pattern.setSrcFilePrefix(DefaultDocumentFormatRegistry.HTML); |
| 443 | + pattern.setDestFilePrefix(DefaultDocumentFormatRegistry.PDF); |
| 444 | + String base64 = Base64.getEncoder().encodeToString(editorRequire.getContent().getBytes()); |
| 445 | + pattern.base64ToBase64(base64); |
| 446 | + assertEquals(true,converter.convert(pattern.getParameter())); |
| 447 | + String base64Result = pattern.getBase64Result(); |
| 448 | + Base64FileTool.saveBase64File(base64Result,"./data/test2.pdf"); |
| 449 | + } |
| 450 | +} |
| 451 | +``` |
| 452 | +参数介绍: |
| 453 | + |
| 454 | + EditorRequire: 在这个对象中的`content`为html内容; |
| 455 | + |
| 456 | + base64Result: 为转换结果的PDF文件内容的base64值; |
| 457 | + |
423 | 458 | ## 4. 待办事项
|
424 | 459 |
|
425 | 460 | * 已经测试通过的有doc、docx、html 按照不同姿势转PDF,其他类型的并没有编写测试单元,后续考虑增加
|
|
0 commit comments