473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adobe acrobat doesn't close my files?

Hi,

I use Adobe Acrobat to read tekst from PDF files. After that the file has
been read, I move the file in a folder (using the date I got from the text I
got from Acrobat). Now here is my problem. When I want to move the file, I
get an error stating:
System.IO.IOExc eption: The process cannot access the file
"x:\VF\2006-01\CVF-06000007.pdf" because it is being used by another
process.

Acrobat just doesn't want to close the file after it has been readed. I have
tried a few things like : (AcroApp is my AcroExch.App Object)

AcroApp.Close()
AcroApp.CloseAl lDocs()
AcroApp.Exit()

However none seem to work. Can anybody help my close the file so the program
can move the pdf to where it belongs?

Thanks
Joris
Apr 5 '06 #1
3 9815

I had similar problems working with PDFs using Acrobat 7.0

Are you using the Acrobat.CAcroPD Doc and/or Acrobat.CAcroAV Doc classes
for opening/reading the document?

If yes,
Are you closing these when you are finished with them?
Are you using IDisposable so that you control when they are
released?

The above
AcroApp.Close()
AcroApp.CloseAl lDocs()
AcroApp.Exit()

will close the docs 'as far as Acrobat is concerned' but if you
have a reference to a document in your code the document will still be
used 'as far as the OS is concerned' until the reference releases -
which is why I ended up implementing IDisposable to control when they
released.
hth,
Alan.

Apr 5 '06 #2
What I did was wrap both the application and document in classes.
Wrapping the application was more for tidiness for me. You may not need
it.

When reading a document I would create a new instance of the document
wrapper class

e.g.

_adobeDoc = New AdobeDocument(f Name, createCopy, storagePath)

And then when closing it I would dispose of it

_adobeDoc.Dispo se()

_adobeDoc = nothing

The Dispose calls close on the avDoc and pdDoc and also decrements the
COM reference count (that's basically what the ReleaseComObjec t()
call does)

and then sets the reference to the COM object to nothing.

At this point we should have totally released the document and you
should be able to delete it.

Worked for me,

Hope it works for you.

Alan.



Application class

=============== ==

Public Class AdobeApplicatio n

Implements IDisposable

#Region "Constants"

'
=============== =============== =============== =============== ============

'* AVZoomType -- Variable zoom "verbs", corresponding to View menu
items *'

Public Const AVZoomNoVary As Short = 0 ' no variable zoom - use
this for XYZ zoom

Public Const AVZoomFitPage As Short = 1 ' fit page to window

Public Const AVZoomFitWidth As Short = 2 ' fit page width to window

Public Const AVZoomFitHeight As Short = 3 ' fit page height to
window

Public Const AVZoomFitVisibl eWidth As Short = 4 ' fit visible width
to window

Public Const AVZoomPreferred As Short = 5 '/* use page's preferred
zoom */

Public Const AV_EXTERNAL_VIE W As Short = 1 ' Open the document with
tool bar visible

Public Const AV_DOC_VIEW As Short = 2 ' Draw the page pane and
scrollbars

Public Const AV_PAGE_VIEW As Short = 4 ' Draw only the page pane

'************** *************** **** PD Things
*************** *************** *****'

'* PDPageMode -- Variable for how the file opens - bookmarks,
thumbnails, full screen, none *'

Public Const PDDontCare As Short = 0

Public Const PDUseNone As Short = 1

Public Const PDUseThumbs As Short = 2

Public Const PDUseBookmarks As Short = 3

Public Const PDFullScreen As Short = 4

'* PDLayoutMode -- Variable for how the file is opened - single
page, one column, two column *'

Public Const PDLayoutDontCar e As Short = 0

Public Const PDLayoutSingleP age As Short = 1

Public Const PDLayoutOneColu mn As Short = 2

Public Const PDLayoutTwoColu mnLeft As Short = 3

Public Const PDLayoutTwoColu mnRight As Short = 4

'
=============== =============== =============== =============== ============

Public Const MIN_ZOOM_PCT As Integer = 50

Public Const MAX_ZOOM_PCT As Integer = 600

Public Const ERR_MSG_INVALID _ZOOM As String = _

"Allowable Zoom Percentages are {0}% to {1}%."

'
=============== =============== =============== =============== ============

Public Const CLASS_NAME_APPL ICATION As String = "AcroExch.A pp"

Public Const CLASS_NAME_AVDO C As String = "AcroExch.AVDoc "

Public Const CLASS_NAME_PDDO C As String = "AcroExch.PDDoc "

Public Const CLASS_NAME_PDPA GE As String = "AcroExch.PDPag e"

Public Const CLASS_NAME_ACRO _RECT As String = "AcroExch.R ect"

Private Const ERR_MSG_CREATE_ FAIL As String = _

"Unable to create an instance of the Acrobat application
because: {0}"

Private Const ERR_MSG_UNKNOWN As String = _

"Unknown Reason."

Private Const ERR_MSG_UNABLE_ TO_LOCK As String = _

"Unable to lock the Acrobat Instance."

Private Const ERR_MSG_UNABLE_ TO_CREATE_DOC As String = _

"Unable to create the document object."

Private Const ERR_MSG_UNABLE_ TO_OPEN_FILE As String = _

"Unable to open the {0}. Reason = {1}."

#End Region

#Region "ctors"

Public Sub New()

Me.New(False)

End Sub

Public Sub New( _

ByVal bLock As Boolean _

)

_acroApp = GetAcrobatAppIn stance()

_appInstanceNam e = String.Empty

If (bLock) Then

_locked = CType(_acroApp. Lock(AppInstanc eName), Boolean)

If (Not _locked) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_LOC K))

End If

End If

End Sub

#End Region

#Region "Properties "

Public ReadOnly Property AppInstanceName () As String

Get

If (_appInstanceNa me Is Nothing _

OrElse _appInstanceNam e.Length = 0) Then

_appInstanceNam e = CreateAppInstan ceName()

End If

Return _appInstanceNam e

End Get

End Property

#End Region

#Region "Methods"

Public Function LoadPDDocument( _

ByVal fName As String _

) As Acrobat.CAcroPD Doc

Dim pdDoc As Acrobat.CAcroPD Doc

pdDoc = CType(CreateObj ect(CLASS_NAME_ PDDOC),
Acrobat.CAcroPD Doc)

If (pdDoc Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_DOC))

End If

Dim bOK As Boolean

Dim strReason As String = ERR_MSG_UNKNOWN

Dim except As Exception

Try

bOK = CType(pdDoc.Ope n(fName), Boolean)

Catch ex As Exception

strReason = ex.Message

End Try

If (Not bOK) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_OPE N_FILE, _

fName, _

strReason), _

except)

End If

Return pdDoc

End Function

Private Function CreateAppInstan ceName() As String

Return System.Guid.New Guid.ToString

End Function

' creates an application instance and returns it.

' throws an exception if unable to create

Private Function GetAcrobatAppIn stance() As Acrobat.CAcroAp p

Dim appInstance As Acrobat.CAcroAp p

Dim strReason As String = String.Empty

Try

appInstance = CType(CreateObj ect(CLASS_NAME_ APPLICATION),
Acrobat.CAcroAp p)

If (appInstance Is Nothing) Then

strReason = ERR_MSG_UNKNOWN

End If

Catch ex As Exception

strReason = ex.Message

Finally

If (strReason.Leng th > 0) Then
System.Runtime. InteropServices .Marshal.Releas eComObject(appI nstance)

Throw New Exception(Strin g.Format(ERR_MS G_CREATE_FAIL,
strReason))

End If

End Try

Return appInstance

End Function

#End Region

#Region "Attributes "

Private _locked As Boolean

Private _appInstanceNam e As String

Private _acroApp As Acrobat.CAcroAp p

#End Region

#Region " IDISPOSABLE IMPLEMENTATION "

#Region "Methods"

Protected Overrides Sub Finalize()

Dispose(False)

End Sub

Public Overloads Sub Dispose() Implements
System.IDisposa ble.Dispose

Dispose(True)

GC.SuppressFina lize(Me)

End Sub

Public Overloads Sub Dispose( _

ByVal bDisposing As Boolean _

)

If (Not _disposed) Then

If (bDisposing) Then

'disposed Managed resources

End If

' dispose unmanaged resources

If (_locked) Then

_acroApp.Unlock Ex(AppInstanceN ame)

End If
System.Runtime. InteropServices .Marshal.Releas eComObject(_acr oApp)

End If

_disposed = True

End Sub



#End Region

#Region "Attributes "

Private _disposed As Boolean

#End Region

#End Region

#Region "Shared Functionality"

#Region "Methods"

Public Shared Function IsValidZoomPct( _

ByVal zoomPct As Integer _

) As Boolean

Return (zoomPct >= MIN_ZOOM_PCT _

And zoomPct <= MAX_ZOOM_PCT)

End Function

Public Shared Function InvalidZoomPctM essage() As String

Return String.Format(E RR_MSG_INVALID_ ZOOM, MIN_ZOOM_PCT,
MAX_ZOOM_PCT)

End Function

#End Region

#End Region

End Class

Document Class:

===============

Public Class AdobeDocument

Implements IDisposable

#Region "Konstants"

Private Const ERR_MSG_UNKNOWN As String = _

"Unknown Reason."

Private Const ERR_MSG_UNABLE_ TO_CREATE_PDDOC As String = _

"Unable to create the PD Document object."

Private Const ERR_MSG_UNABLE_ TO_CREATE_AVDOC As String = _

"Unable to create the AV Document object."

Private Const ERR_MSG_UNABLE_ TO_OPEN_FILE As String = _

"Unable to open the {0}. Reason = {1}."

Private Const ERR_MSG_NO_SIZE As String = _

"Unable to generate a size for the page."

Private Const ERR_MSG_UNABLE_ TO_CREATE_PAGE As String = _

"Unable to read page {0} for the document."

#End Region

#Region "Ctors"

Public Sub New( _

ByVal fName As String, _

ByVal createCopy As Boolean _

)

Me.New(fName, createCopy, String.Empty)

End Sub

Public Sub New( _

ByVal fName As String, _

ByVal createCopy As Boolean, _

ByVal storagePath As String _

)

Try

_doc = New TemporaryFile(f Name, createCopy, storagePath)

_pdDoc = LoadPDDocument( _doc.FileName)

_avDoc = LoadAVDocument( _doc.FileName)

Finally

If (_pdDoc Is Nothing OrElse _avDoc Is Nothing OrElse _doc
Is Nothing) Then

Dispose(True)

End If

End Try

End Sub

#End Region

#Region "Properties "

Public ReadOnly Property PageCount() As Integer

Get

Return _pdDoc.GetNumPa ges

End Get

End Property

Public Property DeleteOnClose() As Boolean

Get

Return _doc.DeleteOnCl ose

End Get

Set(ByVal Value As Boolean)

_doc.DeleteOnCl ose = Value

End Set

End Property

#End Region

#Region "Methods"

Public Overloads Function PrintSilent() As Boolean

Return PrintSilent(1, PageCount)

End Function

Public Overloads Function PrintSilent( _

ByVal nStartpage As Integer, _

ByVal nEndPage As Integer _

) As Boolean

Dim bRet As Boolean

bRet = CType(_avDoc.Pr intPages(nStart page - 1, _

nEndPage - 1, _

0, _

0, _

0), Boolean)

Return bRet

End Function

Private Function LoadAVDocument( _

ByVal fname As String _

) As Acrobat.CAcroAV Doc

' Create the doc object

Dim avDoc As Acrobat.CAcroAV Doc

avDoc = CType(CreateObj ect(AdobeApplic ation.CLASS_NAM E_AVDOC),
Acrobat.CAcroAV Doc)

If (avDoc Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_AVDOC))

End If

' load the file

Dim bOK As Boolean

Dim strReason As String = ERR_MSG_UNKNOWN

Dim except As Exception

Try

bOK = CType(avDoc.Ope n(fname, fname + "tmp"), Boolean)

Catch ex As Exception

strReason = ex.Message

End Try

If (Not bOK) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_OPE N_FILE, _

fname, _

strReason), _

except)

End If

Return avDoc

End Function

'Create the PDDocument Object and loads the file

Private Function LoadPDDocument( _

ByVal fName As String _

) As Acrobat.CAcroPD Doc

' Create the doc object

Dim pdDoc As Acrobat.CAcroPD Doc

pdDoc = CType(CreateObj ect(AdobeApplic ation.CLASS_NAM E_PDDOC),
Acrobat.CAcroPD Doc)

If (pdDoc Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_PDDOC))

End If

' load the file

Dim bOK As Boolean

Dim strReason As String = ERR_MSG_UNKNOWN

Dim except As Exception

Try

bOK = CType(pdDoc.Ope n(fName), Boolean)

Catch ex As Exception

strReason = ex.Message

End Try

If (Not bOK) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_OPE N_FILE, _

fName, _

strReason), _

except)

End If

Return pdDoc

End Function

Public Function GetPage( _

ByVal nPageNbr As Integer _

) As Acrobat.CAcroPD Page

Dim pdPage As Acrobat.CAcroPD Page

If (Not _pdDoc Is Nothing) Then

pdPage = CType(_pdDoc.Ac quirePage(nPage Nbr),
Acrobat.CAcroPD Page)

If (pdPage Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_PAGE, _

nPageNbr))

End If

End If

Return pdPage

End Function

#End Region

#Region "Attributes "

Private _pdDoc As Acrobat.CAcroPD Doc

Private _avDoc As Acrobat.CAcroAV Doc

Private _doc As TemporaryFile

#End Region

#Region " IDISPOSABLE IMPLEMENTATION "

#Region "Methods"

Public Overloads Sub Dispose() Implements
System.IDisposa ble.Dispose

Dispose(True)

GC.SuppressFina lize(Me)

End Sub

Public Overloads Sub Dispose( _

ByVal bDisposing As Boolean _

)

If (Not _disposed) Then

' need to do this one before the _doc as the _doc will try
to delete the file

' Don't know that we can ever get here with a Nothing value
in _pdDdoc

' but it costs little to check

If (Not _pdDoc Is Nothing) Then

Trace.WriteLine ("Releasing the PD DOC")

_pdDoc.Close()
System.Runtime. InteropServices .Marshal.Releas eComObject(_pdD oc)

_pdDoc = Nothing

End If

If Not _avDoc Is Nothing Then

Trace.WriteLine ("Releasing the AV DOC")

_avDoc.Close(1)
System.Runtime. InteropServices .Marshal.Releas eComObject(_avD oc)

_avDoc = Nothing

End If

If (bDisposing) Then

_doc.Dispose()

End If

End If

_disposed = True

End Sub

Protected Overrides Sub Finalize()

Dispose(False)

End Sub

#End Region

#Region "Attributes "

Private _disposed As Boolean

#End Region

#End Region

End Class

Apr 5 '06 #3
Hi, thanks a lot!! it works now.
I read your code and studied it and I added this:

PDDoc.Close()

System.Runtime. InteropServices .Marshal.Releas eComObject(PDDo c)

avDoc.Close(1)

System.Runtime. InteropServices .Marshal.Releas eComObject(avDo c)

I stayed of the IDisposable things... That gave me quite a few problems
first.

Greetz
Joris
"AlanT" <al*******@user s.com> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
What I did was wrap both the application and document in classes.
Wrapping the application was more for tidiness for me. You may not need
it.

When reading a document I would create a new instance of the document
wrapper class

e.g.

_adobeDoc = New AdobeDocument(f Name, createCopy, storagePath)

And then when closing it I would dispose of it

_adobeDoc.Dispo se()

_adobeDoc = nothing

The Dispose calls close on the avDoc and pdDoc and also decrements the
COM reference count (that's basically what the ReleaseComObjec t()
call does)

and then sets the reference to the COM object to nothing.

At this point we should have totally released the document and you
should be able to delete it.

Worked for me,

Hope it works for you.

Alan.



Application class

=============== ==

Public Class AdobeApplicatio n

Implements IDisposable

#Region "Constants"

'
=============== =============== =============== =============== ============

'* AVZoomType -- Variable zoom "verbs", corresponding to View menu
items *'

Public Const AVZoomNoVary As Short = 0 ' no variable zoom - use
this for XYZ zoom

Public Const AVZoomFitPage As Short = 1 ' fit page to window

Public Const AVZoomFitWidth As Short = 2 ' fit page width to window

Public Const AVZoomFitHeight As Short = 3 ' fit page height to
window

Public Const AVZoomFitVisibl eWidth As Short = 4 ' fit visible width
to window

Public Const AVZoomPreferred As Short = 5 '/* use page's preferred
zoom */

Public Const AV_EXTERNAL_VIE W As Short = 1 ' Open the document with
tool bar visible

Public Const AV_DOC_VIEW As Short = 2 ' Draw the page pane and
scrollbars

Public Const AV_PAGE_VIEW As Short = 4 ' Draw only the page pane

'************** *************** **** PD Things
*************** *************** *****'

'* PDPageMode -- Variable for how the file opens - bookmarks,
thumbnails, full screen, none *'

Public Const PDDontCare As Short = 0

Public Const PDUseNone As Short = 1

Public Const PDUseThumbs As Short = 2

Public Const PDUseBookmarks As Short = 3

Public Const PDFullScreen As Short = 4

'* PDLayoutMode -- Variable for how the file is opened - single
page, one column, two column *'

Public Const PDLayoutDontCar e As Short = 0

Public Const PDLayoutSingleP age As Short = 1

Public Const PDLayoutOneColu mn As Short = 2

Public Const PDLayoutTwoColu mnLeft As Short = 3

Public Const PDLayoutTwoColu mnRight As Short = 4

'
=============== =============== =============== =============== ============

Public Const MIN_ZOOM_PCT As Integer = 50

Public Const MAX_ZOOM_PCT As Integer = 600

Public Const ERR_MSG_INVALID _ZOOM As String = _

"Allowable Zoom Percentages are {0}% to {1}%."

'
=============== =============== =============== =============== ============

Public Const CLASS_NAME_APPL ICATION As String = "AcroExch.A pp"

Public Const CLASS_NAME_AVDO C As String = "AcroExch.AVDoc "

Public Const CLASS_NAME_PDDO C As String = "AcroExch.PDDoc "

Public Const CLASS_NAME_PDPA GE As String = "AcroExch.PDPag e"

Public Const CLASS_NAME_ACRO _RECT As String = "AcroExch.R ect"

Private Const ERR_MSG_CREATE_ FAIL As String = _

"Unable to create an instance of the Acrobat application
because: {0}"

Private Const ERR_MSG_UNKNOWN As String = _

"Unknown Reason."

Private Const ERR_MSG_UNABLE_ TO_LOCK As String = _

"Unable to lock the Acrobat Instance."

Private Const ERR_MSG_UNABLE_ TO_CREATE_DOC As String = _

"Unable to create the document object."

Private Const ERR_MSG_UNABLE_ TO_OPEN_FILE As String = _

"Unable to open the {0}. Reason = {1}."

#End Region

#Region "ctors"

Public Sub New()

Me.New(False)

End Sub

Public Sub New( _

ByVal bLock As Boolean _

)

_acroApp = GetAcrobatAppIn stance()

_appInstanceNam e = String.Empty

If (bLock) Then

_locked = CType(_acroApp. Lock(AppInstanc eName), Boolean)

If (Not _locked) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_LOC K))

End If

End If

End Sub

#End Region

#Region "Properties "

Public ReadOnly Property AppInstanceName () As String

Get

If (_appInstanceNa me Is Nothing _

OrElse _appInstanceNam e.Length = 0) Then

_appInstanceNam e = CreateAppInstan ceName()

End If

Return _appInstanceNam e

End Get

End Property

#End Region

#Region "Methods"

Public Function LoadPDDocument( _

ByVal fName As String _

) As Acrobat.CAcroPD Doc

Dim pdDoc As Acrobat.CAcroPD Doc

pdDoc = CType(CreateObj ect(CLASS_NAME_ PDDOC),
Acrobat.CAcroPD Doc)

If (pdDoc Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_DOC))

End If

Dim bOK As Boolean

Dim strReason As String = ERR_MSG_UNKNOWN

Dim except As Exception

Try

bOK = CType(pdDoc.Ope n(fName), Boolean)

Catch ex As Exception

strReason = ex.Message

End Try

If (Not bOK) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_OPE N_FILE, _

fName, _

strReason), _

except)

End If

Return pdDoc

End Function

Private Function CreateAppInstan ceName() As String

Return System.Guid.New Guid.ToString

End Function

' creates an application instance and returns it.

' throws an exception if unable to create

Private Function GetAcrobatAppIn stance() As Acrobat.CAcroAp p

Dim appInstance As Acrobat.CAcroAp p

Dim strReason As String = String.Empty

Try

appInstance = CType(CreateObj ect(CLASS_NAME_ APPLICATION),
Acrobat.CAcroAp p)

If (appInstance Is Nothing) Then

strReason = ERR_MSG_UNKNOWN

End If

Catch ex As Exception

strReason = ex.Message

Finally

If (strReason.Leng th > 0) Then
System.Runtime. InteropServices .Marshal.Releas eComObject(appI nstance)

Throw New Exception(Strin g.Format(ERR_MS G_CREATE_FAIL,
strReason))

End If

End Try

Return appInstance

End Function

#End Region

#Region "Attributes "

Private _locked As Boolean

Private _appInstanceNam e As String

Private _acroApp As Acrobat.CAcroAp p

#End Region

#Region " IDISPOSABLE IMPLEMENTATION "

#Region "Methods"

Protected Overrides Sub Finalize()

Dispose(False)

End Sub

Public Overloads Sub Dispose() Implements
System.IDisposa ble.Dispose

Dispose(True)

GC.SuppressFina lize(Me)

End Sub

Public Overloads Sub Dispose( _

ByVal bDisposing As Boolean _

)

If (Not _disposed) Then

If (bDisposing) Then

'disposed Managed resources

End If

' dispose unmanaged resources

If (_locked) Then

_acroApp.Unlock Ex(AppInstanceN ame)

End If
System.Runtime. InteropServices .Marshal.Releas eComObject(_acr oApp)

End If

_disposed = True

End Sub



#End Region

#Region "Attributes "

Private _disposed As Boolean

#End Region

#End Region

#Region "Shared Functionality"

#Region "Methods"

Public Shared Function IsValidZoomPct( _

ByVal zoomPct As Integer _

) As Boolean

Return (zoomPct >= MIN_ZOOM_PCT _

And zoomPct <= MAX_ZOOM_PCT)

End Function

Public Shared Function InvalidZoomPctM essage() As String

Return String.Format(E RR_MSG_INVALID_ ZOOM, MIN_ZOOM_PCT,
MAX_ZOOM_PCT)

End Function

#End Region

#End Region

End Class

Document Class:

===============

Public Class AdobeDocument

Implements IDisposable

#Region "Konstants"

Private Const ERR_MSG_UNKNOWN As String = _

"Unknown Reason."

Private Const ERR_MSG_UNABLE_ TO_CREATE_PDDOC As String = _

"Unable to create the PD Document object."

Private Const ERR_MSG_UNABLE_ TO_CREATE_AVDOC As String = _

"Unable to create the AV Document object."

Private Const ERR_MSG_UNABLE_ TO_OPEN_FILE As String = _

"Unable to open the {0}. Reason = {1}."

Private Const ERR_MSG_NO_SIZE As String = _

"Unable to generate a size for the page."

Private Const ERR_MSG_UNABLE_ TO_CREATE_PAGE As String = _

"Unable to read page {0} for the document."

#End Region

#Region "Ctors"

Public Sub New( _

ByVal fName As String, _

ByVal createCopy As Boolean _

)

Me.New(fName, createCopy, String.Empty)

End Sub

Public Sub New( _

ByVal fName As String, _

ByVal createCopy As Boolean, _

ByVal storagePath As String _

)

Try

_doc = New TemporaryFile(f Name, createCopy, storagePath)

_pdDoc = LoadPDDocument( _doc.FileName)

_avDoc = LoadAVDocument( _doc.FileName)

Finally

If (_pdDoc Is Nothing OrElse _avDoc Is Nothing OrElse _doc
Is Nothing) Then

Dispose(True)

End If

End Try

End Sub

#End Region

#Region "Properties "

Public ReadOnly Property PageCount() As Integer

Get

Return _pdDoc.GetNumPa ges

End Get

End Property

Public Property DeleteOnClose() As Boolean

Get

Return _doc.DeleteOnCl ose

End Get

Set(ByVal Value As Boolean)

_doc.DeleteOnCl ose = Value

End Set

End Property

#End Region

#Region "Methods"

Public Overloads Function PrintSilent() As Boolean

Return PrintSilent(1, PageCount)

End Function

Public Overloads Function PrintSilent( _

ByVal nStartpage As Integer, _

ByVal nEndPage As Integer _

) As Boolean

Dim bRet As Boolean

bRet = CType(_avDoc.Pr intPages(nStart page - 1, _

nEndPage - 1, _

0, _

0, _

0), Boolean)

Return bRet

End Function

Private Function LoadAVDocument( _

ByVal fname As String _

) As Acrobat.CAcroAV Doc

' Create the doc object

Dim avDoc As Acrobat.CAcroAV Doc

avDoc = CType(CreateObj ect(AdobeApplic ation.CLASS_NAM E_AVDOC),
Acrobat.CAcroAV Doc)

If (avDoc Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_AVDOC))

End If

' load the file

Dim bOK As Boolean

Dim strReason As String = ERR_MSG_UNKNOWN

Dim except As Exception

Try

bOK = CType(avDoc.Ope n(fname, fname + "tmp"), Boolean)

Catch ex As Exception

strReason = ex.Message

End Try

If (Not bOK) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_OPE N_FILE, _

fname, _

strReason), _

except)

End If

Return avDoc

End Function

'Create the PDDocument Object and loads the file

Private Function LoadPDDocument( _

ByVal fName As String _

) As Acrobat.CAcroPD Doc

' Create the doc object

Dim pdDoc As Acrobat.CAcroPD Doc

pdDoc = CType(CreateObj ect(AdobeApplic ation.CLASS_NAM E_PDDOC),
Acrobat.CAcroPD Doc)

If (pdDoc Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_PDDOC))

End If

' load the file

Dim bOK As Boolean

Dim strReason As String = ERR_MSG_UNKNOWN

Dim except As Exception

Try

bOK = CType(pdDoc.Ope n(fName), Boolean)

Catch ex As Exception

strReason = ex.Message

End Try

If (Not bOK) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_OPE N_FILE, _

fName, _

strReason), _

except)

End If

Return pdDoc

End Function

Public Function GetPage( _

ByVal nPageNbr As Integer _

) As Acrobat.CAcroPD Page

Dim pdPage As Acrobat.CAcroPD Page

If (Not _pdDoc Is Nothing) Then

pdPage = CType(_pdDoc.Ac quirePage(nPage Nbr),
Acrobat.CAcroPD Page)

If (pdPage Is Nothing) Then

Throw New
Exception(Strin g.Format(ERR_MS G_UNABLE_TO_CRE ATE_PAGE, _

nPageNbr))

End If

End If

Return pdPage

End Function

#End Region

#Region "Attributes "

Private _pdDoc As Acrobat.CAcroPD Doc

Private _avDoc As Acrobat.CAcroAV Doc

Private _doc As TemporaryFile

#End Region

#Region " IDISPOSABLE IMPLEMENTATION "

#Region "Methods"

Public Overloads Sub Dispose() Implements
System.IDisposa ble.Dispose

Dispose(True)

GC.SuppressFina lize(Me)

End Sub

Public Overloads Sub Dispose( _

ByVal bDisposing As Boolean _

)

If (Not _disposed) Then

' need to do this one before the _doc as the _doc will try
to delete the file

' Don't know that we can ever get here with a Nothing value
in _pdDdoc

' but it costs little to check

If (Not _pdDoc Is Nothing) Then

Trace.WriteLine ("Releasing the PD DOC")

_pdDoc.Close()
System.Runtime. InteropServices .Marshal.Releas eComObject(_pdD oc)

_pdDoc = Nothing

End If

If Not _avDoc Is Nothing Then

Trace.WriteLine ("Releasing the AV DOC")

_avDoc.Close(1)
System.Runtime. InteropServices .Marshal.Releas eComObject(_avD oc)

_avDoc = Nothing

End If

If (bDisposing) Then

_doc.Dispose()

End If

End If

_disposed = True

End Sub

Protected Overrides Sub Finalize()

Dispose(False)

End Sub

#End Region

#Region "Attributes "

Private _disposed As Boolean

#End Region

#End Region

End Class

Apr 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1579
by: Andre L via AccessMonster.com | last post by:
We run numerous Access reports which we auto export as .rtfs to a share. We also have numerous Excel sheets. Each month 10 or more of these reports are combined into deprtmental monthly packets. We were given Adobe Acrobat Professional 6 and told it could build the packet for us in an automated fashion....ie it could convert the 10 or so...
6
5257
by: jdph40 | last post by:
We recently had to upgrade the computers in our company. Now our office's website on our company intranet no longer recognizes reports saved in snapshot format. We get an error message that the file we are downloading "cannot be opened by the default program. It is either corrupted or it has an incorrect file type." We had no problem until...
0
1740
by: philipp | last post by:
I have the following problem: My client application (c#, WindowsForms) uses the IE Browser ActiveX Control to display either HTML or PDF files. This is fine so far. If the Acrobat Reader is configuered appropriately, the pdf-Files are displayed right in that Browser Control. Only problem is, when closing the Application there is a memory...
1
3376
by: MuZZy | last post by:
Hi, I just wonder if someone has any idea where i could get description of Adobe SDK functions translated to C#/VB.NET? The problem is this: we have an C#/VB.NET app which uses Acrobat COM classes for deviding/merging some pdf's. It's all working fine with version 5 of Adobe Acrobat installed, but when we switch to version 7 we started...
1
1831
by: Stinky Pete | last post by:
Hi, With thanx to the group and suggestions to review other news sites, I've got some code that allows me to open Adobe from Access. As I am new at this, I still need some help though. The code to get Abobe to open is working really well, however the referenced file I need is not being opened. I've tried the path that I've got in the...
11
2054
by: saintor1 | last post by:
I can't believe how much time I spent on this. I finally found the cause and it was Adobe 7.0 Professional. What happened was that a database could be opened once, but the subsequent users got a message that it was already opened in exclusive mode. First I fighted with all kind of permissions - no result. At the end of my research, I...
7
5190
by: atlbearcat | last post by:
All - I have a form that has an OLE field in it for files (Excel, Word, PDF, etc.). The problem is that when the user opens a PDF file from the form, it opens fine. But, when they close the PDF file, Access generates an error... The operation on the Acrobat Document object failed. The OLE server may not be registered. To register the...
2
8080
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts: http://kbalertz.com/954822/install-configure-Indexing-Service-Windows-Server-computer.aspx http://kbalertz.com/820105/Application-Query-Indexing-Service-Catalog-Using-Visual-Basic.aspx I can search some files...
0
2458
by: kirankumarn | last post by:
I want to open pdf files from Adobe Reader 8.0 default from C# code. but in my system Adobe Acrobat 5.0 installed & Adobe Reader 8.0 installed. So my code opens by default in Adobe Acrobat 5.0 i want to open by default in Adobe Reader directly from code without doing any settings changes. Thanks in advance
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.