flying-saucer/iTextを使用してPDFを生成できます。しかし、私はスタイルシートをPDFレンダリングに含める方法を理解できません。Flying-saucer/iText PDFファイルが見つかりません
これは参考としてflying-saucer/iText PDF in servlet not finding css fileです。
ので、私は、私はアスカーを使用したものに似た何かを実装しているが、それはCaused by: java.nio.file.InvalidPathException: Illegal char <:> at index 4: http://localhost:8080/proj/resources/css/custom1.css
エラーに
を返すのソリューション
としてrenderer.setDocument(doc, "http://example.com/something/page.html");
を使用することはできません関与する複数のCSSファイルがあります。ここに私のコードは、私が直接アドレスBAに「http://localhost:8080/resources/css/custom1.css」を入力すると、渡されるパスは「http://localhost:8080」 ある
StringBuilder bui = new StringBuilder();
bui.append("<html><head><style>");
bui.append(readFile(path+"/resources/css/custom1.css", Charsets.UTF_8));
bui.append(readFile(path+"/resources/css/custom2.css", Charsets.UTF_8));
bui.append(readFile(path+"/resources/css/custom3.css", Charsets.UTF_8));
bui.append("</style></head>");
bui.append("<body><div><table>");
bui.append(xhtml_file);
bui.append("</table></div></body></html>");
InputStream stream = new ByteArrayInputStream(bui.toString().getBytes(StandardCharsets.UTF_8));
Document doc = tidy.parseDOM(stream, null);
File outputFile = new File(directory+ "FILENAME" +".pdf");
os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
renderer.layout();
renderer.createPDF(os, false);
renderer.finishPDF();
ですr、それはcssファイルを表示します。私は 'パス'を削除しようとしましたが、CSSを取得していません。私は間違って何をしていますか?