Solved

Change pdf filename programmatically using Adobe Acrobat 6.0 Professional

Posted on 2008-10-29
17
2,886 Views
Last Modified: 2011-10-19
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
0
Comment
Question by:alexisbr
  • 10
  • 7
17 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22834226
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
 

Author Comment

by:alexisbr
ID: 22836075
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
 

Author Comment

by:alexisbr
ID: 22852265
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22852333
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22852345
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
 

Author Comment

by:alexisbr
ID: 22853049
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22866471
Your timing issues would be resolved by setting this registry key. Can you run a batch script before the print operation?
0
 

Author Comment

by:alexisbr
ID: 22866502
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22866533
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
 

Author Comment

by:alexisbr
ID: 22866587
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22866719
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
 

Author Comment

by:alexisbr
ID: 22866767
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
 

Author Comment

by:alexisbr
ID: 22890452
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
 

Author Comment

by:alexisbr
ID: 22890602
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
 

Author Comment

by:alexisbr
ID: 22891425
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
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 22894509
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
 

Author Comment

by:alexisbr
ID: 22896865
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now