I have an access database, and have it setup to automate the printing of a few reports for storage in a PDFs.
It prints 2 reports to a temp directory.
Merges them into a final PDF.
Then opens it for the user to scan in extra files (usually drawings marked up with inspection problems).
He alsways sets the pages in the exact order (Access Report 1(1-2 pages long), Access Report 2(always 1 page), scans)
We wanted to make it so he could replace the pages printed from the Access reports.
Since there is scanned items in these PDFs i cant just reprint it or he will loose the scanned pages.
So i am going to just print the new pdf page to a temp file and do a page replacement, then delete the temp PDF (which i have working code for).
Each of the pages from the Access reports contains hidden text, so i can just search for it within a PDF, get that pages number and then use it to replace the pages.
The problem i have is the code im using to search the PDF doesnt always work. Sometimes it works great and i get my page value(s), but sometimes it just locks up, and i have to go to the Task Manager and kill Acrobat.exe. Then it will unfreeze Access and give me an error.
It seems to work more often if i only run it once, but i need to run it twice though. Once to find the last report page in the original PDF and then again to find the last page(in case the report prints 2 pages) in the replacement PDF. Then after this im going to compare them to determine the appropriate way to replace the page(s)
these are what the variables are for
strDir = directory PDF to search is in. (ex. c:\temp\)
strFileName = filename (ex. 1055.pdf)
strSearch = (ex. xxxyyyzzz)
Public Function SearchPDF(strDir As String, strFileName As String, strSearch As String) As Long
Dim AcroApp As Object
Dim AcroAvDoc As Object
Dim AVPage As CAcroAVPageView
Dim bFound As Boolean
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAvDoc = CreateObject("AcroExch.AVDoc")
Call AcroAvDoc.Open(strDir & strFileName, "")
Set AcroAvDoc = AcroApp.GetActiveDoc
If AcroAvDoc.IsValid Then
bFound = AcroAvDoc.FindText(strSearch, 0, 0, 1) '<----this is the line it highlights after i kill acrobat.exe
If bFound = True Then
Set AVPage = AcroAvDoc.GetAVPageView
SearchPDF = AVPage.GetPageNum
Set AVPage = Nothing
End If
End If
AcroAvDoc.Close True
AcroApp.Exit
End Function
It prints 2 reports to a temp directory.
Merges them into a final PDF.
Then opens it for the user to scan in extra files (usually drawings marked up with inspection problems).
He alsways sets the pages in the exact order (Access Report 1(1-2 pages long), Access Report 2(always 1 page), scans)
We wanted to make it so he could replace the pages printed from the Access reports.
Since there is scanned items in these PDFs i cant just reprint it or he will loose the scanned pages.
So i am going to just print the new pdf page to a temp file and do a page replacement, then delete the temp PDF (which i have working code for).
Each of the pages from the Access reports contains hidden text, so i can just search for it within a PDF, get that pages number and then use it to replace the pages.
The problem i have is the code im using to search the PDF doesnt always work. Sometimes it works great and i get my page value(s), but sometimes it just locks up, and i have to go to the Task Manager and kill Acrobat.exe. Then it will unfreeze Access and give me an error.
It seems to work more often if i only run it once, but i need to run it twice though. Once to find the last report page in the original PDF and then again to find the last page(in case the report prints 2 pages) in the replacement PDF. Then after this im going to compare them to determine the appropriate way to replace the page(s)
these are what the variables are for
strDir = directory PDF to search is in. (ex. c:\temp\)
strFileName = filename (ex. 1055.pdf)
strSearch = (ex. xxxyyyzzz)
Public Function SearchPDF(strDir As String, strFileName As String, strSearch As String) As Long
Dim AcroApp As Object
Dim AcroAvDoc As Object
Dim AVPage As CAcroAVPageView
Dim bFound As Boolean
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAvDoc = CreateObject("AcroExch.AVDoc")
Call AcroAvDoc.Open(strDir & strFileName, "")
Set AcroAvDoc = AcroApp.GetActiveDoc
If AcroAvDoc.IsValid Then
bFound = AcroAvDoc.FindText(strSearch, 0, 0, 1) '<----this is the line it highlights after i kill acrobat.exe
If bFound = True Then
Set AVPage = AcroAvDoc.GetAVPageView
SearchPDF = AVPage.GetPageNum
Set AVPage = Nothing
End If
End If
AcroAvDoc.Close True
AcroApp.Exit
End Function