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
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 |