Word to PDF Converter |
The Word to PDF converter, PdfConverter, converts Word documents to PDF without Microsoft Word: .docx, .docm, .dotx, .dotm, .doc, .dot, RTF, WordML, plain text, and also HTML and Markdown read as Word documents. The document is laid out by a Word layout engine in the library, on Windows, Linux and macOS.
using ExpertPdf.Anywhere.WordToPdf; PdfConverter converter = new PdfConverter(); // converter.LicenseKey = "your license key"; // page numbers in the footer converter.PdfDocumentOptions.ShowFooter = true; converter.PdfFooterOptions.ShowPageNumber = true; converter.SavePdfFromWordFileToFile("report.docx", "report.pdf");
The document can come from a file, a stream or bytes (GetPdfBytesFromWordFile, GetPdfBytesFromWordStream, GetPdfBytesFromWordBytes, and the SavePdfFrom... methods). The format is found from the file extension or from the content; pass a WordFormat to set it. A password protected document needs Password.
By default (PageSetup = WordPageSetup.Document) the PDF pages take the page sizes and margins of the Word document, a different size per section included. With WordPageSetup.Options the document is laid out again on the page size, orientation and margins of PdfDocumentOptions:
PdfConverter converter = new PdfConverter(); converter.PageSetup = WordPageSetup.Options; converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; converter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape; converter.PdfDocumentOptions.LeftMargin = 36; converter.PdfDocumentOptions.RightMargin = 36; byte[] pdf = converter.GetPdfBytesFromWordFile("report.docx");
Bookmarks: the PDF outline from the headings (the default), from the bookmarks of the document, or none.
PageRanges: convert only some pages, for example "1-3,5".
UpdateFields: update the fields (page numbers, table of contents) before the conversion.
PreserveFormFields: keep the form fields of the document as PDF form fields.
PdfStandardSubset and AccessibilityStandard: PDF/A, PDF/X and tagged PDF/UA output; set Language and the title for an accessible document.
The header and footer options (title, footer text, page numbers, a Word document as header or footer with WordToPdfArea), the security options and the document information work as they do for the HTML to PDF converter.
A font the document uses and the host does not have is replaced by a font with the same metrics; on Linux and macOS hosts without fonts, add the ExpertPdf.Anywhere.Fonts package.