AlexTeslin
May 21 2012, 11:30 AM
Hi,
Currently we use Access 2003 in our office where I use Leban's code and approach to convert and merge reports to pdf formats. I heared (not tried myself yet) that Office 2007 onwards it possible to convert files to pdf. I've read that Excel files can be converted to pdf without using any Adobe UIs. I have the 2 following questions that I coudn't answer:
Can I convert reports to pdf without using Leban's code ?
Can I merge 2 pdfs together (as Leban's code allows) ?
Merging is an important part of running pdf functionalities here, so I thought if this can be replaced in Office 2007 or 2010 then I can parsuade my managers to upgrade the whole Office suite.
Thanks in advance
theDBguy
May 21 2012, 11:44 AM
Hi,
You are correct that reports can be converted to PDFs in Office 2007 and 2010, but you still can't merge two separate PDF files without using other methods, such as Lebans' DLL.
Just my 2 cents...
jleach
May 21 2012, 11:45 AM
Hi,
You can indeed output reports to PDF in 2007 and foward.
I'm not sure about merging... I don't think this would be built in, it's more of an adobe function and if I recall correctly, the PDF Output doesn't allow merging directly. So, not that I'm aware, but I could be wrong. Worst case, you can continue to keep the two dlls in your app folder and use the MergePDF function.
hth
fkegley
May 21 2012, 12:55 PM
I have successfully merged two pdf files using code by manipulating the Adobe Acrobat program through VBA.
AvgJoe
May 21 2012, 02:12 PM
Frank,
Would your code happen to be available in the Code Archives?
AvgJoe
fkegley
May 21 2012, 02:30 PM
No it isn't. I can post it, though. I found it on the Web and since it didn't quite do what I needed I modified it a bit to take care of my needs. You will need to adapt it to fit what you need.
I am storing the paths to the separate documents in a table, then opening the table into a recordset and opening them in a specified order, which is also in the recordset. You may or may not need to do that.
Here it is:
Private Sub cmdPrepareIPCPReport_Click()
Dim AcroApp As Acrobat.CAcroApp
Dim db As DAO.Database
Dim rsIPCPReports As DAO.Recordset
Dim rsClientIPCPReports As DAO.Recordset
Dim Part1Document As Acrobat.CAcroPDDoc
Dim Part2Document As Acrobat.CAcroPDDoc
Dim Part1DocumentName As String
Dim numPages As Integer
Dim DocumentID As Integer
Dim SeriesNumber As Integer
Set db = CurrentDb()
SeriesNumber = 1
' Set rsIPCPReports = db.OpenRecordset("IPCPReports")
' Set rsClientIPCPReports = db.OpenRecordset("ClientIPCPReports")
Set AcroApp = CreateObject("AcroExch.App")
Set Part1Document = CreateObject("AcroExch.PDDoc")
DocumentID = DLookup("[ReportID]", "[IPCPReports]", "[IPCPOrder] = " & SeriesNumber)
Part1Document.Open (DLookup("[ReportFileName]", "[ClientIPCPReports]", "[ReportID] = " & DocumentID & " And [CaseNumber] = '" & Me.txtClientNumber & "'"))
SeriesNumber = SeriesNumber + 1
Do Until SeriesNumber > 2
' Part1Document.Open ("C:\temp\TheProtocolsOfZion.pdf")
DocumentID = DLookup("[ReportID]", "[IPCPReports]", "[IPCPOrder] = " & SeriesNumber)
Set Part2Document = CreateObject("AcroExch.PDDoc")
Part2Document.Open (DLookup("[ReportFileName]", "[ClientIPCPReports]", "[ReportID] = " & DocumentID & " And [CaseNumber] = '" & Me.txtClientNumber & "'"))
' Insert the pages of Part2 after the end of Part1
numPages = Part1Document.GetNumPages()
Debug.Print "Number of pages Before = " & numPages
If Part1Document.InsertPages(numPages - 1, Part2Document, 0, Part2Document.GetNumPages(), True) = False Then
MsgBox "Cannot insert pages"
End If
Debug.Print "Number of pages After = " & Part1Document.GetNumPages()
If Part1Document.Save(PDSaveFull, DocumentPath & Me.txtClientName & "-" & Me.txtClientNumber & "-Testing\IPCP.pdf") = False Then
MsgBox "Cannot save the modified document"
End If
SeriesNumber = SeriesNumber + 1
Loop
'
Part1Document.Close
Part2Document.Close
AcroApp.Exit
Set AcroApp = Nothing
Set Part1Document = Nothing
Set Part2Document = Nothing
MsgBox "Done"
End Sub
fkegley
May 21 2012, 02:33 PM
I found the code I modified at this link:
Programming Adobe Acrobat VBA
AvgJoe
May 21 2012, 09:06 PM
AlexTeslin
May 22 2012, 04:32 AM
Thank you all guys for your replies. I will try Frank's code for merging and if it does what is required then I can persuade my manager to upgrade.
Frank, thanks for posting your code. As I've mentioned on my original post I am using Leban's method to convert and merge. The only downside with Leban's code is that if you convert and merge a large number of pdf files, after say 100's item it considerably slows down. I am wondering if you have used Leban's code before to compare with your existing method, or indeed have a large number of iterations in the loop to convert and merge, and if you have, did you notice any performance issues with this new method ?
Thanks
fkegley
May 22 2012, 08:34 AM
I have never used Leban's code to merge PDF files, so can't compare to what I used. And BTW, you should know that the code I posted hasn't been tested by me with a large number of files, it may have the same problem as Leban's code does.
I just tell the users that's the best I could do and they will just have to live with it. Not everything can happen yesterday like it does on TV.
AlexTeslin
May 22 2012, 11:06 AM

Thank you Frank
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.