Convert markdown document to html/pdf using VisualBasic in a super easy way! This is a small VB.NET wrapper utility around wkhtmltopdf
console tool. You can use it to easily convert Markdown/HTML reports to PDF.
wkhtmltopdf
cli wrapper code translate from https://github.com/codaxy/wkhtmltopdf.
sciBASIC#
wkhtmltopdf
binary distributes from ./dist/wkhtmltopdf.7z
package to app release folderFirst of all, please make sure the encoding of your console is UTF8. Utf8 encoding is the default encoding of the html document:
Console.InputEncoding = Encoding.UTF8
PdfConvert.Environment.Debug = False
PdfConvert.ConvertHtmlToPdf(New PdfDocument With {
.Url = "input.html"
}, New PdfOutput With {
.OutputFilePath = "output.pdf"
})
PdfConvert.ConvertHtmlToPdf(New PdfDocument With {
.Url = "input.html",
.HeaderLeft = "[title]",
.HeaderRight = "[date] [time]",
.FooterCenter = "Page [page] of [topage]"
}, New PdfOutput With {
.OutputFilePath = "output.pdf"
})
PdfConvert.ConvertHtmlToPdf(New PdfDocument With {
.Html = "<html><h1>test</h1></html>"
}, New PdfOutput With {
.OutputFilePath = "inline.pdf"
})
PdfConvert.ConvertHtmlToPdf(New PdfDocument With {
.Html = "<html><h1>測試</h1></html>"
}, New PdfOutput With {
.OutputFilePath = "inline_cht.pdf"
})
Actually, you can construct a html document content from XElement
directly in your VB code:
' In this case, we use HTMLDocument object instead of PdfDocument object
Dim html As New HTMLDocument With {
.HTML =
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!!!</h1>
<hr/>
<h2>Example code</h2>
<code>
<pre>
Public Function Main() As Integer
Call println("Hello world!")
Return 0
End Function
</pre>
</code>
<h4>Another header</h4>
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>
<footer style="position:fixed; font-size:.8em; text-align:right; bottom:0px; margin-left:-25px; height:20px; width:100%;">
Here is the PDF document footer.
</footer>
</body>
</html>
}
Call println(html.GetDocument)
Call PdfConvert.ConvertHtmlToPdf(html, App.HOME & "/hello-world.pdf")
# markdown2pdf
markdown2pdf ./input.md
# Due to the reason of markdown parser is compatible with html format,
# so that convert from a html file is also works fine!
markdown2pdf ./input.html
There are some special placeholer can be used for the html template rendering:
[#page]
for create page number dynamics[#h1]
for create the master header numbers[#h2]
for create the secondary header numbers[#h3]
for create the header numbers in third level[#h4]
for create the header numbers in fourth level[#fig]
for create the figure numbers[#tab]
for create the table numbers# http://github.com/xieguigang/sciBASIC
# install via nuget
PM> Install-Package sciBASIC -Pre
This project is available under MIT Licence.
MIT licence. Copyright (c) 2017 しゃけい よしつな
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型