-
Notifications
You must be signed in to change notification settings - Fork 5
Markdown2Pdf.Markdown2PdfConverter
Namespace: Markdown2Pdf
Assembly: Markdown2Pdf.dll
The main class for converting markdown to PDF.
public class Markdown2PdfConverter : IConvertionEventsobject ← Markdown2PdfConverter
object.Equals(object), object.Equals(object, object), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object, object), object.ToString()
The following code example shows how to convert a file "README.md" in the current directory to PDF. The output will be saved as "README.pdf" in the same directory.
var converter = new Markdown2PdfConverter();
var resultPath = await converter.Convert("README.md");To further specify the conversion process, Markdown2PdfOptions can be passed to the converter.
var options = new Markdown2PdfOptions {
HeaderHtml = File.ReadAllText("header.html"),
FooterHtml = File.ReadAllText("footer.html"),
DocumentTitle = "Example PDF",
};
var converter = new Markdown2PdfConverter(options);Instantiates a new Markdown2PdfConverter.
public Markdown2PdfConverter(Markdown2PdfOptions? options = null)options Markdown2PdfOptions?
Optional options to specify how to convert the markdown.
The template used for generating the HTML which then gets converted into PDF.
public string ContentTemplate { get; set; }Modify this to get more control over the HTML generation (e.g. to add your own JS-Scripts).
Contains all options this converter uses for generating the PDF.
public Markdown2PdfOptions Options { get; }Can be set with the constructor Markdown2PdfOptions).
The PDF file name without extension.
public string? OutputFileName { get; }The Markdig MarkdownPipelineBuilder used for the markdown to HTML conversion.
public MarkdownPipelineBuilder PipelineBuilder { get; }MarkdownPipelineBuilder
This MarkdownPipelineBuilder has the following extensions enabled by default:
* MarkdownPipelineBuilder)
* MarkdownPipelineBuilder)
* Boolean)
* AutoLink
Converts the given markdown-file to PDF.
public Task<FileInfo> Convert(FileInfo markdownFile)markdownFile FileInfo
FileInfo containing the markdown.
The newly created PDF file.
The PDF will be saved in the same location as the markdown file with the naming convention "markdownFileName.pdf".
Converts the given markdown-file to PDF.
public Task Convert(FileInfo markdownFile, FileInfo outputFile)markdownFile FileInfo
FileInfo containing the markdown.
outputFile FileInfo
FileInfo for saving the generated PDF.
Converts the given markdown file to PDF.
public Task<string> Convert(string markdownFilePath)markdownFilePath string
Path to the markdown file.
Filepath to the generated pdf.
The PDF will be saved at the path specified in outputFilePath.
Converts the given markdown file to PDF.
public Task<string> Convert(string markdownFilePath, string outputFilePath)markdownFilePath string
Path to the markdown file.
outputFilePath string
File path for saving the PDF to.
Filepath to the generated pdf.
The PDF will be saved at the path specified in outputFilePath.
Converts the given enumerable of markdown files to PDF.
public Task<string> Convert(IEnumerable<string> markdownFilePaths)markdownFilePaths IEnumerable<string>
Enumerable with paths of the markdown files.
The PDF will be saved in the same location of the first markdown file with the naming convention "markdownFileName.pdf".
Converts the given enumerable of markdown files to PDF.
public Task<string> Convert(IEnumerable<string> markdownFilePaths, string outputFilePath)markdownFilePaths IEnumerable<string>
Enumerable with paths of the markdown files.
outputFilePath string
File path for saving the PDF to.
Instantiates a new Markdown2PdfConverter.
The Markdown2PdfOptions are loaded from a YAML front matter block
at the start of the given markdown document.
public static Markdown2PdfConverter CreateWithInlineOptionsFromFile(string markdownFilePath)markdownFilePath string
Path to the markdown file containing the YAML front matter.
The new Markdown2PdfConverter.
Use this at the beginning of the markdown file:
---
document-title: myDocumentTitle
metadata-title: myMetadataTitle
module-options: Remote # or None or path to node_module directory
theme: Github # or Latex or None or path to css file
code-highlight-theme: Github
enable-auto-language-detection: true
header-html: "<div class='document-title' style='background-color: #5eafed; width: 100%; padding: 5px'></div>"
# footer-html: "<div>hello world</div>"
# custom-head-content: "<style>h2 { page-break-before: always; }</style>"
# chrome-path: "C:\Program Files\Google\Chrome\Application\chrome.exe"
keep-html: false
margin-options:
top: 80px
bottom: 50px
left: 50px
right: 50px
is-landscape: false
format: A4
scale: 1
table-of-contents:
list-style: decimal
min-depth-level: 2
max-depth-level: 6
page-number-options:
tab-leader: dots
---
# Here the normal markdown content startsInstead of three dashes (---) an HTML comment (<!-- -->) can also be used to wrap the YAML.
Instantiates a new Markdown2PdfConverter.
The Markdown2PdfOptions are loaded from a YAML front matter block
at the start of the given markdown document.
public static Markdown2PdfConverter CreateWithInlineOptionsFromFile(FileInfo markdownFile)markdownFile FileInfo
Markdown file containing the YAML front matter.
The new Markdown2PdfConverter.
Use this at the beginning of the markdown file:
---
document-title: myDocumentTitle
metadata-title: myMetadataTitle
module-options: Remote # or None or path to node_module directory
theme: Github # or Latex or None or path to css file
code-highlight-theme: Github
enable-auto-language-detection: true
header-html: "<div class='document-title' style='background-color: #5eafed; width: 100%; padding: 5px'></div>"
# footer-html: "<div>hello world</div>"
# custom-head-content: "<style>h2 { page-break-before: always; }</style>"
# chrome-path: "C:\Program Files\Google\Chrome\Application\chrome.exe"
keep-html: false
margin-options:
top: 80px
bottom: 50px
left: 50px
right: 50px
is-landscape: false
format: A4
scale: 1
table-of-contents:
list-style: decimal
min-depth-level: 2
max-depth-level: 6
page-number-options:
tab-leader: dots
---
# Here the normal markdown content startsInstead of three dashes (---) an HTML comment (<!-- -->) can also be used to wrap the YAML.
Gets invoked before the markdown to HTML conversion.
public event EventHandler<MarkdownArgs>? BeforeHtmlConversionGets invoked after a temporary PDF file is created.
public event EventHandler<PdfArgs>? OnTempPdfCreatedEventThis only happens if a parsing of the generated PDF is needed, e.g. for generating page numbers.
Gets invoked when the template model is created.
public event EventHandler<TemplateModelArgs>? OnTemplateModelCreatingEventHandler<TemplateModelArgs>?
This can be used to add custom content to the html template.