locked
Converting Ms Word to Pdf format RRS feed

  • Question

  • There are so many third party library or sites to convert Ms doc/docx file to pdf format. Unfortunately they all have limitations and expensive. i coudn't find a free tools for it. i added reference "Microsoft Word 15.0 Object Library"

    But it needs to Office 2013 installed in your Pc. I couldn't run it in another computer which has earlier versions of Office(for example office 2003). i also tried to copy dll files as independed outside the office as new reference, it doesn't work either. i have been searching for it one week. i don't know why people hesisate to share it even though there are so many online site for it. Finally i lost my hope to find it in web.

    Would you help me how i can do it with/without using Ms Office? i will be so happy if someone help me about it.

         Dim MyWordDoc As Word.Document = MyApp.Documents.Add(TextBox1.Text)
    
                MyApp.Visible = True
    
                MyWordDoc = MyApp.ActiveDocument
    
                'code to fill doc
    
                'code to fill doc
    
                'code to fill doc
    
                MyWordDoc.SaveAs(sf.FileName, Word.WdSaveFormat.wdFormatPDF)



    • Edited by ulasank Monday, March 9, 2015 4:18 PM
    Monday, March 9, 2015 4:15 PM

Answers

  • Converting a Word document to PDF, without Microsoft Word, is a rather complicated process especially if both .doc (structured storage) and .docx (XML) types are supported. For this reason you won't see developers giving it away for free.

    I think your best bet would be to use Microsoft Word automation (late binding) and a free PDF printer driver called CutePDF. Instead of saving the document to PDF you print it instead, which means it's version independent as far as Microsoft Word is concerned.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by ryguy72 Monday, March 9, 2015 7:14 PM
    • Marked as answer by ulasank Monday, March 9, 2015 7:16 PM
    Monday, March 9, 2015 6:04 PM

All replies

  • Converting a Word document to PDF, without Microsoft Word, is a rather complicated process especially if both .doc (structured storage) and .docx (XML) types are supported. For this reason you won't see developers giving it away for free.

    I think your best bet would be to use Microsoft Word automation (late binding) and a free PDF printer driver called CutePDF. Instead of saving the document to PDF you print it instead, which means it's version independent as far as Microsoft Word is concerned.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by ryguy72 Monday, March 9, 2015 7:14 PM
    • Marked as answer by ulasank Monday, March 9, 2015 7:16 PM
    Monday, March 9, 2015 6:04 PM
  • There is no free lunch and so 3rd party libraries come with a cost. But they can save time so they pay for themselves quite soon.

    So if you will be considering third party tools, Docentric may also fit your needs. It supports document generation based on templates and it also supports document creation programmatically. It supports docx, pdf and xps output.

    Don't use Interop (Office COM) on servers. Office automation has not been designed for such scenarios (see KB 257757). You should definitely use OpenXML (either directly or via 3rd party toolkit).


    Monday, March 23, 2015 10:35 PM