Skip to content

Instantly share code, notes, and snippets.

@ErwanLT
Last active December 2, 2022 19:46
Show Gist options
  • Save ErwanLT/187684aceb397eaa6acfaf1694865213 to your computer and use it in GitHub Desktop.
Save ErwanLT/187684aceb397eaa6acfaf1694865213 to your computer and use it in GitHub Desktop.
String htmlWithStyle = "<link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65\" crossorigin=\"anonymous\">"
+ "<script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4\" crossorigin=\"anonymous\"></script>" +
"<ul class=\"list-group\">\n" +
" <li class=\"list-group-item\">An item</li>\n" +
" <li class=\"list-group-item\">A second item</li>\n" +
" <li class=\"list-group-item\">A third item</li>\n" +
" <li class=\"list-group-item\">A fourth item</li>\n" +
" <li class=\"list-group-item\">And a fifth one</li>\n" +
"</ul>";
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
renderOptions.setRenderDelay(500);
// Render the HTML as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf(htmlWithStyle, renderOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment