PDF-файл сгенерирован успешно, однако кажется, что в PDF-файле не отображается только символ «c» с символом карона.
if i откройте html, я вижу текст правильно.
Я использую Spring Boot, чтобы проверить его, но это можно выполнить таким же образом с помощью простого основного кода в Java.
вот мой простой код
Код: Выделить всё
@GetMapping("/pdf")
public ResponseEntity generatePdf(@RequestParam("filePath") String filePath) throws IOException, DocumentException {
File htmlFile = new File(filePath);
String htmlContent = new String(Files.readAllBytes(htmlFile.toPath()));
ITextRenderer renderer = new ITextRenderer();
// Path to a font that supports Central European characters and Unicode
String fontPath = "c:/temp/poc-pdf/src/main/resources/templates/DejaVuSans.ttf";
// Adding the font with Unicode encoding
renderer.getFontResolver().addFont(fontPath, com.lowagie.text.pdf.BaseFont.IDENTITY_H, true);
// Set the HTML content
renderer.setDocumentFromString(htmlContent);
renderer.layout();
File file = new File("c:/temp/poc-pdf/src/main/resources/templates/pdf.pdf");
try (OutputStream outputStream = new FileOutputStream(file)) {
renderer.createPDF(outputStream);
}
return ResponseEntity.ok();
}
Код: Выделить всё
čččččLorem ipsum dolor šit amet, consečtetur adipisčing elit. Vestibulum acčumsan metuš pharetra urna efficitur, ac congue justo commodo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed et faucibus lectus. Suspendisse euismod tincidunt pretium. Aliquam porttitor ornare magna. Maecenas eget cursus arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Praesent sodales commodo varius. Maecenas pellentesque velit vitae orci eleifend egestas. Aenean aliquet elit lorem, non maximus sapien efficitur a.
Подробнее здесь: https://stackoverflow.com/questions/791 ... -appearing
Мобильная версия