How Markdown Merging Works in C#
Aspose.HTML for .NET
merges Markdown through a two-stage C# workflow. Converter.ConvertMarkdown() parses each .md source into an HTMLDocument, and HtmlRenderer writes the converted documents to one output device in the specified order. The result is a PDF, XPS, DOCX, or TIFF document rather than one concatenated, editable Markdown file.
C# Markdown Merger and Interactive Example
Use the interactive example to configure the source sequence and generate a matching C# workflow. Add the Markdown files in the required order and choose PDF, XPS, DOCX, or TIFF. The code panel updates the filenames, rendering device, and output extension whenever the current selection changes. You can also run the configured merge online to inspect the result.
using Aspose.Html;
using Aspose.Html.Converters;
using Aspose.Html.Rendering;
using Aspose.Html.Rendering.Pdf;
// Convert the Markdown files to HTML documents in the required merge order.
using HTMLDocument document1 = Converter.ConvertMarkdown("first.md");
using HTMLDocument document2 = Converter.ConvertMarkdown("second.md");
// Create the renderer and the PDF output device.
using HtmlRenderer renderer = new HtmlRenderer();
using PdfDevice device = new PdfDevice("merged.pdf");
// Render the documents into one PDF file.
renderer.Render(device, document1, document2);
Markdown Merger Workflow
The example uses PDF by default. The same two-stage workflow applies to the other device-based outputs available in the widget:
- Call
Converter.ConvertMarkdown()for every source file to create anHTMLDocument. - Keep the resulting documents in the order in which their rendered pages must appear.
- Create an
HtmlRendererinstance. - Create the output device, such as
PdfDevicefor PDF. - Pass the device and all converted documents to
HtmlRenderer.Render().
Choose a Markdown Merger Output Format
- PDF – create a fixed-layout document for distribution or printing.
- XPS – write the rendered pages to an XPS document.
- DOCX – create a document that can be opened in Microsoft Word or another compatible editor.
- TIFF – render the combined pages as raster image output.
The generated C# selects PdfDevice, XpsDevice, DocDevice, or ImageDevice according to the chosen format. See
Rendering Devices in C#
for format-specific settings.
Markdown Merging Notes
- The result is rendered output. Headings, lists, code blocks, links, and other parsed Markdown content become part of the intermediate HTML documents; the original
.mdsources are not concatenated. - Input order controls output order. Arrange files in the widget or pass the converted
HTMLDocumentobjects toRender()in the required sequence. - Referenced resources must remain available. Relative images and other linked resources need resolvable locations when the intermediate HTML is rendered.
- Output settings are device-specific. Page size, margins, resolution, and other options belong to the selected output device and its rendering options rather than to the Markdown parser.
Get Started with Aspose.HTML for .NET API
Install Aspose.HTML for .NET from NuGet with the .NET CLI:
dotnet add package Aspose.HTML
You can also use the NuGet Package Manager UI or run Install-Package Aspose.HTML in the Package Manager Console. See the
installation guide
for setup details, or request a
temporary license
to evaluate the API without evaluation limitations.
Markdown Merger FAQ
1. Can I merge Markdown supplied as streams?
Yes. Use the Converter.ConvertMarkdown(Stream, string) overload for each source and provide a base URI that resolves relative links and images. The method returns an HTMLDocument that can be included in the renderer call with the other converted sources.
2. Can I edit the converted Markdown before rendering the result?
Yes. Converter.ConvertMarkdown() returns an HTMLDocument, so the application can inspect or modify its DOM before passing it to HtmlRenderer.Render(). This is useful when the merged output needs generated headings, separators, or normalized content.
3. Can converted Markdown and an existing HTML document share one output?
Yes. After the Markdown sources become HTMLDocument objects, include them and an existing HTMLDocument in the same HtmlRenderer.Render() call. Their argument order determines their order in the rendered output.
4. Will relative images from Markdown files appear in the result?
They appear when their paths can be resolved and the resources are accessible during rendering. Keep the source location and related assets together, or provide document base locations that lead to the correct image files.
5. Can I configure PDF page size and margins for the merged result?
Yes. Create PdfRenderingOptions, configure its PageSetup, and pass the options to PdfDevice. The selected page settings then apply while all converted Markdown documents are rendered to the same PDF.
Related File Mergers
Choose another source format or return to the merger overview.