Frequently Asked Question:
Error Message: There was an error opening this document. This file is already open or in use by another application
I've created a thumbnail in VB.NET/VS2008/.NET2.0 using Quick PDF Library using the code below but when the thumbnail is clicked, I always see this error message:
"There was an error opening this document. This file is already open or in use by another application."
This is the code that I'm using:
Dim QP As QuickPDFAX0718.PDFLibrary
Dim Result As Integer
Dim lngFileHandle As Long
Dim pageRef As Long
Dim imageConversionResult As Integer
QP = New QuickPDFAX0718.PDFLibrary
Result = QP.UnlockKey("license-key")
lngFileHandle = QP.DAOpenFile("C:\my.pdf", "")
pageRef = QP.DAFindPage(lngFileHandle, 1)
imageConversionResult = QP.DARenderPageToFile(lngFileHandle, pageRef, 5, 75, "C:\my.png")
QP = Nothing
The error message is caused by the fact that the file you're trying to open manually is already open by way of the DAOpenFile function. Files opened with DAOpenFile may not be accessed by other processes until the file has been closed by one of the following functions:
So to resolve the problem you're experiencing, you simply need to call the DACloseFile function after you've finished rendering the page. Like this:
Dim QP As QuickPDFAX0718.PDFLibrary
Dim Result As Integer
Dim lngFileHandle As Long
Dim pageRef As Long
Dim imageConversionResult As Integer
QP = New QuickPDFAX0718.PDFLibrary
Result = QP.UnlockKey("license-key")
lngFileHandle = QP.DAOpenFile("C:\my.pdf", "")
pageRef = QP.DAFindPage(lngFileHandle, 1)
imageConversionResult = QP.DARenderPageToFile(lngFileHandle, pageRef, 5, 75, "C:\my.png")
QP.DACloseFile(lngFileHandle)
QP = Nothing