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
Other People Are Reading
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.
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
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"
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
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for