Change pdf filename programmatically using Adobe Acrobat 6.0 Professional

Hi.  I have been playing with this for a while now.  I am testing this logic from Access 2003 in XP although we really need this to work in another application in XP that is not very well known (Vee 7.5.)

I am printing an Access report directly to a pdf file.  I unchecked the checkbox for "Prompt for Adobe PDF filename" and set the port to save to the folder I want.  That is all working.  However, the pdffile name is being set each time to the Access report caption (Deposition.pdf).  I need to be able to set the filename each time it is printed.

Here's the code I have that works along with the Adobe settings.
stDocName = "rptDeposition"
DoCmd.OpenReport stDocName, acViewPreview, , "SampleID='" & Me.SampleID & "'"
DoCmd.PrintOut

Is there an easy way to tell Adobe what filename I want to use?  I hope that figuring it out in Access will help me figure it out in the other application.  We have Adobe Acrobat 6.0 Professional and Acrobat Distiller 6.0.

Thanks for your help.
Alexis
alexisbrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karl Heinz KremerCommented:
Starting with Acrobat 7, yes there is an easy way to configure the output filename (by setting a registry key), but this was not available in Acrobat 6. Can you upgrade Acrobat?

If not, you have some work to do: You first need to create a PostScript file, then you run Distiller (using the Distiller API that is documented by Adobe) to convert that PostScript file to a PDF file.
0
alexisbrAuthor Commented:
Thanks, khkremer.  I don't know if upgrading is an option.  We may have found a workaround in the meantime.  Let me try this workaround and I will get back to you.
Thanks,
Alexis
0
alexisbrAuthor Commented:
khkremer.
We can upgrade to Acrobat 9 Professional.  If so, how do we change the filename using the registry key?  Also, we will have multiple pages to print to one pdf file before we want to change the name.  Can we set Acrobat to not create a new pdf each time we do a printscreen and have the ability to tell Adobe when we are done printing to that pdf and to start a new one?  I can open a new question for that if you want.

We almost had this process working using pdfFactory but we are running into some inconsistencies and may end up having to use Adobe after all.

Also, I won't be back to this client again until Wed so I can't test anything out until then.
Thanks,
Alexis
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Karl Heinz KremerCommented:
Take a look at the Distiller API Reference (http://www.adobe.com/devnet/acrobat/pdfs/Distiller9APIReference.pdf) - this document shows you how to turn off the prompt for the filename and provide the name via the registry key.

Unfortunately, you can only do this for one job at a time (unless you can send all the pages in the same print operation). So you would need to collect a number of PDF documents, and then when you are done you can use VBA to automate Acrobat to combine all these documents into the one output document.
0
Karl Heinz KremerCommented:
One more thing: The registry key is dependent on the application name, so your program needs to be changed when you move the solution from Access to Vee.
0
alexisbrAuthor Commented:
We are currently testing in Vee only.  I am no longer testing in Access.  We worked around the filename problem by writing a VBScript program to rename the Vee.pdf file created by the process after the process is done.  The Vee application can call a batch file so I created a batch file that calls my VBS program.  That works, however, we ran into some timing issues with the VBS trying to change the name even though the pdf has not finished being written yet.    

We're not sure if we can write VB code from within Vee.  That's why we tried to figure out a solution that would be outside of Vee.  If I can change the registry key and combine multiple PDF documents using VBScript, that should work from Vee.

Thanks,
Alexis
0
Karl Heinz KremerCommented:
Your timing issues would be resolved by setting this registry key. Can you run a batch script before the print operation?
0
alexisbrAuthor Commented:
Yes, we can run a batch script at any point, including before we print.  We are printing using the equivalent of a printscreen and have the pdf driver set as the default printer.  This PC will not be used for anything but our application so this is not a problem.

Thanks,
Alexis
0
Karl Heinz KremerCommented:
OK, in that case it's simple: Just set the registry key in your pre-print batch script (that of course requires that you have access to your desired output name at that time). It does not matter at which time you set the key, as long as it is set when you actually submit the job to the Adobe PDF printer. Distiller will remove the key after it's done, so you have to set it again the next time around (to a different name to avoid overwriting the first one).
0
alexisbrAuthor Commented:
We know the desired filename at the very begining of the process.   I can set the registry key.  However, since we call the print several times before we are done but we want one pdf file, I will have to combine the multiple pdf files.  I will probably have to keep resetting the registry key before each print to filename_1, filename_2, etc. (where filename is our desired filename) so I can combine them at the end.  I will be at the client on Wed and will try to test this out. I have to review the API to figure out the registry key and combine files syntax.

Thanks for your help.  I'll let you know how it goes.
Alexis
0
Karl Heinz KremerCommented:
Your first attempt may not work - because you may not know the correct application name. Do you have access to the application before you visit your client? If so, you should run a few tests to find out what the application uses as it's name when it initiates the print request.

Once way to do that is to check a different registry key. I describe the method in this question:
http://www.experts-exchange.com/Web_Development/Document_Imaging/Adobe_Acrobat/Q_23629368.html

(here is the one comment that you actually need from that discussion:
OK, then you may have the correct program filename. Use your application and print to the Adobe PDF printer, then open regedit and look in the PrinterJobControl key. There should be a new value with a name that starts with "LastPdfPortFolder - ", followed by the application name (unfortunately, it does not list the path). Is that the same application name that you've used?)
0
alexisbrAuthor Commented:
I think I understand what you are saying.  Unfortunately, the applicaiton is an engineering app that I do not have access to unless I am there.  I will do what you said and get the name from regedit.  I know the app outputs all pdf files to the name vee.pdf but that may be different from what I will see in regedit.

Thanks again for all the details.  I've never had to work with pdf file creation before.  The project we are working on is very important to the company and this printing issue is the last hurdle and it is complete.

Regards,
Alexis
0
alexisbrAuthor Commented:
I set the registry key, however, when I tested using Wordpad as you suggested in some other posts, it doesn't work.  The pdf file name is not going to where I wanted and doesn't have the filename I set.  Plus, the registry key is still there after I print so I know something's wrong.

I attached a screenshot of the registry setting I created.  Did I do something wrong?  I installed Adobe Acrobat Professional 9.0 before I did any of this.  Once I get the Wordpad example working, I will try to get it to work with the Vee application.

Thanks,
Alexis
registry.jpg
0
alexisbrAuthor Commented:
I figured out the problem after doing  more testing.  Although my registry setting was correct, I had changed the Adobe Output PDF Folder setting from "prompt" to a physical folder.  I thought maybe that was interfering with the registry.  When I put the setting back to "prompt", and then ran Wordpad, it worked.  Now I will try to write a batch script to change the setting so I can call it from the vee program.  I'll let you know if I have any questions.
Thanks,
Alexis
0
alexisbrAuthor Commented:
Hi khkremer,
I tested manually setting the registry key for the vee application and the pdf file was created correctly.  I reviewed various posts on windows scripting but I can't get a complete file written.  I'd like to do this in VBScript.  For now, I want to get it to work with the Wordpad example.  I wrote a script below based on code I found but I don't know where to tell the script that the application is Wordpad.  The two string values I manually entered in regedit under "HKEY_CURRENT_USER\SOFTWARE\ADOBE\Acrobat Distiller\PrinterJobControl" are "C:\Program Files\Windows NT\Accessories\wordpad.exe" and "C:\Documents and Settings\processtest\My Documents\MyPDFFiles\mypdf.pdf".  How do I get both values in the script?  Am I even close here (see code snippet)?
Thanks,
Alexis



Dim WshShell, bKey
Set WshShell = WScript.CreateObject("WScript.Shell")
myKey = "HKEY_CURRENT_USER\SOFTWARE\ADOBE\Acrobat Distiller\PrinterJobControl\" 
WshShell.RegWrite myKey, "C:\Documents and Settings\processtest\My Documents\MyPDFFiles\mypdf.pdf", "REG_SZ"
set WshShell = Nothing

Open in new window

0
Karl Heinz KremerCommented:
I am not familiar enough with VB to comment on your script - I'll try it anyways :)

If you look at the sample in the Adobe documentation, you'll see that the application name is actually part of the key (this is Adobe's Wordpad example):

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\PrinterJobControl]
"C:\Program Files\Windows NT\Accessories\wordpad.exe" =
"c:\MyPDFoutputFileName.pdf"

The subkey in PrinterJobControl has the value of the PDF output path. As I said, I'm not an expert in VBS, but I searched a bit and found the following:

http://msdn.microsoft.com/en-us/library/aa393600.aspx

And I got the following code to work:

const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Adobe\Acrobat Distiller\PrinterJobControl"
KeyPath = "SOFTWARE\Adobe\Acrobat Distiller\PrinterJobControl"
strValueName = "C:\Program Files\Windows NT\Accessories\wordpad.exe"
strValue = "c:\output.pdf"
 
 
 
    ' write string value to key    
    Return = objReg.SetStringValue( _
        HKEY_CURRENT_USER,strKeyPath,strValueName,strValue)
    If (Return = 0) And (Err.Number = 0) Then 
        Wscript.Echo "Success"
    Else
        Wscript.Echo "SetStringValue failed. Error = " & Err.Number
    End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexisbrAuthor Commented:
Thanks, khkremer.  That worked.  I really appreciate it.  I worked on this quite a bit yesterday afternoon but just couldn't find the proper syntax.

If I have any more questions on getting this to work, I will open a new question.

Thanks again.
Alexis
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Acrobat

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.