• 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

    Logit

    unduplicated list

    If you also include the "Check Run Date" column in the table as well, that will provide a means of selecting which month.

    Code:
    
    
    ...

    Logit Today, 04:35 PM Go to last post
    BuddyGSD

    unduplicated list

    Is there a way for excel to gather the names of the families from the month of April and May to appear on the Undup Clients tab then?...

    BuddyGSD Today, 04:08 PM Go to last post
    NoS

    Sum cells in each generated row

    Along with writing the form data to the sheet you could write a formula into the O column

    Code:
    Cells(whateverrow, 15).FormulaR1C1="=SUM(RC[-9]:RC[-1])"
    ...

    NoS Today, 02:27 PM Go to last post
    p45cal

    If overide formulae

    Array-enter (Ctrl+Shift+Enter, not just Enter) and copy down:
    =INDEX({"Fail";"Risk";"Pass"},MIN(MATCH(T2:U2,{"Fail","Risk","Pass"},0)))...

    p45cal Today, 12:14 PM Go to last post
    jonespandrew

    If overide formulae

    Sorry I have read you last response wrong Write

    Fail Risk would be a fail
    Risk pass would be a Risk
    Risk Fail would be a fail...

    jonespandrew Today, 11:14 AM Go to last post