提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.common; |
X |
2 |
|
|
3 |
import org.springframework.core.io.ByteArrayResource; |
|
4 |
import org.springframework.stereotype.Component; |
|
5 |
|
|
6 |
import java.io.ByteArrayOutputStream; |
|
7 |
import java.io.IOException; |
|
8 |
|
|
9 |
import com.itextpdf.html2pdf.HtmlConverter; |
|
10 |
|
|
11 |
@Component |
|
12 |
public class PdfGenerator { |
|
13 |
public ByteArrayResource generatePdfFromHtml(String html) throws IOException { |
|
14 |
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
15 |
HtmlConverter.convertToPdf(html, outputStream); |
|
16 |
byte[] bytes = outputStream.toByteArray(); |
|
17 |
return new ByteArrayResource(bytes); |
|
18 |
} |
|
19 |
} |