Solved

Appending PDF files together without Adobe tools ?

Posted on 2014-07-31
4
388 Views
Last Modified: 2014-08-03
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
Comment
Question by:bthouin
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40231780
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
 
LVL 84
ID: 40232857
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
 
LVL 1

Author Comment

by:bthouin
ID: 40237596
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
 
LVL 84
ID: 40237709
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now