Create PDF using PDFCreator

edwardjzimmer

New member
Joined
Dec 9, 2012
Messages
5
Reaction score
0
Points
0
Hello, I have a similar situation I need help with. I need to combine all the jobs in the PDF Creator and save them as one PDF file (the worksheet's active cell.) The only difference is that the PDF Creator program will already be open and visible on the desktop. I just need a macro that combines and saves. Of all the code out there, I can't believe I'm unable to find this somewhere, but it seems like all the code is written to control PDF Creator while it is closed.
 

Ken Puls

Administrator
Staff member
Joined
Mar 13, 2011
Messages
2,519
Reaction score
4
Points
38
Location
Nanaimo, BC, Canada
Website
www.excelguru.ca
Excel Version(s)
Excel Office 365 Insider
Hi Edward,

I've split your post to a new thread, as the one you posted on was fairly old.

So you're looking to create a PDF based on the name in a single cell. With regards to the rest of the question, can I ask why PDFCreator will be open on the desktop? Typically, I kill any instance of PDFCreator that is running before I try to start working with it so that I know exactly what I have.

We could certainly try to bind to an open version... something maybe like the following:

Code:
Option Explicit
Sub PrintToPDF_Late()
'Author       : Ken Puls ([URL="http://www.excelguru.ca/"][COLOR=#417394]www.excelguru.ca[/COLOR][/URL])
'Macro Purpose: Print to PDF file using PDFCreator
'   (Download from [URL="http://sourceforge.net/projects/pdfcreator/"][COLOR=#417394]http://sourceforge.net/projects/pdfcreator/[/COLOR][/URL])
'   Designed for late bind, no references req'd
    Dim pdfjob As Object
    Dim sPDFName As String
    Dim sPDFPath As String

    '/// Change the output file name here! ///
    sPDFName = "testPDF.pdf"
    sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

    'Check if worksheet is empty and exit if so
    If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
    Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
    With pdfjob
        If .cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't initialize PDFCreator.", vbCritical + _
                vbOKOnly, "PrtPDFCreator"
            Exit Sub
        End If
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = sPDFPath
        .cOption("AutosaveFilename") = sPDFName
        .cOption("AutosaveFormat") = 0    ' 0 = PDF
        .cClearCache
    End With

    'Combine all jobs already in the PDFCreator queue
    pdfjob.cCombineAll = False
    pdfjob.cPrinterStop = False

    'Wait until the file shows up before closing PDF Creator
    Do
        DoEvents
    Loop Until Dir(sPDFPath & sPDFName) = sPDFName

    pdfjob.cClose
    Set pdfjob = Nothing
End Sub
 

edwardjzimmer

New member
Joined
Dec 9, 2012
Messages
5
Reaction score
0
Points
0
Hi Edward,

I've split your post to a new thread, as the one you posted on was fairly old.

So you're looking to create a PDF based on the name in a single cell. With regards to the rest of the question, can I ask why PDFCreator will be open on the desktop? Typically, I kill any instance of PDFCreator that is running before I try to start working with it so that I know exactly what I have.

We could certainly try to bind to an open version... something maybe like the following:

Thank you for your quick response! I do print to file for the billing department of a medical center and I have to pull in various reports from different locations by printing them (with PDFCreator) and then combining them into one file to be sent to the next department. Having a macro to combine and save the file doesn't save much time, but since I do hundreds a day, every second counts. So I don't need to save worksheets, and I need the PDFCreator to already be open since I am putting different pages into it. So if I can push a button and it will combine what I have already loaded in there, and then save it as the active cell (which is the account number that I use in the other programs to access the pages I'm printing) it would save me about an hour each day.

Thanks!

Edward
 

edwardjzimmer

New member
Joined
Dec 9, 2012
Messages
5
Reaction score
0
Points
0
So....does anyone know how to do this? It really seems like it should be easy enough. Maybe something like:
Code:
Option Explicit
Sub PrintToPDF_Late()
'Author       : Ken Puls
'Macro Purpose: Print to PDF file using PDFCreator

    Dim pdfjob As Object
    Dim sPDFName As String
    Dim sPDFPath As String

    '/// Change the output file name here! ///
    sPDFName = activecell.value
    sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
    Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
    With pdfjob
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = sPDFPath
        .cOption("AutosaveFilename") = sPDFName
        .cOption("AutosaveFormat") = 0    ' 0 = PDF
        
    End With

    'Combine all jobs already in the PDFCreator queue
    pdfjob.cCombineAll = False
    pdfjob.cPrinterStop = False

    'Wait until the file shows up before closing PDF [COLOR=#417394]Creator[/COLOR]
    Do
        DoEvents
    Loop Until Dir(sPDFPath & sPDFName) = sPDFName

    pdfjob.cClose
    Set pdfjob = Nothing
End Sub

Unfortunately this isn't working....
 

Ken Puls

Administrator
Staff member
Joined
Mar 13, 2011
Messages
2,519
Reaction score
4
Points
38
Location
Nanaimo, BC, Canada
Website
www.excelguru.ca
Excel Version(s)
Excel Office 365 Insider
Hmm... I see...

So the issue is that the code I gave you tries to create a new instance of PDFCreator, instead of binding to an existing instance which is where your files are.

All things being equal, this SHOULD work:

Code:
Sub CombinePDFs()
'Author       : Ken Puls
'Macro Purpose: Print to PDF file using PDFCreator
    Dim pdfjob As Object
    Dim sPDFName As String
    Dim sPDFPath As String
    '/// Change the output file name here! ///
    sPDFName = "Test.pdf"
    sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
    Set pdfjob = GetObject(, "PDFCreator.clsPDFCreator")
    With pdfjob
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = sPDFPath
        .cOption("AutosaveFilename") = sPDFName
        .cOption("AutosaveFormat") = 0    ' 0 = PDF
        
    End With
    'Combine all jobs already in the PDFCreator queue
    pdfjob.cCombineAll = True
    pdfjob.cPrinterStop = False
    'Wait until the file shows up before closing PDF Creator
    Do
        DoEvents
    Loop Until Dir(sPDFPath & sPDFName) = sPDFName
    pdfjob.cClose
    Set pdfjob = Nothing
End Sub

But it won't. It's gagging on the line to connect to the PDF Creator class. And I'm not sure why.

The irony here is that, if you gave me a list of the files (with paths) that you want to merge into one PDF in a column, I could make that happen quite easily. But trying to attach to where you've already got the files printed is a bit of a monster. In fact, I could even build a "picker" to allow you to collect the file paths of all files you'd want to collect, then print them, so long as they were MS Office documents.

Frustrating!
 

edwardjzimmer

New member
Joined
Dec 9, 2012
Messages
5
Reaction score
0
Points
0
Yes! VERY frustrating. As soon as the owner of the program writes the code, my current project will become obselete. But the program is old (Not MS) and I don't have access to the code that runs it to pull from so for now the only automation that can be done is to combine and save. Well, at least now I know why 15-20 hours wasen't enough time to figure it out! Since it doesn't seem to be possible.... Thanks for looking at it.
 

edwardjzimmer

New member
Joined
Dec 9, 2012
Messages
5
Reaction score
0
Points
0
Well, I've been holding my breathe hoping someone would come up with an answer to this simple problem, but I guess there really is no solution. Does anyone know of another program this would be possible with in place of PDFCreator?
 
Top