Merging PDF Files with PDFCreator (1 Viewer)

jco23

Registered User.
Local time
Today, 01:26
Joined
Jun 2, 2015
Messages
48
trying this again folks since my prior thread (XPS merging) got zero responses.

I soon realized that using the VBA code for PDFCreator will merge PDF files, so I can move away from XPS.

My code is almost there. my only roadblock is that once each PDF gets sent to the PDFCreator Print Queue, the macro freezes until I close Adobe Acrobat (using Reader since some of the folks that I support do NOT have Pro).

I'm somewhat able to work around that by launching Adobe first, but then the PDFCreator dialogue box appears with all of the jobs queued up. I tried using a sendkeys command to work through that, but to no avail.

below is my code:

Private Sub MergePDFs_Click()

If FileThere("Acrobat.exe") Then
ShellEx "Acrobat.exe"
Else
ShellEx "AcroRd32.exe"
End If


Dim fn(0 To 20) As String, s As String
Dim p_file_name As String

Dim yearstr As String
Dim YYYYMM As String

YYYYMM = (Year(Now()) * 100) + Month(Now())

If Mid(Me.text1, 4, 2) * 1 > 96 Then
yearstr = "19" & Mid(Me.text1, 4, 2)
Else
yearstr = "20" & Mid(Me.text1, 4, 2)
End If

p_file_name = Left(Me.text1, 3) & "_" & yearstr & Right(Me.text1, 3) & "_p_" & YYYYMM & ".pdf"

fn(0) = "C:\file1.pdf"
fn(1) = "C:\file2.pdf"
fn(2) = "C:\file3.pdf"
fn(3) = "C:\file4.pdf"
fn(4) = "C:\file5.pdf"
fn(5) = "C:\file6.pdf"
fn(6) = "C:\file7.pdf"
fn(7) = "C:\file8.pdf"


s = "C:\merged_PDF_File.pdf"

PDFCreatorCombine fn(), s


If FileThere("C:\merged_PDF_File.pdf") Then
Application.FollowHyperlink "C:\merged_PDF_File.pdf"

End If
End Sub

Sub PDFCreatorCombine(sPDFName() As String, sMergedPDFname As String, Optional tfKillMergedFile As Boolean = True)
Dim oPDF As PDFCreator.PdfCreatorObj, q As PDFCreator.Queue
Dim pj As PrintJob
Dim v As Variant, i As Integer, ii As Integer
Dim fso As Object, tf As Boolean
Dim s() As String
Dim brestart As Boolean
Dim MergedPDF As String
MergedPDF = "C:\merged_PDF_File.pdf"

Set fso = CreateObject("Scripting.FileSystemObject")
If tfKillMergedFile And fso.FileExists(sMergedPDFname) Then Kill sMergedPDFname

Set q = New PDFCreator.Queue

With q

On Error Resume Next
.ReleaseCom
.Initialize

If LBound(sPDFName) = 0 Then
.WaitForJobs UBound(sPDFName) + 1, 1
Else
.WaitForJobs UBound(sPDFName), 1
End If

Set oPDF = New PDFCreator.PdfCreatorObj
tf = .WaitForJobs(ii, 5)

i = 0
For Each v In sPDFName()
If fso.FileExists(v) Then oPDF.PrintFile

i = i + 1

Next v

On Error GoTo endnow
.MergeAllJobs

Set pj = q.NextJob
With pj
.SetProfileByGuid "DefaultGuid"
.SetProfileSetting "Printing.PrinterName", "PDFCreator"
.SetProfileSetting "Printing.SelectPrinter", "SelectedPrinter"
.SetProfileSetting "OpenViewer", "false"
.SetProfileSetting "OpenWithPdfArchitect", "false"
.SetProfileSetting "ShowProgress", "false"
.ConvertTo sMergedPDFname
End With
endnow:
.ReleaseCom
End With
Set pj = Nothing

End Sub

thanks!
 

ByteMyzer

AWF VIP
Local time
Yesterday, 22:26
Joined
May 3, 2004
Messages
1,409
Have you considered Stephen Lebans' ReportToPDF? You can use the MergePDFDocuments function to accomplish the same thing.
 

jco23

Registered User.
Local time
Today, 01:26
Joined
Jun 2, 2015
Messages
48
Have you considered Stephen Lebans' ReportToPDF? You can use the MergePDFDocuments function to accomplish the same thing.

thanks for the reply. I did see that, but my company will not approve downloading and installing library files from unapproved sources. thanks though...
 

HiTechCoach

Well-known member
Local time
Today, 00:26
Joined
Mar 6, 2006
Messages
4,357
jco23,

I have used the Access sample code in ReportToPDF for years to merge PDF files. It uses a DynaPDF v2 (https://www.dynaforms.com/en/home.html) commercial library. Unfortunately it has not been update in many years. I am starting to have issue with it running in Access 2010 and later running on the newer Windows versions.

I was considering purchasing DynoPDF v4 since I know how well it works.

I am curious to see how well PDFCreator works.

Can you share which license you purchased?

I plan to download it this weekend to try it.
 
Last edited:

jco23

Registered User.
Local time
Today, 01:26
Joined
Jun 2, 2015
Messages
48
jco23,

I have used the Access sample code in ReportToPDF for years to merge PDF files. It uses a DynaPDF v2 (https://www.dynaforms.com/en/home.html) commercial library. Unfortunately it has not been update in many years. I am starting to have issue with it running in Access 2010 and later running on the newer Windows versions.

I was considering purchasing DynoPDF v4 since I know how well it works.

I am curious to see how well PDFCreator works.

Can you share which license you purchased?

I plan to download it this weekend to try it.

PDFCreator works fine except for my minor issue. it seems to be a decent alternative to those that do NOT have Adobe Pro.

Essentially, PDFCreator acts as another Printer, so you can print to PDF as well. The merge feature is the one that I am most interested in. It does merge the files, just having some difficulty making it seamless.
 

HiTechCoach

Well-known member
Local time
Today, 00:26
Joined
Mar 6, 2006
Messages
4,357
PDFCreator works fine except for my minor issue. it seems to be a decent alternative to those that do NOT have Adobe Pro.

Essentially, PDFCreator acts as another Printer, so you can print to PDF as well. The merge feature is the one that I am most interested in. It does merge the files, just having some difficulty making it seamless.

Thanks for the info. There are several great free PDF viewers and writers. I prefer a different one.

I am also very interested the the automation and merge abilities of PDFCreater for use in non-open source and/or commercial applications on a terminal server. As far as I can tell does require the purchase of a license.

You forgot to mention:
Which license did you purchase?
 

jco23

Registered User.
Local time
Today, 01:26
Joined
Jun 2, 2015
Messages
48
Thanks for the info. There are several great free PDF viewers and writers. I prefer a different one.

I am also very interested the the automation and merge abilities of PDFCreater for use in non-open source and/or commercial applications on a terminal server. As far as I can tell does require the purchase of a license.

You forgot to mention:
Which license did you purchase?

sorry about that. version 2.2.2

this is what my company has. this appears to be a free version
 

HiTechCoach

Well-known member
Local time
Today, 00:26
Joined
Mar 6, 2006
Messages
4,357
sorry about that. version 2.2.2

this is what my company has. this appears to be a free version

Thanks for the update.

FYI: The current version I downloaded was 2.5.2

I will test your code later today.
 

HiTechCoach

Well-known member
Local time
Today, 00:26
Joined
Mar 6, 2006
Messages
4,357
What I have discovered is PDFCreator is really just a wrapper for Ghostscript.

It merges PDFs by calling the app associated file type and telling the app to print. That is why Acrobat (or whatever viewer you have set as teh default viewer) is starting.

From my research, what you are experiencing is standard behavior with PDFs and PDFCreator.


I am used to software that can work directly with PDF files to merge them.

From reading the documentation what may be possible is:

1) suspend the printer queue for PDFCreator

2) use a PDF viewer that has a command line interface with silent printing mode to print the PDFs to the PDFCreator printer. I would expect this to add them to thw printer job queue.

3) merge the PDFs

4) turn on the printer queue for PDFCreator

The key will be finding a PDF viewer app that supports a command line with silent printing.
 

jco23

Registered User.
Local time
Today, 01:26
Joined
Jun 2, 2015
Messages
48
thanks again for looking deeper into this, much appreciated!

along those lines, I stumbled upon a possible solution. if click on the line that reads ".mergealljobs" creating a stopping point whereby the line turns maroon (not sure what the correct terminology is for that), and then run the macro, the script then goes through and adds the files to the PDFCreator print queue. then, when I resume, it merges them all seamlessly.
to replicate this, I tried inserting a pause command "sleep(2000)" for example to wait 2 seconds (and tried other numbers, but not quite yet there). I'm sure there is a better pause command, just not sure what it is.
for the time being, I inserted a msgbox just above the ".mergealljobs" line reading,

MsgBox "Please press OK after all PDF files are sent to print queue", vbOKOnly, "Pause"

this works perfectly, but the only issue is when the macro is done, the focus is stuck on Adobe Acrobat, and not switched back to Access. But this is the only hangup. So having users simply tab back to Access is much more desirable than having to press merge jobs, continue, enter the correct path, etc.

Also, for some odd reason, after the jobs have been merged, when I try to close the newly opened file, it just hangs. I suppose another work around would be to just open the folder where the file is located rather than opening the file.

hope this helps others....
 
Last edited:

HiTechCoach

Well-known member
Local time
Today, 00:26
Joined
Mar 6, 2006
Messages
4,357
thanks again for looking deeper into this, much appreciated!

along those lines, I stumbled upon a possible solution. if click on the line that reads ".mergealljobs" creating a stopping point whereby the line turns maroon (not sure what the correct terminology is for that), and then run the macro, the script then goes through and adds the files to the PDFCreator print queue. then, when I resume, it merges them all seamlessly.
to replicate this, I tried inserting a pause command "sleep(2000)" for example to wait 2 seconds (and tried other numbers, but not quite yet there). I'm sure there is a better pause command, just not sure what it is.
for the time being, I inserted a msgbox just above the ".mergealljobs" line reading,

MsgBox "Please press OK after all PDF files are sent to print queue", vbOKOnly, "Pause"

this works perfectly, but the only issue is when the macro is done, the focus is stuck on Adobe Acrobat, and not switched back to Access. But this is the only hangup. So having users simply tab back to Access is much more desirable than having to press merge jobs, continue, enter the correct path, etc.

Also, for some odd reason, after the jobs have been merged, when I try to close the newly opened file, it just hangs. I suppose another work around would be to just open the folder where the file is located rather than opening the file.

hope this helps others....


Thanks for the update.

Sounds like you are making progress.

FYI: It is referred to as a Break Point when you set a "marker" in your code to get it to stop execution.


Sounds like a timing issue.

You need your code to wait for the print process of the PDF before continuing. This is best handled by monitoring the process.

I have some ideas to try. Is it possible for you to post your updated code for me to test?
 

jco23

Registered User.
Local time
Today, 01:26
Joined
Jun 2, 2015
Messages
48
Thanks for the update.

Sounds like you are making progress.

FYI: It is referred to as a Break Point when you set a "marker" in your code to get it to stop execution.


Sounds like a timing issue.

You need your code to wait for the print process of the PDF before continuing. This is best handled by monitoring the process.

I have some ideas to try. Is it possible for you to post your updated code for me to test?

the code is the same as in the original post except for the addition of the msgbox line directly above the .mergealljobs command.

one other key point (as noted in my code, but may not work for others), is that I make sure to launch Adobe Acrobat first.
 

Users who are viewing this thread

Top Bottom