### Example Custom Style Resolver Definition Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents An example implementation of a custom style resolver that treats 'Heading' and 'Header' styles as Heading1, in addition to default behavior. ```cs // Example - treat headings without number as Heading1 public class CustomStyleNamingResolver : DefaultStyleNamingResolver { public override bool IsHeader1Style(string styleId) { return styleId.Trim().Equals("Heading", StringComparison.OrdinalIgnoreCase) || styleId.Trim().Equals("Header", StringComparison.OrdinalIgnoreCase) || base.IsHeader1Style(styleId); } } ``` -------------------------------- ### Multiline Code Block Example Source: https://github.com/manfromarce/docsharp/blob/main/test-files/Markdown/Markdown.md Demonstrates a basic multiline code block. Ensure content is properly indented or fenced. ```text Multiline code block Second paragraph ``` -------------------------------- ### Convert DOC to DOCX using DocSharp.Binary Source: https://github.com/manfromarce/docsharp/wiki/Convert-binary-documents Use this snippet to convert a Microsoft Word 97-2003 DOC file to a DOCX file. Ensure the DocSharp.Binary.Doc NuGet package is installed. ```cs using WordprocessingDocument = DocSharp.Binary.OpenXmlLib.WordprocessingML.WordprocessingDocument; using DocSharp.Binary.DocFileFormat; using DocSharp.Binary.StructuredStorage.Reader; // ... using (var reader = new StructuredStorageReader(inputFile)) { var outputType = DocSharp.Binary.OpenXmlLib.WordprocessingDocumentType.Document; // Use Template type for .dot files var doc = new WordDocument(reader); using (var docx = WordprocessingDocument.Create(outputFile, outputType)) { DocSharp.Binary.WordprocessingMLMapping.Converter.Convert(doc, docx); } } ``` -------------------------------- ### Convert PPT to PPTX using DocSharp.Binary Source: https://github.com/manfromarce/docsharp/wiki/Convert-binary-documents Convert a PowerPoint 97-2003 PPT file to a PPTX file using this C# code. Ensure the DocSharp.Binary.Ppt NuGet package is installed. ```cs using PresentationDocument = DocSharp.Binary.OpenXmlLib.PresentationML.PresentationDocument; using DocSharp.Binary.PptFileFormat; using DocSharp.Binary.StructuredStorage.Reader; // ... using (var reader = new StructuredStorageReader(inputFile)) { var outputType = DocSharp.Binary.OpenXmlLib.PresentationDocumentType.Presentation; // Use Template type for .pot files, and Slideshow for .pps files var ppt = new PowerpointDocument(reader); using (var pptx = PresentationDocument.Create(outputFile, outputType)) { DocSharp.Binary.PresentationMLMapping.Converter.Convert(ppt, pptx); } } ``` -------------------------------- ### Footnote Code Example Source: https://github.com/manfromarce/docsharp/blob/main/test-files/Markdown/Markdown.md Illustrates how to include code within a footnote. The code is typically rendered in a monospaced font. ```text { my code } ``` -------------------------------- ### Get All DOCX Pages as PNG Bytes Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Retrieves all pages of a DOCX document as an enumerable collection of PNG byte arrays. Supports streams as input. ```cs var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; var pages = renderer.GetAllPagesAsPng("input.docx"); ``` -------------------------------- ### Basic Markdown to DOCX Conversion Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Converts a Markdown file to a DOCX file. Ensure the DocSharp.Markdown package is installed. Sets the base URI for images based on the Markdown file's directory. ```cs using DocSharp.Markdown; // ... var markdown = MarkdownSource.FromFile("markdown.md"); var converter = new MarkdownConverter() { ImagesBaseUri = Path.GetDirectoryName("markdown.md") }; converter.ToDocx(markdown, "output.docx"); // or output Stream ``` -------------------------------- ### Get All DOCX Pages as SVG Strings Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Retrieves all pages of a DOCX document as an enumerable collection of SVG strings. Supports streams as input. ```cs var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; var pages = renderer.GetAllPagesAsSvg("input.docx"); ``` -------------------------------- ### Convert XLS to XLSX using DocSharp.Binary Source: https://github.com/manfromarce/docsharp/wiki/Convert-binary-documents This code converts an Excel 97-2003 XLS file to an XLSX file. You need to install the DocSharp.Binary.Xls NuGet package. ```cs using SpreadsheetDocument = DocSharp.Binary.OpenXmlLib.SpreadsheetML.SpreadsheetDocument; using DocSharp.Binary.Spreadsheet.XlsFileFormat; using DocSharp.Binary.StructuredStorage.Reader; // ... using (var reader = new StructuredStorageReader(inputFile)) { var outputType = DocSharp.Binary.OpenXmlLib.SpreadsheetDocumentType.Workbook; // Use Template type for .xlt files var xls = new XlsDocument(reader); using (var xlsx = SpreadsheetDocument.Create(outputFile, outputType)) { DocSharp.Binary.SpreadsheetMLMapping.Converter.Convert(xls, xlsx); } } ``` -------------------------------- ### Get All Pages as PNG Bytes Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Retrieves all pages of a DOCX document as an enumerable collection of PNG image byte arrays. ```APIDOC ## Get All Pages as PNG Bytes This method retrieves all pages of a DOCX document as an `IEnumerable` collection, where each element is the byte array representing a PNG image of a page. ### Method ```csharp renderer.GetAllPagesAsPng(string inputDocxPath) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. ### Response #### Success Response - **pages** (IEnumerable) - An enumerable collection of byte arrays, each representing a PNG image of a page. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; var pages = renderer.GetAllPagesAsPng("input.docx"); // streams are also supported ``` ``` -------------------------------- ### Get WordprocessingDocument Object Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Retrieves an Open XML SDK WordprocessingDocument object from a Markdown source, allowing for further programmatic manipulation before saving. Sets the base URI for images. ```cs var markdown = MarkdownSource.FromFile(filePath); var converter = new MarkdownConverter() { ImagesBaseUri = Path.GetDirectoryName(filePath) }; WordprocessingDocument doc = converter.ToWordprocessingDocument(markdown, "output.docx"); ``` -------------------------------- ### Get DOCX Bytes Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Converts Markdown to DOCX and returns the resulting document as a byte array. This is useful for scenarios where the DOCX needs to be sent over a network or stored in memory. ```cs byte[] bytes = converter.ToDocxBytes(markdown); ``` -------------------------------- ### Get All Pages as SVG Strings Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Retrieves all pages of a DOCX document as an enumerable collection of SVG string representations. ```APIDOC ## Get All Pages as SVG Strings This method retrieves all pages of a DOCX document as an `IEnumerable` collection, where each element is a string representing the SVG content of a page. ### Method ```csharp renderer.GetAllPagesAsSvg(string inputDocxPath) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. ### Response #### Success Response - **pages** (IEnumerable) - An enumerable collection of strings, each representing the SVG content of a page. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; var pages = renderer.GetAllPagesAsSvg("input.docx"); // streams are also supported ``` ``` -------------------------------- ### Convert Markdown to RTF Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Converts a Markdown document to RTF format. Ensure the DocSharp.Markdown package is installed. Images are handled via ImageConverter, with ImageSharp recommended for broader format support. ```cs using DocSharp.Markdown; // ... var markdown = MarkdownSource.FromFile("markdown.md"); var converter = new MarkdownConverter() { ImagesBaseUri = Path.GetDirectoryName(filePath), // or a custom folder path or http(s) URL ImageConverter = new ImageSharpConverter() // or SystemDrawingConverter }; converter.ToRtf(markdown, "output.rtf"); // or output Stream ``` -------------------------------- ### Configure Page Size and Margins for Conversion Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Sets the page size and margins for DOCX or RTF conversions. Predefined configurations like A4_Landscape and Narrow margins are available, as well as custom dimension settings. ```cs using DocSharp.Primitives; var markdown = MarkdownSource.FromFile("markdown.md"); var converter = new MarkdownConverter() { PageSize = PageSize.A4_Landscape, PageMargins = PageMargin.Narrow, }; converter.ToDocx(markdown, "output.docx", settings); // or ToRtf ``` ```cs using DocSharp.Primitives; var markdown = MarkdownSource.FromFile("markdown.md"); var converter = new MarkdownConverter() { PageSize = PageSize.FromMillimeters(210, 297), PageMargins = PageMargins.FromInches(1, 1, 1, 1), }; converter.ToDocx(markdown, "output.docx", settings); // or ToRtf ``` -------------------------------- ### Set Magick.NET Image Converter for MarkdownConverter Source: https://github.com/manfromarce/docsharp/wiki/Convert-images Initialize a MarkdownConverter with Magick.NET support for image conversion by assigning a MagickConverter to the ImageConverter property. ```csharp var converter = new MarkdownConverter() { // ... ImageConverter = new MagickConverter() }; ``` -------------------------------- ### Configure Image Conversion for Markdown Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Enables image conversion for Markdown output by specifying an output folder and a base URI. Images are saved to ImagesOutputFolder and referenced using ImagesBaseUriOverride. ```cs var converter = new DocxToMarkdownConverter() { ImagesOutputFolder = Path.GetDirectoryName(inputFilePath), ImagesBaseUriOverride = "", // will produce just the image file name, same effect as "./" }; converter.Convert(inputFile, outputFile); ``` -------------------------------- ### Save DOCX to PDF with Custom Settings Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders a DOCX file to a PDF file, allowing customization of PDF settings and metadata. Ensure QuestPDF is configured if using advanced features. ```cs var settings = QuestPDF.Infrastructure.DocumentSettings.Default; settings.PDFA_Conformance = QuestPDF.Infrastructure.PDFA_Conformance.PDFA_3A; var metadata = QuestPDF.Infrastructure.DocumentMetadata.Default; metadata.Author = "Author name"; var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter(), PdfSettings = settings, PdfMetadata = metadata }; renderer.SaveAsPdf("input.docx", "output.pdf"); ``` -------------------------------- ### Render DOCX Bytes to PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Converts DOCX data provided as a byte array into a PDF file. Ensure the byte array contains valid DOCX content. ```cs var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter(), }; renderer.SaveAsPdf(docxByteArray, "output.pdf"); ``` -------------------------------- ### Use ImageSharp for Image Conversion Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Enables the use of the ImageSharp library for converting unsupported image formats (like WebP) to formats compatible with DOCX. Requires the DocSharp.ImageSharp package. ```cs var converter = new MarkdownConverter() { ImageConverter = new ImageSharpConverter() }; converter.ToDocx(markdown, "output.docx"); ``` -------------------------------- ### Render DOCX Stream to PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Saves a DOCX document from an input stream to a PDF file. The input stream must be properly managed. ```cs var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter(), }; renderer.SaveAsPdf(inputDocxStream, "output.pdf"); ``` -------------------------------- ### Customize Markdown to RTF Conversion Settings Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Customizes the RTF conversion by providing specific font and color settings. The MarkdownToRtfSettings class allows fine-grained control over the appearance of different Markdown elements. ```cs var markdown = MarkdownSource.FromFile("markdown.md"); var converter = new MarkdownConverter() { ImagesBaseUri = Path.GetDirectoryName("markdown.md"), ImageConverter = new ImageSharpConverter() }; converter.ToRtf(markdown, "output.rtf", new MarkdownToRtfSettings() { DefaultFont = "Times New Roman", CodeFont = "Cascadia Mono" }); ``` -------------------------------- ### Custom Style Resolver for Markdown/HTML Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Allows mapping custom or additional Word styles to heading levels for Markdown and HTML conversion. Set the StyleNamingResolver property to a custom resolver instance. ```cs var converter = new DocxToMarkdownConverter(); converter.StyleNamingResolver = new CustomStyleResolver(); converter.Convert(inputFile, outputFile); ``` -------------------------------- ### Render WordprocessingDocument to PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Converts an in-memory WordprocessingDocument object to a PDF file. Requires obtaining the WordprocessingDocument object first. ```cs using (var wordDocument = /* obtain WordprocessingDocument */) { var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; renderer.SaveAsPdf(wordDocument, "output.pdf"); } ``` -------------------------------- ### Set Output Document Type Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Specifies the Open XML document type when converting Markdown to DOCX. Can be set to 'Document', 'Template', or 'Macro-enabled Document'. ```cs converter.ToDocx(markdown, "output.dotx", WordprocessingDocumentType.Template); ``` -------------------------------- ### Convert RTF File to DOCX Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Use this method to convert an RTF file to a DOCX file. Input can be a file path, stream, or TextReader. Output can be a file path or TextReader. ```cs var converter = new RtfToDocxConverter(); converter.Convert("input.rtf", "output.docx"); ``` -------------------------------- ### Handle RTF Sub-documents Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Sets both OriginalFolderPath and OutputFolderPath for RTF conversion to handle sub-documents. OriginalFolderPath resolves DOCX sub-document paths, while OutputFolderPath specifies where converted RTF sub-documents are saved. ```cs var converter = new DocxToRtfConverter() { OriginalFolderPath = Path.GetDirectoryName(inputFilePath), // This will be used to resolve DOCX sub-documents paths OutputFolderPath = Path.GetDirectoryName(outputFilePath) // This will be used to save the converted RTF sub-documents // (it doesn't necessarily have to be the same location as the output document, it can be any folder path). }; converter.Convert(inputFilePath, outputFilePath); ``` -------------------------------- ### Export Specific DOCX Page to PNG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders a specific page from a DOCX document to a PNG image file. The page number must be valid. ```cs int pageNumber = 1; var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; renderer.SaveAllPagesAsPng(pageNumber, "input.docx", "output.png"); ``` -------------------------------- ### Render DOCX Bytes to PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders DOCX data from a byte array to a PDF file. ```APIDOC ## Render DOCX Bytes to PDF This method renders DOCX data provided as a byte array into a PDF file. ### Method ```csharp renderer.SaveAsPdf(byte[] docxByteArray, string outputPdfPath) ``` ### Parameters - **docxByteArray** (byte[]) - Required - The byte array containing the DOCX data. - **outputPdfPath** (string) - Required - The path where the output PDF file will be saved. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter(), }; renderer.SaveAsPdf(docxByteArray, "output.pdf"); ``` ``` -------------------------------- ### Save DOCX to XPS Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document to a single XPS file. This functionality is only supported on Windows. Streams are also supported. ```cs var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; renderer.SaveAsXps("input.docx", "output.xps"); ``` -------------------------------- ### Render DOCX Stream to PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders a DOCX file from a stream to a PDF file. ```APIDOC ## Render DOCX Stream to PDF This method renders a DOCX file from an input stream to a PDF file. ### Method ```csharp renderer.SaveAsPdf(Stream inputDocxStream, string outputPdfPath) ``` ### Parameters - **inputDocxStream** (Stream) - Required - The input stream containing the DOCX file. - **outputPdfPath** (string) - Required - The path where the output PDF file will be saved. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter(), }; renderer.SaveAsPdf(inputDocxStream, "output.pdf"); ``` ``` -------------------------------- ### Export All DOCX Pages to PNG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document as individual PNG image files into a specified folder. Uses System.Drawing for conversion. ```cs var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; renderer.SaveAllPagesAsPng("input.docx", "output-folder", "document-name"); ``` -------------------------------- ### Convert RTF to DOCX Template Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Convert an RTF file to a DOCX template (.dotx) file. This is useful when you want to create a template for further document generation. ```cs var converter = new RtfToDocxConverter(); converter.Convert("input.rtf", "output.dotx", WordprocessingDocumentType.Template); ``` -------------------------------- ### Set ImageSharp Image Converter for DocxToRtfConverter Source: https://github.com/manfromarce/docsharp/wiki/Convert-images Configure a DocxToRtfConverter to use ImageSharp for image conversion by setting the ImageConverter property to an ImageSharpConverter instance. ```csharp var converter = new DocxToRtfConverter() { // ... ImageConverter = new ImageSharpConverter() }; ``` -------------------------------- ### Convert DOCX to Markdown String Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Generates a Markdown string representation of a DOCX document instead of saving directly to a file. Useful for in-memory processing. ```cs var converter = new DocxToMarkdownConverter(); string markdown = converter.ConvertToString(inputFile); ``` -------------------------------- ### Set System.Drawing Image Converter for DocxToMarkdownConverter Source: https://github.com/manfromarce/docsharp/wiki/Convert-images Assign an instance of SystemDrawingConverter to the ImageConverter property when creating a DocxToMarkdownConverter to handle image processing using System.Drawing. ```csharp var converter = new DocxToMarkdownConverter() { // ... ImageConverter = new SystemDrawingConverter() }; ``` -------------------------------- ### Convert RTF file to DOCX file Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Converts an RTF file to a DOCX file using the default settings. ```APIDOC ## Convert RTF file to DOCX file ### Description Converts an RTF file to a DOCX file. ### Method Signature `converter.Convert(string inputRtfFilePath, string outputDocxFilePath)` ### Parameters - **inputRtfFilePath** (string) - Required - The path to the input RTF file. - **outputDocxFilePath** (string) - Required - The path where the output DOCX file will be saved. ### Request Example ```cs var converter = new RtfToDocxConverter(); converter.Convert("input.rtf", "output.docx"); ``` ``` -------------------------------- ### Save DOCX as PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders a DOCX file to a PDF file. Supports custom PDF settings and metadata. ```APIDOC ## Save DOCX as PDF This method renders a DOCX file to a PDF file. You can optionally configure custom PDF settings and metadata. ### Method ```csharp renderer.SaveAsPdf(string inputDocxPath, string outputPdfPath) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputPdfPath** (string) - Required - The path where the output PDF file will be saved. ### Request Example ```csharp // Set custom PDF settings if desired var settings = QuestPDF.Infrastructure.DocumentSettings.Default; settings.PDFA_Conformance = QuestPDF.Infrastructure.PDFA_Conformance.PDFA_3A; // Set custom metadata if desired var metadata = QuestPDF.Infrastructure.DocumentMetadata.Default; metadata.Author = "Author name"; var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter(), // PdfSettings and PdfMetadata are QuestPDF types — configure as needed PdfSettings = settings, PdfMetadata = metadata }; renderer.SaveAsPdf("input.docx", "output.pdf"); ``` ``` -------------------------------- ### Customize RTF Conversion Settings Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Allows customization of default font and paragraph formatting for RTF conversion when not specified in the document. Access the DefaultSettings property to modify font name, size, paragraph spacing, and line spacing. ```cs converter.DefaultSettings.FontName = "Calibri"; converter.DefaultSettings.FontSize = 11; // In points (default is 12) converter.DefaultSettings.SpaceAfterParagraph = 0; // In points (default is 8) converter.DefaultSettings.LineSpacing = 1; // In lines (default is 1.15) ``` -------------------------------- ### Convert DOCX to RTF String Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Generates an RTF string representation of a DOCX document instead of saving directly to a file. Useful for in-memory processing. ```cs var converter = new DocxToRtfConverter(); string rtf = converter.ConvertToString(inputFile); ``` -------------------------------- ### Convert RTF String to DOCX Stream Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Convert an RTF string directly to a DOCX output stream. Ensure the `outputDocxStream` is properly initialized before calling this method. ```cs var converter = new RtfToDocxConverter(); converter.ConvertString(rtfContent, outputDocxStream); ``` -------------------------------- ### Handle DOCX Sub-documents Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Sets the OriginalFolderPath to resolve sub-document paths when converting DOCX files. This is necessary for preserving content from sub-documents created in the Microsoft Word outline view. ```cs var converter = new DocxToHtmlConverter() // or DocxToMarkdownConverter, DocxToTxtConverter { OriginalFolderPath = Path.GetDirectoryName(inputFileName) }; converter.Convert(inputFileName, outputFileName); ``` -------------------------------- ### Append Markdown to Existing DOCX Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Appends the converted Markdown content to an existing DOCX file. Sets the base URI for images based on the Markdown file's directory. ```cs var markdown = MarkdownSource.FromFile(filePath); var converter = new MarkdownConverter() { ImagesBaseUri = Path.GetDirectoryName(filePath) }; converter.ToDocx(markdown, "existing.docx", append: true); ``` -------------------------------- ### Render WordprocessingDocument to PDF Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders an in-memory WordprocessingDocument object to a PDF file. ```APIDOC ## Render WordprocessingDocument to PDF This method renders an in-memory `WordprocessingDocument` object to a PDF file. ### Method ```csharp renderer.SaveAsPdf(WordprocessingDocument wordDocument, string outputPdfPath) ``` ### Parameters - **wordDocument** (WordprocessingDocument) - Required - The `WordprocessingDocument` object to render. - **outputPdfPath** (string) - Required - The path where the output PDF file will be saved. ### Request Example ```csharp using (var wordDocument = /* obtain WordprocessingDocument */) { var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; renderer.SaveAsPdf(wordDocument, "output.pdf"); } ``` ``` -------------------------------- ### Convert Markdown to RTF String Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Retrieves the RTF representation of a Markdown document as a string. This is useful for in-memory processing or when the output does not need to be written directly to a file. ```cs string rtf = converter.ToRtfString(markdown); ``` -------------------------------- ### Set SkiaSharp Image Converter for DocxToMarkdownConverter Source: https://github.com/manfromarce/docsharp/wiki/Convert-images Specify SkiaSharp as the image processing library for a DocxToMarkdownConverter by setting its ImageConverter property to a SkiaSharpConverter. ```csharp var converter = new DocxToMarkdownConverter() { ImageConverter = new SkiaSharpConverter() }; ``` -------------------------------- ### Export All DOCX Pages to JPEG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document as individual JPEG image files into a specified folder. Uses System.Drawing for conversion. ```cs var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; renderer.SaveAllPagesAsJpeg("input.docx", "output-folder", "document-name"); ``` -------------------------------- ### Convert DOCX to HTML Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Converts a DOCX file to HTML format. Specify input and output file paths or streams. The inputFile can also be a WordprocessingDocument object. Images are preserved as inline base64 by default. ```cs var converter = new DocxToHtmlConverter(); converter.Convert(inputFile, outputFile); // file paths or streams; inputFile may also be a WordprocessingDocument object ``` -------------------------------- ### Convert DOCX to RTF Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Converts a DOCX file to RTF format. Specify input and output file paths or streams. The inputFile can also be a WordprocessingDocument object. ```cs var converter = new DocxToRtfConverter(); converter.Convert(inputFile, outputFile); // file paths or streams; inputFile may also be a WordprocessingDocument object ``` -------------------------------- ### Export All Pages to PNG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document as individual PNG image files into a specified folder. ```APIDOC ## Export All Pages to PNG This method exports every page of a DOCX document as a separate PNG image file. The images are saved into a specified folder with a given filename prefix. ### Method ```csharp renderer.SaveAllPagesAsPng(string inputDocxPath, string outputFolderPath, string filenamePrefix) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputFolderPath** (string) - Required - The folder where the PNG images will be saved. - **filenamePrefix** (string) - Required - A prefix for the generated PNG filenames. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; // exports all pages as PNG files into the folder with the given filename prefix renderer.SaveAllPagesAsPng("input.docx", "output-folder", "document-name"); ``` ``` -------------------------------- ### Save as XPS Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document to a single XPS (XML Paper Specification) file. Note: XPS export is only supported on Windows. ```APIDOC ## Save as XPS This method exports all pages of a DOCX document into a single XPS file. This format is an alternative to PDF. Please note that this functionality is only available on Windows operating systems. ### Method ```csharp renderer.SaveAsXps(string inputDocxPath, string outputXpsPath) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputXpsPath** (string) - Required - The path where the output XPS file will be saved. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; renderer.SaveAsXps("input.docx", "output.xps"); // streams are also supported ``` ``` -------------------------------- ### Convert RTF to WordprocessingDocument object Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Converts an RTF file and returns the result as a WordprocessingDocument object. ```APIDOC ## Convert RTF to WordprocessingDocument object ### Description Converts an RTF file and returns the result as a `WordprocessingDocument` object, allowing for further manipulation before saving. ### Method Signature `converter.ToWordprocessingDocument(string inputRtfFilePath)` ### Parameters - **inputRtfFilePath** (string) - Required - The path to the input RTF file. ### Response #### Success Response - **WordprocessingDocument** - The converted document object. ### Request Example ```cs using var doc = converter.ToWordprocessingDocument("input.rtf"); // Further operations on the doc object can be performed here ``` ``` -------------------------------- ### Skip Images During Conversion Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Converts Markdown to DOCX while preventing the converter from processing any images. Useful for reducing file size or avoiding external resource loading. ```cs var markdown = MarkdownSource.FromFile(filePath); var converter = new MarkdownConverter() { SkipImages = true }; converter.ToDocx(markdown, "output.docx"); ``` -------------------------------- ### Append Markdown to WordprocessingDocument Object Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Appends Markdown content to an already loaded Open XML SDK WordprocessingDocument object. Sets the base URI for images. ```cs var markdown = MarkdownSource.FromFile(filePath); var converter = new MarkdownConverter() { ImagesBaseUri = Path.GetDirectoryName(filePath) }; converter.AppendToDocument(markdown, wpDocument); ``` -------------------------------- ### Convert DOCX to Markdown Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Converts a DOCX file to Markdown format. Specify input and output file paths or streams. The inputFile can also be a WordprocessingDocument object. ```cs var converter = new DocxToMarkdownConverter(); converter.Convert(inputFile, outputFile); // file paths or streams; inputFile may also be a WordprocessingDocument object ``` -------------------------------- ### Customize default encoding and code page Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Allows customization of the default encoding and code page used for interpreting RTF documents, especially for non-conformant or legacy content. ```APIDOC ## Customize default encoding and code page ### Description Control how unknown or legacy text encodings are interpreted by setting `DefaultEncoding` and `DefaultCodePage` properties on the converter. ### Properties - **DefaultCodePage** (int) - Optional - Sets the default code page to use (e.g., 1252 for Windows Western). - **DefaultEncoding** (Encoding) - Optional - Sets the default encoding to use (e.g., `Encoding.UTF8`). ### Example 1: Setting Default Code Page ```cs var converter2 = new RtfToDocxConverter() { DefaultCodePage = 1252 }; converter2.Convert("input.rtf", "output.docx"); ``` ### Example 2: Setting Default Encoding with Document Type ```cs var converter = new RtfToDocxConverter(); converter.Convert("input.rtf", "output.docx", WordprocessingDocumentType.Document, Encoding.UTF8); ``` ``` -------------------------------- ### Export Specific DOCX Page to SVG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Renders a specific page from a DOCX document to an SVG file. The page number must be valid and between 1 and the total number of pages. ```cs var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; renderer.SaveAsSvg(1, "input.docx", "output-page1.svg"); ``` -------------------------------- ### Export Specific Page to PNG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports a specific page of a DOCX document as a PNG image file. ```APIDOC ## Export Specific Page to PNG This method exports a single, specified page from a DOCX document as a PNG image file. ### Method ```csharp renderer.SaveAllPagesAsPng(int pageNumber, string inputDocxPath, string outputPngPath) ``` ### Parameters - **pageNumber** (int) - Required - The number of the page to export (1-based index). - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputPngPath** (string) - Required - The path where the output PNG image will be saved. ### Request Example ```csharp int pageNumber = 1; // Must be between 1 and pages count var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; renderer.SaveAllPagesAsPng(pageNumber, "input.docx", "output.png"); // streams are also supported ``` ``` -------------------------------- ### Export All Pages to JPEG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document as individual JPEG image files into a specified folder. ```APIDOC ## Export All Pages to JPEG This method exports every page of a DOCX document as a separate JPEG image file. The images are saved into a specified folder with a given filename prefix. ### Method ```csharp renderer.SaveAllPagesAsJpeg(string inputDocxPath, string outputFolderPath, string filenamePrefix) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputFolderPath** (string) - Required - The folder where the JPEG images will be saved. - **filenamePrefix** (string) - Required - A prefix for the generated JPEG filenames. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; // exports all pages as JPG files into the folder with the given filename prefix renderer.SaveAllPagesAsJpeg("input.docx", "output-folder", "document-name"); ``` ``` -------------------------------- ### Convert RTF to DOCX with custom document type Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Converts an RTF document to a specified Open XML document type, such as a template. ```APIDOC ## Convert RTF to DOCX with custom document type ### Description Converts an RTF document to a specified Open XML document type (e.g., Template). ### Method Signature `converter.Convert(string inputRtfFilePath, string outputFilePath, WordprocessingDocumentType documentType)` ### Parameters - **inputRtfFilePath** (string) - Required - The path to the input RTF file. - **outputFilePath** (string) - Required - The path for the output document. - **documentType** (WordprocessingDocumentType) - Required - The type of the output document (e.g., `WordprocessingDocumentType.Template`). ### Request Example ```cs var converter = new RtfToDocxConverter(); converter.Convert("input.rtf", "output.dotx", WordprocessingDocumentType.Template); ``` ``` -------------------------------- ### Convert RTF to WordprocessingDocument Object Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Obtain a `WordprocessingDocument` object directly from an RTF file. This allows for in-memory manipulation before saving or further processing. ```cs using var doc = converter.ToWordprocessingDocument("input.rtf"); ``` -------------------------------- ### Save WordprocessingDocument with Custom Options Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Saves a WordprocessingDocument object to a file with custom save options, such as specifying an ImageConverter. This allows for fine-grained control over the conversion process. ```cs document.SaveTo("document.rtf", new RtfSaveOptions() { ImageConverter = new ImageSharpConverter() }); ``` -------------------------------- ### Export All Pages to SVG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports all pages of a DOCX document as individual SVG files into a specified folder. ```APIDOC ## Export All Pages to SVG This method exports every page of a DOCX document as a separate SVG file. The files are saved into a specified folder with a given filename prefix. ### Method ```csharp renderer.SaveAllPagesAsSvg(string inputDocxPath, string outputFolderPath, string filenamePrefix) ``` ### Parameters - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputFolderPath** (string) - Required - The folder where the SVG files will be saved. - **filenamePrefix** (string) - Required - A prefix for the generated SVG filenames. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new SystemDrawingConverter() }; // exports all pages as SVG files into the folder with the given filename prefix renderer.SaveAllPagesAsPng("input.docx", "output-folder", "document-name"); ``` ``` -------------------------------- ### Treat Font Families as Code in Markdown Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Configures the Markdown converter to render specific font families as inline code. Set the CodeFontFamilies property with an array of font family names. ```cs var converter = new DocxToMarkdownConverter(); converter.CodeFontFamilies = new[] { "Fira Code", "Source Code Pro" }; string markdown = converter.ConvertToString(inputFile); ``` -------------------------------- ### Convert RTF to Byte Array Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Convert an RTF file into a byte array representing the DOCX document. This is useful for sending the document over a network or storing it in a database. ```cs byte[] docxBytes = converter.ConvertToBytes("input.rtf"); ``` -------------------------------- ### Save WordprocessingDocument to File Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Uses the SaveTo extension method to save a WordprocessingDocument object to a separate DOCX, RTF, HTML, Markdown, or plain text document. This method allows for creating new documents from an existing WordprocessingDocument object. ```cs using (WordprocessingDocument document = WordprocessingDocument.Create("document.docx", WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); Paragraph paragraph = body.AppendChild(new Paragraph()); Run run = paragraph .AppendChild(new Run()); run.AppendChild(new Text("Add some text here.")); document.SaveTo("document.rtf", SaveFormat.Rtf); } ``` -------------------------------- ### Convert RTF string to DOCX stream Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Converts an RTF string directly into a DOCX output stream. ```APIDOC ## Convert RTF string to DOCX stream ### Description Converts an RTF string content directly into a DOCX output stream. ### Method Signature `converter.ConvertString(string rtfContent, Stream outputDocxStream)` ### Parameters - **rtfContent** (string) - Required - The RTF content as a string. - **outputDocxStream** (Stream) - Required - The stream to write the generated DOCX content to. ### Request Example ```cs var converter = new RtfToDocxConverter(); converter.ConvertString(rtfContent, outputDocxStream); ``` ``` -------------------------------- ### Append Markdown to DOCX Document Source: https://github.com/manfromarce/docsharp/wiki/Convert-Markdown-documents Appends converted Markdown content to an existing Word document. Use this when you want to add Markdown content to a document that already has content or custom styles. ```cs converter.AppendToDocument(markdown, wpDocument); ``` ```cs converter.ToDocx(markdown, "template.docx", append: true); ``` -------------------------------- ### Convert RTF to byte array Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Converts an RTF file into a byte array representing the DOCX content. ```APIDOC ## Convert RTF to byte array ### Description Converts an RTF file directly into a byte array, which can be useful for sending over a network or storing in memory. ### Method Signature `converter.ConvertToBytes(string inputRtfFilePath)` ### Parameters - **inputRtfFilePath** (string) - Required - The path to the input RTF file. ### Response #### Success Response - **byte[]** - A byte array containing the DOCX file content. ### Request Example ```cs byte[] docxBytes = converter.ConvertToBytes("input.rtf"); ``` ``` -------------------------------- ### Convert RTF with UTF-8 Encoding Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Convert an RTF file using UTF-8 as the default encoding. This is useful for non-conformant RTF documents where control words might contain characters not part of standard ANSI. ```cs var converter = new RtfToDocxConverter(); converter.Convert("input.rtf", "output.docx", WordprocessingDocumentType.Document, Encoding.UTF8); ``` -------------------------------- ### Set Default Code Page for RTF Conversion Source: https://github.com/manfromarce/docsharp/wiki/Convert-RTF-documents Specify a default code page (e.g., 1252 for Windows Western) to ensure correct interpretation of characters when the RTF document does not specify its own code page. This is independent of the system's culture settings. ```cs var converter2 = new RtfToDocxConverter() { DefaultCodePage = 1252 }; converter2.Convert("input.rtf", "output.docx"); ``` -------------------------------- ### Export Specific Page to SVG Source: https://github.com/manfromarce/docsharp/wiki/Render-DOCX-documents Exports a specific page of a DOCX document as an SVG file. ```APIDOC ## Export Specific Page to SVG This method exports a single, specified page from a DOCX document as an SVG file. ### Method ```csharp renderer.SaveAsSvg(int pageNumber, string inputDocxPath, string outputSvgPath) ``` ### Parameters - **pageNumber** (int) - Required - The number of the page to export (1-based index). - **inputDocxPath** (string) - Required - The path to the input DOCX file. - **outputSvgPath** (string) - Required - The path where the output SVG file will be saved. ### Request Example ```csharp var renderer = new DocxRenderer() { ImageConverter = new ImageSharpConverter() }; // save first page as SVG (the page number must be between 1 and pages count) renderer.SaveAsSvg(1, "input.docx", "output-page1.svg"); // streams are also supported ``` ``` -------------------------------- ### Convert DOCX to Plain Text Source: https://github.com/manfromarce/docsharp/wiki/Convert-DOCX-documents Extracts plain unformatted text from DOCX documents. Text is extracted from most elements including paragraphs, hyperlinks, text boxes, and tables. Table layout is maintained, but nested tables are ignored. ```cs var converter = new DocxToTxtConverter(); converter.Convert(inputFilePath, "output.txt"); // file paths or streams; inputFile may also be a WordprocessingDocument object ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.