Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Appending PDF files together without Adobe tools ?

Posted on 2014-07-31
4
Medium Priority
?
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 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 85
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 85
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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