Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

Appending PDF files together without Adobe tools ?

Hi

I have a problem.

One of the Access (2007) apps I developed at my current clients had to create one single PDF document out of multiple PDF files, which are themselves the results of generating Access reports in PDF format. I did that by looking up examples on the Internet, using the following code, which worked perfectly well:

Public Sub MergePDFFiles(sInputFileNames() As String, sOutputFileName As String, sFilePath As String)
    Dim pdfMainDoc As Object
    Dim pdfAddedDoc As Object
    Dim nMainPages As Long
    Dim nAddedPages As Long
    Dim i As Byte
    Const sTempOutputDoc As String = "sMergedFile.pdf"
    Dim fs As Object

    On Error GoTo EH
    
    i = 1
    Do While sInputFileNames(i + 1) <> ""
        Set pdfMainDoc = CreateObject("AcroExch.PDDoc")
        If i = 1 Then
            pdfMainDoc.Open (sInputFileNames(i))
        Else
            pdfMainDoc.Open (sFilePath & "\" & sTempOutputDoc)
        End If
        nMainPages = pdfMainDoc.getNumPages
        Set pdfAddedDoc = CreateObject("AcroExch.PDDoc")
        pdfAddedDoc.Open (sInputFileNames(i + 1))
        nAddedPages = pdfAddedDoc.getNumPages
        pdfMainDoc.InsertPages nMainPages - 1, pdfAddedDoc, 0, nAddedPages, False
        pdfMainDoc.Save 1, sFilePath & "\" & sTempOutputDoc
        pdfMainDoc.Close
        pdfAddedDoc.Close
        i = i + 1
    Loop
    On Error Resume Next
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.DeleteFile (sOutputFileName)
    On Error GoTo EH
    Name sFilePath & "\" & sTempOutputDoc As sOutputFileName

XH:
    On Error Resume Next
    Set pdfMainDoc = Nothing
    Set pdfAddedDoc = Nothing
    Exit Sub
    
EH:
    MsgBox "Error: " & Err.Description & " in MergePDFFiles", , "Internal error"
    Resume XH
    
End Sub

Open in new window


So essentially, I was using code in the local copy of Adobe Reader to load one document after the other and to append the documents one after the other in the final, single PDF document, with proper pagination and layout. The environment was rather complex, using Citrix,  terminal servers and thin clients MS Office 2007 and Adobe Reader 9.

Now my client is just switching to the newest version of Citrix and Office 2013, but has decided that Adobe Reader is no more going to be available to each of the users (a maximum of 30 of them is using the app). So that code of course doesn't work anymore. I tried using generating the reports in rtf format, but the result is dismal in appearance (more or less text only) although the files can be merged in one single Word document which can be converted to PDF.

Do I have any chance of being able to "piggyback" multiple PDF docs into a single one over Access VBA without the Adobe Reader and without 3rd party tools (which are just not allowed at my client), or is this a brick wall ?

Thanks for your opinions / hints / (solutions?).

Bernard
0
bthouin
Asked:
bthouin
  • 2
1 Solution
 
KimputerCommented:
Combining PDF's is a function the free open source PDFcreator can also do. They even supply a vbs script for you to start with. Changing that to VBA shouldn't be a problem.

edit: Sorry didn't read you couldn't install other software. Since Office 2013 can create PDF's natively (also in VBA code), you should use the VBA to create subreports, and then save this combined report as PDF.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I think you're out of luck if you're stuck with VBA only. The code you show above relies on the Adobe codebase to do the work, and there is no equivalent in VBA. As Kimputer said you may be able to fudge it with subreports (if the PDF files are created from Access reports, of course) - but if you want to work with PDF files in the manner you wish, you'll have to use some form of "3rd party" utility, even if that is the Adobe SDK.
0
 
bthouinAuthor Commented:
Hi Kimputer (and Scott)

Yes, thanks for your answers. Kimputer is right, subreports would be the only solution, although they would be fairly time-consuming to build in my case because of various reasons. However, I've found another solution, which escaped me in the first place. Among all the Access apps I developed for that client, a number of them are kind of "server apps" running scheduled once a day or running the whole day waiting for requests in the central DB to do something specific. They all run on separate server machines, on which... Adbe Reader is installed :-). So here comes soon yet another "server" app which will periodically look up the database for requests of PDF files to be merged, and do it using of course the code I presented above... Problem solved :-)

Thanks for your help anyway. Kimputer gets the points for his early answer.

Bernard
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
But Kimputer didn't "answer" your question. You should instead accept your own comment as the solution, and then also accept Kimputer's comment as an Assisted solution if you like.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now