Convert DOCX to PDF in C#
This code example demonstrates how IronPDF provides users with a concise, easy-to-implement method for converting any Microsoft Word Document to PDF. With this, you can convert your DOCX files to high-quality PDF documents in just a couple of lines.
Steps to Convert DOCX to PDF in C#
// Instantiate the renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render the DOCX file as a PDF document
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF document to a file
pdf.SaveAs("pdfFromDocx.pdf");
// Instantiate the renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render the DOCX file as a PDF document
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF document to a file
pdf.SaveAs("pdfFromDocx.pdf");
' Instantiate the renderer
Dim renderer As New DocxToPdfRenderer()
' Render the DOCX file as a PDF document
Dim pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")
' Save the PDF document to a file
pdf.SaveAs("pdfFromDocx.pdf")
The first step is to instantiate the renderer. The DocxToPdfRenderer
class handles the conversion of DOCX files into PDF format without losing any of the original quality. Here, we have named our renderer "renderer," making it easy to reference and access its methods. This takes us to the next step, where we use the RenderDocxAsPdf
method to convert the DOCX file we have provided into a new PdfDocument
object. Once this is done, the newly created PDF document can be further manipulated with the IronPDF library, should you need to.
Finally, we save the PDF document using the SaveAs
method, which will save the PDF to the specified file location with the set name. This is a comprehensive and easy-to-use method for DOCX to PDF conversion, saving you time with its minimal setup; while also giving you access to further methods that can be used to fully customize and control how the output PDF document will appear.
Click here to view the How-to Guide, including examples, sample code, and files