Solved

Appending PDF files together without Adobe tools ?

Posted on 2014-07-31
4
391 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
PDF files have been in the limelight due to its unmatched features.  Personal documents, emails, business reports and eBooks are all converted into PDF files owing to peerless features provided by it. Adding watermark to a PDF file is a method to se…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

932 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

11 Experts available now in Live!

Get 1:1 Help Now