При выполнении нескольких руководств: (которые могут быть скопированы друг из друга...)
- https://www.baeldung.com/thymeleaf-generate-pdf
- https://tuhrig.de/generating -pdfs-with-java-flying-saucer-and-thymeleaf/
- https://www.baeldung.com/java-html-to-pdf (flying-saucer-pdf- openpdf теперь называется летающей тарелкой-pdf)
- Фрагменты здесь, на StackOverflow
Код: Выделить всё
java.lang.Error: Unresolved compilation problem:
The method createPDF(OutputStream) from the type ITextRenderer refers to the missing type DocumentException
Я понимаю, что мне либо нужна зависимость для этого класса, которая выглядит как com.lowagie.text.DocumentException (surce:doc). Мне не удалось узнать, как получить этот исходный код, и это кажется странным, поскольку в руководствах он не используется.
Мой pom.xml настроен так же, как в этих руководствах:< /p>
Код: Выделить всё
org.xhtmlrenderer
flying-saucer-pdf
9.5.1
org.jsoup
jsoup
1.17.2
Код: Выделить всё
requires org.jsoup;
requires flying.saucer.pdf;
requires flying.saucer.core;
Код: Выделить всё
Document document = Jsoup.parse(htmlString, "UTF-8");
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
try (OutputStream outputStream = new FileOutputStream("outputPDF.pdf")) {
ITextRenderer renderer = new ITextRenderer();
SharedContext sharedContext = renderer.getSharedContext();
sharedContext.setPrint(true);
sharedContext.setInteractive(false);
renderer.setDocumentFromString(document.html());
renderer.layout();
renderer.createPDF(outputStream); //
Подробнее здесь: [url]https://stackoverflow.com/questions/79032385/flying-saucer-pdf-missing-type-documentexception[/url]
Мобильная версия