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