Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Creating an Instance of CAcroACDoc for .DOC to .PDF Conversion

Status
Not open for further replies.

reffek

Programmer
Apr 7, 2005
24
0
0
US
Here's a snippet of code I am using to convert MS Word docs to PDFs. Similar code works fine in VB6 but in VB.NET is gives me the error "Object reference not set to an instance of an object." The error occurs on this line:

Code:
AcroDoc.Open("\\path\to\file\test.doc", "")

Here is the full snippet:

Code:
Imports Acrobat

Dim AcroApp As CAcroApp
Dim AcroDoc As CAcroAVDoc
Dim AcroPdf As CAcroPDDoc

AcroDoc.Open("\\path\to\file\test.doc", "")
AcroDoc = AcroApp.GetActiveDoc
AcroPdf = AcroDoc.GetPDDoc
AcroPdf.Save(1 Or 4 Or 32, "\\path\to\file\test.pdf")

AcroPdf.Close()
AcroDoc.Close(True)
AcroApp.Exit()

AcroPdf = Nothing
AcroDoc = Nothing
AcroApp = Nothing
 
Code:
AcroDoc.Open("\\path\to\file\test.doc", "")
AcroDoc = AcroApp.GetActiveDoc

Are you sure that's right? Opening a file w/ AcroDoc, then overrighting the value of AcroDoc with AcroApp.GetActiveDoc?

I think this might be what you are looking for:
Code:
Imports Acrobat

Dim AcroApp As [b]New[/b] CAcroApp
Dim AcroDoc As CAcroAVDoc
Dim AcroPdf As CAcroPDDoc

[b]AcroApp[/b].Open("\\path\to\file\test.doc", "")
AcroDoc = AcroApp.GetActiveDoc
AcroPdf = AcroDoc.GetPDDoc
AcroPdf.Save(1 Or 4 Or 32, "\\path\to\file\test.pdf")

AcroPdf.Close()
AcroDoc.Close(True)
AcroApp.Exit()

AcroPdf = Nothing
AcroDoc = Nothing
AcroApp = Nothing
(changes in bold)

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Code:
Dim AcroApp As New CAcroApp
Causes "'New' cannot be used on an interface
 
Also, "Open" is not a member of "CAcroApp"

Like I stated, it was working in VB6... But for some reason .NET can't create the object properly.
 
Ok, drop the new, what about the other part? I'm not familiar with the classes you are using, but did the other change look like it made sence?

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Open" is not a member of "CAcroApp
 
one more try:
Code:
Imports Acrobat

Dim AcroDoc As New CAcroAVDoc
Dim AcroPdf As CAcroPDDoc

AcroDoc.Open("\\path\to\file\test.doc", "")
AcroPdf = AcroDoc.GetPDDoc
AcroPdf.Save(1 Or 4 Or 32, "\\path\to\file\test.pdf")

AcroPdf.Close()
AcroDoc.Close(True)

AcroPdf = Nothing
AcroDoc = Nothing

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
You might want to contact the vendor/maker of the tool you're using.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top