3

Hi I am trying to convert DOCX to PDF conversion in C# Console application.

I found similar questions in stack overflow but didn't get the proper answer means unable to proceed with those approaches.

string strFolderPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
strFolderPath = "E:\\Test\\TestDocument\\TemplateFiller\\";
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(@strFileFullPath);
string strPDFFilePath = strFolderPath + "AcknowledgementLetter.pdf";
doc.Activate();
doc.SaveAs2(@strPDFFilePath, WdSaveFormat.wdFormatPDF);
doc.Close();
  1. This code is working locally because ms office installed,but in server it is throwing exceptions, because it requires MS office installation.
  2. iTextSharp is not converting Docx to pdf format.
  3. installed PDF/XPS exporter, but how to provide the reference not able to get.

Can any body provide sample to convert DOCX to PDF without/with licence(cheaper). and usually how we will achieve this functionality. Kindly respond.

Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • Take a look at this CodeProject link: http://www.codeproject.com/Questions/346784/How-to-convert-word-document-to-pdf-in-Csharp – Mr. B Oct 06 '15 at 03:38
  • @Mr.B: I gone through this link, but it is using inter operable dlls which requires ms office installation, as i said because of security reasons we can't install office in server. Could you let me know is there any possibility of converting word to pdf with out word installation – Chaitanya Tallapragada Oct 06 '15 at 03:45
  • I've actually run up against this several times in my career. Unfortunately I think the answer to that question is no. Going from HTML to PDF is really strait forward. HTML to Word is difficult. Word to PDF and visa versa is also very difficult. – Mr. B Oct 06 '15 at 03:50
  • Does the input have to be a Word document? – Mr. B Oct 06 '15 at 03:50
  • @MR B: yes it is word document only – Chaitanya Tallapragada Oct 06 '15 at 03:54
  • 1
    Mohit is right, we ended up going with a COTs solution called SautinSoft, but our scenario was a bit different. – Mr. B Oct 06 '15 at 04:27
  • 1
    Also. It seems like the best approach would be to go ahead and install Word on that server. Or just a shot in the dark here. Try just including the Microsoft.Office.Interop.Word DLLs with your build. – Mr. B Oct 06 '15 at 04:29

1 Answers1

0

I think you can use Spire.PDF for .NET. Free Spire.PDF for .NET is a Community Edition of the Spire.PDF for .NET, which is a totally free PDF component for commercial and personal use. As a standalone C#/VB.NET component, Free Spire.PDF for .NET enables developers to create, write, edit, convert, print, handle and read PDF files on any .NET applications.

NOTE: Free version is limited to 10 pages of PDF.

With Spire.Office for .NET, developers can create a wide range of applications. It enables developers to open, create, modify, convert, print, View MS Word, Excel, PowerPoint and PDF documents. Furthermore, it allows users to export data to popular files such as MS Word/Excel/RTF/Access, PowerPoint, PDF, XPS, HTML, XML, Text, CSV, DBF, Clipboard, SYLK, etc. As an independent Office .NET component, Spire.Office doesn't need Microsoft Office to be installed on neither the development nor target systems. In addition, it is a better alternative to MS Office Automation in terms of security, stability, scalability, speed, price and features.

Mohit S
  • 13,723
  • 6
  • 34
  • 69