I need to convert word file to pdf.
I am using openxml to create word file and save. Now I need to convert that file to pdf without using third party software, dll or library. How can I convert it using openxml?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Smart Media24 reputationPosted Aug 15, 2019, 5:32 PM EDT
For converting DOCX to PDF even with placeholders, I have created a free "Report-From-DocX-HTML-To-PDF-Converter" library with .NET CORE under the MIT license, because I was so unnerved that no simple solution existed and all the commercial solutions were super expensive. You can find it here with an extensive description and an example project: https://github.com/smartinmedia/Net-Core-DocX-HTML-To-PDF-Converter
It can perform these conversions (alongside a template / report engine, which replaces placeholders):
You can add placeholders for:
Darshan Patel125 reputationPosted Aug 21, 2023, 8:14 AM EDT
its not easy to found the proper library but i found this and its working i hope its usefull to you
download this library manually and install in nuget package
then store this in "C:\Program Files (x86)\Microsoft SDKs\NuGetPackages"itext.8.0.1.nupkg
itext.bouncy-castle-adapter.8.0.1.nupkg
its availble on this path
https://github.com/itext/itext7-dotnet/releases/tag/8.0.1
private readonly ILogger _logger; private readonly string wordDocumentPath = "WordDocuments/SampleWordDocument.docx"; // Provide the actual path to your Word document. private readonly string pdfFilePath = @"D:\CoreDemoWordtoPdf\WordDocToPdf\WordDocToPdf\PdfFiles\Output.pdf"; public IActionResult ConvertToPdf() { string pdfFileName = "ConvertedDocument.pdf"; string pdfFilePath = Path.Combine(Directory.GetCurrentDirectory(), "PdfFiles", pdfFileName); using (MemoryStream wordStream = new MemoryStream(System.IO.File.ReadAllBytes(wordDocumentPath))) { bool conversionResult = WordToPdfConverter.ConvertWordToPdf(wordStream, pdfFilePath); if (conversionResult) { byte[] pdfBytes = System.IO.File.ReadAllBytes(pdfFilePath); return File(pdfBytes, "application/pdf", pdfFileName); } else { return Content("Word to PDF conversion failed."); } } } public static bool ConvertWordToPdf(Stream wordStream, string pdfFilePath) { using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(wordStream, false)) { using (var pdfWriter = new PdfWriter(pdfFilePath)) { using (var pdfDocument = new PdfDocument(pdfWriter)) { using (var document = new iText.Layout.Document(pdfDocument)) { foreach (var paragraph in wordDocument.MainDocumentPart.Document.Body.Elements()) { string text = paragraph.InnerText; document.Add(new iText.Layout.Element.Paragraph(text)); } } } } } return true; }i hope this is usefull
Abhishek YadavRank #217 · 11.3K reputationPosted Aug 21, 2023, 9:03 PM EDT
https://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically
Satyendra PatelRank #1,411 · 1.2K reputationPosted Jan 8, 2019, 2:25 AM EST
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 8, 2019, 2:55 AM EST
Sapna GirishRank #1,811 · 819 reputationPosted Jan 8, 2019, 2:13 PM EST
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 8, 2019, 6:39 PM EST
Mohamed AbedallahRank #2,074 · 697 reputationPosted Aug 22, 2019, 5:04 AM EDT
Using LEADTOOLS, the code is simple and similar to this:
For more info see this page:
https://www.leadtools.com/sdk/document/document-converter
If you don’t use library directly in your application, you can use the cloud services for converting word to PDF, see this link:
https://services.leadtools.com/documentation/api-reference/convert
Mohammad HussainRank #513 · 4.8K reputationPosted Aug 24, 2023, 12:36 AM EDT
You could use the Microsoft Office Interop libraries to automate Microsoft Word to open the document and then save it as a PDF. However, this approach requires Microsoft Word to be installed on the machine running the code, and it's generally not recommended for server-side applications due to potential reliability and licensing issues.