1 Star 0 Fork 0

xieguigang/markdown2pdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MarkdownToPdf

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.

Feature

  • Convert markdown/html document to PDF
  • Custom CSS style supports. (Works in progress)
  • Html template rendering engine for do automatically data analysis report

How to install

  • Clone the source code in this repository
  • Open in VisualStudio 2017 and restore the nuget package sciBASIC#
  • compile
  • Extract wkhtmltopdf binary distributes from ./dist/wkhtmltopdf.7z package to app release folder
  • Run app in cmd/bash or shell scripting for batch converts of the PDF documents.

Usage

First 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

Convert: from URL source

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"
})

Convert: given html content

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"
})

Demo: hello world

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")

CLI Usage

# 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

Html template engine

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

Dependence

sciBASIC#
# http://github.com/xieguigang/sciBASIC
# install via nuget 
PM> Install-Package sciBASIC -Pre

Licence

This project is available under MIT Licence.

MIT licence. Copyright (c) 2017 しゃけい よしつな

MIT License Copyright (c) 2017 しゃけい よしつな Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Convert markdown document to html/pdf using VisualBasic in a super easy way! 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Visual Basic
1
https://gitee.com/xieguigang/markdown2pdf.git
git@gitee.com:xieguigang/markdown2pdf.git
xieguigang
markdown2pdf
markdown2pdf
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891