Results 1 to 8 of 8

Thread: Create PDF using PDFCreator

  1. #1

    Create PDF using PDFCreator



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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.

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    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 (www.excelguru.ca)
    'Macro Purpose: Print to PDF file using PDFCreator
    '   (Download from http://sourceforge.net/projects/pdfcreator/)
    '   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
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3

    Lightbulb

    Quote Originally Posted by Ken Puls View Post
    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

  4. #4
    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 Creator
        Do
            DoEvents
        Loop Until Dir(sPDFPath & sPDFName) = sPDFName
    
        pdfjob.cClose
        Set pdfjob = Nothing
    End Sub
    Unfortunately this isn't working....

  5. #5
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Sorry, been very busy here.

    Is it giving you any errors? Just running forever, or...?
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  6. #6
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    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!
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  7. #7
    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.

  8. #8
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •