ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Convert Word Document to PDF in ASP.Net MVC<p>Hi khushboo,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>For this example i have used&nbsp;Microsoft.Office.Interop library. You need to add the&nbsp;Microsoft.Office.Interop library reference in your projet.</p> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <pre class="brush: csharp">using Word = Microsoft.Office.Interop.Word;</pre> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } [HttpPost] public FileResult Convert(HttpPostedFileBase postedFile) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(postedFile.FileName); string filePath = Server.MapPath(&#34;~/Files/&#34;) + Path.GetFileName(postedFile.FileName); postedFile.SaveAs(filePath); string input = filePath; string output = Server.MapPath(&#34;~/Files/&#34;) + fileNameWithoutExtension + &#34;.pdf&#34;; ConvertWordToSpecifiedFormat(input, output, Word.WdSaveFormat.wdFormatPDF); return File(output, &#34;application/pdf&#34;, fileNameWithoutExtension + &#34;.pdf&#34;); } private static void ConvertWordToSpecifiedFormat(object input, object output, object format) { Word._Application application = new Word.Application(); application.Visible = false; object missing = Missing.Value; object isVisible = true; object readOnly = false; Word._Document document = application.Documents.Open(ref input, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); document.Activate(); document.SaveAs(ref output, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); application.Quit(ref missing, ref missing, ref missing); } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;div&gt; &lt;%using (Html.BeginForm(&#34;Convert&#34;, &#34;Home&#34;, FormMethod.Post, new { enctype = &#34;multipart/form-data&#34; })) { %&gt; &lt;input type=&#34;file&#34; name=&#34;postedFile&#34; /&gt;&lt;br /&gt;&lt;br /&gt; &lt;input type=&#34;submit&#34; value=&#34;Convert Word To PDF&#34; /&gt; &lt;% } %&gt; &lt;/div&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshots</span></strong></p> <p><span style="text-decoration: underline;">The Word File</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/XUileIZ.jpg" alt="" width="472" height="189" /></span></p> <p><span style="text-decoration: underline;">The converted PDF</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/JqUG41h.gif" alt="" width="398" height="268" /></span></p>https://www.aspforums.net:443/Threads/944547/Convert-Word-Document-to-PDF-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/944547/Convert-Word-Document-to-PDF-in-ASPNet-MVC/Tue, 30 Apr 2019 03:13:59 GMT