• Error Messages: Can't Initialize PDFCreator

    A problem than can occur when working with PDFCreator via code is that sometimes the code releases PDFCreator too early, and it isn't properly closed.

    What is happening?
    At the end of the PDFCreator routines on this site, we release PDFCreator with (a variation of) the following line:
    Code:
    Set pdfjob = Nothing
    As long as the PDFCreator.exe task is (still) running, we'll get the error "Can't initialize PDFCreator." every time we try to run the PDF creation code:
    So if you're seeing the above error, the issue is that a PDFCreator process is running on your system. If you opened PDFCreator manually, you may not have closed it. Or, if you had previously run a PDFCreator routine, then it had not finished doing what it needed to do, so the process that was actually running on the system stayed alive. We can check this by going into the Task Manager, (right click the taskbar and choose Task Manager,) and verifying that a PDFCreator.exe task is running.

    Killing the running process:
    The very first thing that we need to do to enable our code to run again is to close the running instance of PDFCreator. The steps to do this are listed below, but you should take great care to follow them exactly. Killing the wrong process could cause damage to your system, so make sure that you have the correct process selected! (You may want to print this, as the Task Manager will sit on top of all of your open windows.)
    • Right click your taskbar
    • Select Task Manager
    • Click on the Processes tab
    • Click Image Name until your list is sorted in alphabetical order
    • Scroll down the list until you find PDFCreator.exe
    • Right click PDFCreator.exe and choose End Process
    • Once the process disappears, close the Task Manager

    The first thing you should check about your code:
    On March 1st, 2007, I updated all the PDFCreator articles on the site to change the way PDFCreator was released. Check your code to see if you have a loop near the end that looks something like this:

    Code:
    'Wait until the PDFCreator queue is clear
    Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
    Loop
    If you do, try changing it to the following:

    Code:
    'Wait until the PDF file shows up then release the objects
    Do Until Dir(sPDFPath & sPDFName) <> ""
    DoEvents
    Loop
    The reason that this works, is that instead of checking to see when the file shows up in the destination directory, the second variation checks to see when the PDFCreator queue is clear. At that point you can properly release the objects and they will close properly.

    Alternative Solutions:
    This article was originally published with the steps listed below to pause the PDFCreator code as I didn't have a better method at the time. Rather than remove them outright, I decided to leave them as an alternate way to work around the problem of closing PDFCreator. The method that follows is anything but elegant, but it is effective.

    Alternative One - No time to adjust the code:
    If you don't have time sleuth your your code, you could try closing all extra running programs to give your RAM and processor as much resources as possible. Often that is enough to allow a PDFCreator loop to complete.

    The problems with this, obviously, are:
    • We shouldn't need to close down our other applications to do this
    • It won't always work
    • It's not reliable when deploying code to clients. (Their systems will have different resource loads.)

    Alternative Two - Coding a pause:
    We can deal with this issue by intentionally slowing down our code with a pause. Personally, this goes against my grain, and is the reason I kept pursuing a better way. I want my code to complete as fast as possible, but if you don't mind this method, it will work.

    The actual length of the pause that is required will depend on your system, your RAM, your processor, and how many applications you have open when the PDFCreator code is running. It may take some experimentation to get it correct, and you should be warned that it may not work on your client's PC. You may need to increase the pause there to be safe.

    The following line of code just will add a 3 second pause in the routine. To adjust this pause, just increase or decrease the 3 to as much or little as you need.

    Code:
    Application.Wait Now + TimeValue("0:0:3")
    The code above should be inserted just before the PDF job is closed. I.e. In the case of the (pre-updated) Printing Worksheets To A PDF File article, each of the routines would end:

    Code:
    'Wait until the PDF file shows up then release the objects
    Do Until Dir(sPDFPath & sPDFName) <> ""
        DoEvents
    Loop
    'Wait a bit longer for PDF Creator to finish
    Application.Wait Now + TimeValue("0:0:3")
    pdfjob.cClose
    Set pdfjob = Nothing

     

    I'm afraid that you must be logged in to comment or leave a testimonial. I wish it could be otherwise, but I'm trying to keep my site spam free for everyone's benefit. If you don't yet have an account it's completely free to sign up, and a very quick process. Simply click here to Register. Not only can you post a comment here, but it gives you full access to posts questions in our forum as well!

     

    If you already have an account, and just haven't logged in yet, what are you waiting for? Login Now!

  • MVP Logo
  • Recent Forum Posts

    Shoeboxken

    VBA Programming help

    I am sorry if I am making this confusing.

    Original request is to have the highest number taken without reproducing a NAME more than 5 times...

    Shoeboxken Today, 03:32 AM Go to last post
    Kenneth Hobson

    VBA Programming help

    I can only do what you have asked. If you keep changing what you want this can go on forever....

    Kenneth Hobson Today, 03:09 AM Go to last post
    Tucker

    Shared Excel file view

    Someone who has left our organization created an Excel Workbook with multiple catalogues for several degrees we offer. Subsequently, they left and are...

    Tucker Today, 02:41 AM Go to last post
    Shoeboxken

    VBA Programming help

    HI Kenneth,

    I thank you and appreciate the effort in getting this code to work as intended. Its great that only 5 names are being selected
    ...

    Shoeboxken Today, 02:36 AM Go to last post
    Kenneth Hobson

    Userform

    DataFormUserform

    Of course the code goes into ThisWorkbook object.

    Sheet1 is the codename of the sheet which must have data...

    Kenneth Hobson Today, 01:42 AM Go to last post