Java HTML文件中显示的编码字符
我的Html文件在将其转换为pdf时显示了一系列错误 封面 在生成的pdf中 我理解这是一个编码错误,并试图指定Java HTML文件中显示的编码字符,java,html,encoding,utf-8,Java,Html,Encoding,Utf 8,我的Html文件在将其转换为pdf时显示了一系列错误 封面 在生成的pdf中 我理解这是一个编码错误,并试图指定 <meta charset="utf-8"> 如果响应为HttpServletResponse,则HttpServletResponse仅声明此HTML应由浏览器/接收器使用utf-8进行解码,要使此声明有效,您需要将HTML源代码保存在您声称的utf-8中。如果您尝试使用windows-1252编码来解码”()这最初是用utf-8编码的。因此,请尝试将文件编辑器的编码
<meta charset="utf-8">
如果响应为HttpServletResponse,则HttpServletResponse仅声明此HTML应由浏览器/接收器使用
utf-8
进行解码,要使此声明有效,您需要将HTML源代码保存在您声称的utf-8
中。如果您尝试使用windows-1252
编码来解码”
()这最初是用utf-8
编码的。因此,请尝试将文件编辑器的编码改为utf-8而不是windows-1252,这样会显示正确的html。至于PDF,请查看PDFGenerator
是否允许显式设置编码。
<strong>“ <span style="text-decoration: underline;">
Technology</span>�
String html = templateEngine.process("template", context);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PDFGenerator.createPdf(html, bos);
byte[] outArray = bos.toByteArray();
String fileName = "abc" + ".pdf";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PDFGenerator.createPdf(html, bos);
byte[] outArray = bos.toByteArray();
response.reset();
response.setContentType("application/pdf");
response.setContentLength(outArray.length);
response.setHeader("Expires:", "0");
response.setHeader("Content-Disposition",
"attachment; filename="" + fileName + "\"");
FileCopyUtils.copy(outArray, response.getOutputStream());
bos.flush();
bos.close();