How to Convert Word to PDF with VB.Net

Written by jeff grundy Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert Word to PDF with VB.Net
(Siri Stafford/Lifesize/Getty Images)

If you are developing a document-management application in VB.Net, you might find a method of converting Microsoft Word documents to PDF files through automation very useful. If you need your application to convert the documents to the PDF format to prevent changes or edits, then coding a class or module to do just that will save users of your application a lot of time when conversions are needed.

Skill level:
Moderately Challenging


  1. 1

    Create a Word application class that opens a document. Create the variable class to open a document named "myfilename.doc" or something similar. Insert the following code into a module in VB.Net:

    Dim word =new ApplicationClass();

    Dim word_file =path as Object

    Word.Document opened_doc = word.Documents.Open(ref word_file, ref null, ref null, ref null, ref null, ref null,ref null, ref null, ref null, ref null, ref null, ref null);

    Be sure the "null" values are present in the above code to open the document using default parameters unless you need to open the document in a specific view or need to enable other special Word features on opening the document.

  2. 2

    Create a function that copies the content of the Word document to the Windows clipboard. To do this, use the "WholeStory" VBA command to simulate the task of pressing the "Ctrl" and "A" keys at the same time to highlight and select all the objects and text in the document. Use the "Copy" command to insert the highlighted objects in the Windows Clipboard. To do this, insert the following code into the function:



    Dim clip =Clipboard.GetDataObject

  3. 3

    Code an object variable to create a new PDF and transfer content from the Word document. Paste the following code into the new object:

    Dim mypdf As New mjwPDF

    mypdf.PDFFileName = "word_transfer.pdf"

    mypdf.PDFTextOut clip.ToString

  4. 4

    Insert code to close both the Word and PDF documents by pasting the following code at the end of the function:

    Set word = nothing

    Set opened_doc = nothing

    Set mypdf = nothing

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.