# markdown2pdf **Repository Path**: xieguigang/markdown2pdf ## Basic Information - **Project Name**: markdown2pdf - **Description**: Convert markdown document to html/pdf using VisualBasic in a super easy way! - **Primary Language**: Visual Basic - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-22 - **Last Updated**: 2024-04-16 ## Categories & Tags **Categories**: markdown-utils **Tags**: None ## README # MarkdownToPdf ![](./dist/Adobe_Acrobat_Pro_PDF.png) 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 - [x] Convert markdown/html document to PDF - [ ] Custom CSS style supports. (Works in progress) - [x] 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. ![](./dist/CLI.png)
## Usage First of all, please make sure the encoding of your console is UTF8. Utf8 encoding is the default encoding of the html document: ```vbnet Console.InputEncoding = Encoding.UTF8 ``` ### Convert: from URL source ```vbnet 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 ```vbnet PdfConvert.ConvertHtmlToPdf(New PdfDocument With { .Html = "

test

" }, New PdfOutput With { .OutputFilePath = "inline.pdf" }) PdfConvert.ConvertHtmlToPdf(New PdfDocument With { .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: ```vbnet ' In this case, we use HTMLDocument object instead of PdfDocument object Dim html As New HTMLDocument With { .HTML = Hello World!

Hello World!!!


Example code

					Public Function Main() As Integer
						Call println("Hello world!")
						Return 0
					End Function
				

Another header

1 2 3
a b c
} Call println(html.GetDocument) Call PdfConvert.ConvertHtmlToPdf(html, App.HOME & "/hello-world.pdf") ```
## CLI Usage ```bash # 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# ```bash # 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 しゃけい よしつな