Class DocxToPdfRenderer
Converts Microsoft Word documents (.docx) to PDF with perfect formatting preservation. Maintains tables, images, headers, footers, styles, and complex layouts exactly as they appear in Word.
// Simple conversion:
var renderer = new DocxToPdfRenderer();
var pdf = renderer.RenderDocxAsPdf("contract.docx");
pdf.SaveAs("contract.pdf");
// With custom margins:
var options = new DocxPdfRenderOptions {
MarginTop = 20,
MarginBottom = 20,
PaperSize = PdfPaperSize.Letter
};
var pdf = renderer.RenderDocxAsPdf("report.docx", options);
// From stream (web upload):
using (var stream = uploadedFile.OpenReadStream()) {
var pdf = renderer.RenderDocxAsPdf(stream);
pdf.SaveAs($"converted_{uploadedFile.FileName}.pdf");
}Preserves Word formatting better than Office interop or OpenXML
Only supports .docx format (not .doc legacy format)
See: https://ironpdf.com/how-to/docx-to-pdf/
Inheritance
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public class DocxToPdfRenderer : Object
Use DocxToPdfRenderer in IronPDF when a C# application works with PDF generation. It represents converts Microsoft Word documents (.DOCX) to PDF with perfect formatting preservation.
DocxToPdfRenderer matters when an application needs to configure or invoke PDF generation from C# code. The class encapsulates the related options and behavior in a single object that is set up once and reused across render or processing calls. Typical scenarios include batch generation pipelines, templated document workflows, and integration with existing C# document services.
To use DocxToPdfRenderer, instantiate or obtain it from the relevant entry point in the IronPDF C# API. Key properties include RenderingOptions. Assign options or invoke methods on the instance to configure or perform the operation. The DOCX to PDF covers typical usage in C# end to end.
using IronPdf;
var instance = new DocxToPdfRenderer();
var current = instance.RenderingOptions;
instance.RenderDocxAsPdf();For the broader workflow, see the DOCX to PDF example and the DOCX to PDF guide in the IronPDF C# documentation. For broader context, the PDF generation portion of the IronPDF C# API contains related types that work with DocxToPdfRenderer directly. DocxToPdfRenderer exposes additional members beyond those highlighted above; the reference tables on this page list the full set. In application code, treat DocxToPdfRenderer as a configured object that is constructed once and reused across operations rather than instantiated per call. Configuration is generally idempotent: assigning the same property value twice has the same effect as assigning it once. For diagnostic purposes, inspect the relevant DocxToPdfRenderer property after each operation to confirm the configured state. See the constructors, properties, and methods tables below for the complete API surface of DocxToPdfRenderer.
Constructors
DocxToPdfRenderer()
Create a new Docx To PDF renderer.
Declaration
public DocxToPdfRenderer()
DocxToPdfRenderer(DocxPdfRenderOptions)
Create a new Docx to PDF renderer using the specified options
Declaration
public DocxToPdfRenderer(DocxPdfRenderOptions Options)
Parameters
| Type | Name | Description |
|---|---|---|
| DocxPdfRenderOptions | Options | Rendering options |
Properties
RenderingOptions
Rendering options
Declaration
public DocxPdfRenderOptions RenderingOptions { get; set; }
Property Value
| Type | Description |
|---|---|
| DocxPdfRenderOptions |
Methods
RenderDocxAsPdf(Byte[], DocxPdfRenderOptions)
Converts Word document bytes to PDF for in-memory processing without file I/O. Perfect for database BLOBs, API responses, or encrypted document processing.
// From database BLOB:
byte[] docxBytes = GetDocumentFromDatabase(id);
var renderer = new DocxToPdfRenderer();
var pdf = renderer.RenderDocxAsPdf(docxBytes);
SavePdfToDatabase(pdf.BinaryData);
// From API response:
var docxBytes = await httpClient.GetByteArrayAsync(url);
var pdf = renderer.RenderDocxAsPdf(docxBytes);
return File(pdf.BinaryData, "application/pdf");No temporary files created - all processing in memory
Large documents may require substantial memory
Declaration
public PdfDocument RenderDocxAsPdf(byte[] WordDocumentBytes, DocxPdfRenderOptions Options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | WordDocumentBytes | The word document byte array to be rendered as a PDF. |
| DocxPdfRenderOptions | Options | An instance of DocxPdfRenderOptions that allows configuration of DocxRenderer "Docx to PDF" rendering parameters. |
Returns
| Type | Description |
|---|---|
| PdfDocument | A PdfDocument with the Docx rendered as its contents. |
RenderDocxAsPdf(Stream, DocxPdfRenderOptions)
Converts Word document stream to PDF for web uploads and cloud storage integration. Ideal for ASP.NET file uploads, Azure Blob storage, or any stream-based workflow.
// Web upload conversion:
[HttpPost]
public IActionResult ConvertUpload(IFormFile file) {
using (var stream = file.OpenReadStream()) {
var renderer = new DocxToPdfRenderer();
var pdf = renderer.RenderDocxAsPdf(stream);
return File(pdf.BinaryData, "application/pdf",
$"{Path.GetFileNameWithoutExtension(file.FileName)}.pdf");
}
}
// Azure Blob conversion:
var blobStream = await blobClient.OpenReadAsync();
var pdf = renderer.RenderDocxAsPdf(blobStream);
await SaveToBlob(pdf.Stream);Stream position is reset automatically if seekable
Stream must be readable and contain valid .docx data
See: https://ironpdf.com/how-to/docx-to-pdf/#stream-conversion
Declaration
public PdfDocument RenderDocxAsPdf(Stream WordDocumentStream, DocxPdfRenderOptions Options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | WordDocumentStream | The word document stream to be rendered as a PDF. |
| DocxPdfRenderOptions | Options | An instance of DocxPdfRenderOptions that allows configuration of DocxRenderer "Docx to PDF" rendering parameters. |
Returns
| Type | Description |
|---|---|
| PdfDocument | A PdfDocument with the Docx rendered as its contents. |
RenderDocxAsPdf(String, DocxPdfRenderOptions)
Converts a Word document file to PDF with full formatting fidelity. Preserves complex layouts, styles, images, tables, headers/footers exactly as they appear in Word.
// Simple conversion:
var renderer = new DocxToPdfRenderer();
var pdf = renderer.RenderDocxAsPdf(@"C:\Documents\report.docx");
pdf.SaveAs("report.pdf");
// With custom settings:
var options = new DocxPdfRenderOptions {
PaperSize = PdfPaperSize.A4,
MarginTop = 10,
MarginBottom = 10
};
var pdf = renderer.RenderDocxAsPdf("invoice.docx", options);
// Add watermark after conversion:
var pdf = renderer.RenderDocxAsPdf("contract.docx");
pdf.AddWatermark("DRAFT");
pdf.SaveAs("contract-draft.pdf");Headers and footers from Word are automatically preserved
See: https://ironpdf.com/examples/docx-to-pdf/
Declaration
public PdfDocument RenderDocxAsPdf(string WordDocumentPath, DocxPdfRenderOptions Options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | WordDocumentPath | The word document full path to be rendered as a PDF. |
| DocxPdfRenderOptions | Options | An instance of DocxPdfRenderOptions that allows configuration of DocxRenderer "Docx to PDF" rendering parameters. |
Returns
| Type | Description |
|---|---|
| PdfDocument | A PdfDocument with the Docx rendered as its contents. |
RenderDocxAsPdfAsync(String, DocxPdfRenderOptions)
, Creates a PDF file from an Word document and returns it as an PdfDocument object which can be edited and saved to disk or served on a website.
Async version of the RenderDocxAsPdf method.
Declaration
public Task<PdfDocument> RenderDocxAsPdfAsync(string WordDocumentPath, DocxPdfRenderOptions Options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | WordDocumentPath | The word document full path to be rendered as a PDF. |
| DocxPdfRenderOptions | Options | An instance of DocxPdfRenderOptions that allows configuration of DocxRenderer "Docx to PDF" rendering parameters. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<PdfDocument> | A PdfDocument with the Docx rendered as its contents. |
RenderDocxMailMergeAsPdf<TRecipientsDataModel>(List<TRecipientsDataModel>, String, DocxPdfRenderOptions)
Declaration
public IEnumerable<PdfDocument> RenderDocxMailMergeAsPdf<TRecipientsDataModel>(List<TRecipientsDataModel> recipientsDataList, string WordDocumentPath, DocxPdfRenderOptions Options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.List<TRecipientsDataModel> | recipientsDataList | |
| System.String | WordDocumentPath | |
| DocxPdfRenderOptions | Options |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<PdfDocument> |
Type Parameters
| Name | Description |
|---|---|
| TRecipientsDataModel |
RenderDocxMailMergeAsPdfAsync<TRecipientsDataModel>(List<TRecipientsDataModel>, String, DocxPdfRenderOptions)
Creates a PDF file from an Word document and returns it as an PdfDocument object which can be edited and saved to disk or served on a website.
Async version of the RenderDocxAsPdf method.
Declaration
public Task<IEnumerable<PdfDocument>> RenderDocxMailMergeAsPdfAsync<TRecipientsDataModel>(List<TRecipientsDataModel> RecipientsDataList, string WordDocumentPath, DocxPdfRenderOptions Options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.List<TRecipientsDataModel> | RecipientsDataList | List of recepient data |
| System.String | WordDocumentPath | The word document full path to be rendered as a PDF. |
| DocxPdfRenderOptions | Options | An instance of DocxPdfRenderOptions that allows configuration of DocxRenderer "Docx to PDF" rendering parameters. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<PdfDocument>> | A PdfDocument with the Docx rendered as its contents. |
Type Parameters
| Name | Description |
|---|---|
| TRecipientsDataModel |