springboot vue2 下 markdown文档 如何转PDF导出

springboot vue2 下 markdown文档 如何转PDF导出

最好能有代码例子

Markdown2Pdf 使用这个类库

直接用markdown2document https://github.com/floppylab/markdown2document
这个我用过,简单易用。
你对于需求描述的不是很清楚。

  • 不要再前端(Vue)处理生成PDF的工作,难度很高
  • 在前端(Vue)把编辑好的markdown,传给后端(Java)来生成PDF

ContentFactory contentFactory = ContentFactory.getInstance();

Document document = Document
        .builder()
        .markdownContents(Arrays.asList(
                contentFactory.create("# Sample header \n sample content "),
                contentFactory.create(new URL("https://floppylab.com/resources/markdown2document/sample.md"))
        ))
        .styles(Arrays.asList(
                contentFactory.create("body { font-family: sans-serif; color: #555; /* some comment*/ }"),
                new Link("https://floppylab.com/resources/markdown2document/sample.css")
        )).build();

PdfGenerator pdfGenerator = new PdfGenerator();
Output output = pdfGenerator.generate(document);
output.toFile("sample.pdf");

HtmlGenerator htmlGenerator = new HtmlGenerator();
output = htmlGenerator.generate(document);
output.toFile("sample.html");

将markdown文档转化为pdf格式
跟着步骤来
https://blog.csdn.net/weixin_67340472/article/details/126554960

参考一下

参考