Programatically disable 'View Adobe PDF Results'

J

Jeff

Hello,

When writing Access VBA code to print a report to PDF, the code I found
gives ways to suppress some settings via changing the registry.

For example:
If you dont want to View the PDF after it is printed in Acrobat 5.0 it was
possible by setting the bExecViewer = 0 in the registry.

This no longer works in later versions of Adobe.

Any idea how to achieve this in Acrobat 7.0?

Thank you,
Jeff
 
J

Jeff

Thank u but I know about this already, I would like to know how to do it the
above way. I am not allowed to installed additonal Dlls where the Lebans
method requires u to do so.

Does anyone know ?

Thank you,
Jeff
 
D

DAVID

Sorry, suggest you repost, cause I don't have an answer.
Actually, suggest you repost in Adobe newsgroup, rather
than Access, but you're welcome to try again.

Lebans code does not have to be called .dll if that
is a problem. Just rename the file .mdb and make
slight changes to the calling code to load the
".mdb" file instead of the ".dll" file.

Also, Snapshot or MS Document Image Writer are
good formats to replace PDF.

(david)
 
R

Robert Robinson

This works with Adobe Acrobat 8/9/X.

Adobe PDF Converter is used to convert documents to PDF format under programmatic control in which the locations of the incoming and outgoing document files and the PDF options are program defined.
No user interaction is required except for initiating the process.

It is important that the Adobe PDF Printing Preferences be setup properly including turning off ?View Adobe PDF Results.?
If this option is on, a document is displayed after each conversion and operator intervention is required to close each display window.

The procedures for programmatically controlling the ?View Adobe PDF Results? and a number of other Printing Preferences are, unfortunately, not publicly available. RegShot, or a similar program, can be used to obtain before and after dumps of the entire registry to identify all fields that have changed after some operation; for example, turning the View Adobe PDF
Results on and off. A partial of a RegShot dump/compare is as follows:

REGISTRY COMPARE FOLLOWS:



HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Adobe PDF\ChangeID: 0x3E0E1837
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Adobe PDF\ChangeID: 0x43FB0A22
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Adobe PDF\PrinterDriverData\ViewPrintOutput: 0x00000000
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Adobe PDF\PrinterDriverData\ViewPrintOutput: 0x00000001
HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Adobe PDF\ChangeID: 0x3E0E1837
HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Adobe PDF\ChangeID: 0x43FB0A22
HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Adobe PDF\PrinterDriverData\ViewPrintOutput: 0x00000000
HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Adobe PDF\PrinterDriverData\ViewPrintOutput: 0x00000001
HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Adobe PDF\ChangeID: 0x3E0E1837
HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Adobe PDF\ChangeID: 0x43FB0A22
HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Adobe PDF\PrinterDriverData\ViewPrintOutput: 0x00000000
HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Adobe PDF\PrinterDriverData\ViewPrintOutput: 0x00000001
HKU\S-1-5-21-1893839149-681825858-379077944-1001\Printers\DevModePerUs er\Adobe PDF: (long binary data follow)

The ViewPrintOutput registry entries shown above do not, unfortunately, control the Adobe Printing Preferences.

The HKEY_USERS entry does control the Preferences. The contents of DevModePerUser is a lengthy binary file that contains a combination of field names and field data. A definition of the structure of the fields is apparently not publically available. Some of the definitions are obvious from decoding the hexadecimal data. We did not, however, try to define the structure because of the difficulty of doing this and the uncertainty about creating errors.

An alternative is to use the Adobe PDF Converter Printing Preferences Window to display and set the options. The resultant DevMode file is stored and is then written to the DevModePerUser field when the options are to be programmatically selected.
This approach has worked without problems.

The necessary steps are outlined as follows:

Obtain the login name of the current user. You can use ?my.user.name? or ClientInfo.WTSUserName

Search HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ProfileImagePath for this name.
When found, save the corresponding address that is located in the ProfileList.

Find this address in HKEY_USERS. It will look something like "HKEY_USERS\S-1-5-21-1893839149-681825858-379077944-1001
\Printers\DevModePerUser"

The alphanumeric data starting with S is an unique code for the current user

The field of interest is DevModeData. Save its contents and then replace the data with The custom version of DevModeData.
The original contents of DevModeData are restored on exit from the application program.

The following is a Visual Basic NET program fragment that was compiled with Visual Studio 2010. This code is abstracted from a larger program and handles only the steps that are described above.

'The following code sets the current user DevCode data so that the View Adobe Printing Results is unchecked
'Setup the byte array for DevCode
Dim byteArray() As Byte = New Byte() {}
Dim saveByteArray() As Byte = New Byte() {}
Dim regVersion As RegistryKey
Dim keyValue As String
'Dim str As String
Dim userDirectoryPath As String = ""


Dim Key As RegistryKey = Registry.LocalMachine.OpenSubKey _
("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", False)
Dim SubKeyNames() As String
SubKeyNames = Key.GetSubKeyNames()
Dim Index As Integer
Dim SubKey As RegistryKey
keyValue = ""
For Index = 0 To Key.SubKeyCount - 1
SubKey = Registry.LocalMachine.OpenSubKey _
("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + "\" _
+ SubKeyNames(Index), False)
Dim ret As Integer
regVersion = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" & "\" & SubKeyNames(Index), True)
userDirectoryPath = regVersion.GetValue("ProfileImagePath", "Default Value")
'Skip the bacup file
ret = InStr(SubKeyNames(Index), ".bak")
If ret = 0 Then
ret = InStr(userDirectoryPath, MainForm.logonName)
If ret > 0 Then
keyValue = SubKeyNames(Index) & "\Printers\DevModePerUser"
Exit For
End If
'MessageBox.Show(SubKeyNames(Index))
End If
Next

saveByteArray = Nothing
'Open the DevModePerUser key for the current user
Try
regVersion = Registry.Users.OpenSubKey(keyValue, True)
Catch err As Exception
MessageBox.Show("Open SubKey " & err.Message)
Exit Sub
End Try

'Check for presence of the DevModeData File
Try
If Directory.Exists(userDirectoryPath) = False Then
Directory.CreateDirectory(userDirectoryPath)
End If
Catch err As Exception
MessageBox.Show("Exists userDirectoryPath " & err.Message)
Exit Sub
End Try
If Not File.Exists(userDirectoryPath & "\DevModeData") Then
If MessageBox.Show("Open Adobe PDF Printing Preferences and uncheck View Adobe Printing Results." & vbCrLf & "Then press OK.", "Setup Default Adobe Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) = MsgBoxResult.Cancel Then
Exit Sub
End If
'Read DevData from the HKEY_USERS hive
Try
byteArray = regVersion.GetValue("Adobe PDF", "Default Value")
Catch err As Exception
MessageBox.Show("Read Adobe PDF DevData " & err.Message)
Exit Sub
End Try
saveByteArray = byteArray
'This is a trace to display DevData in hexadecimal format
'Dim strings As String() = Array.ConvertAll(byteArray, Function(b) b.ToString("X2"))
'Dim str As String = String.Join(" ", strings)
'MessageBox.Show(str)
'Save the existing DevData in current user directory
Try
File.WriteAllBytes(userDirectoryPath & "\DevModeData", byteArray)
Catch err As Exception
MessageBox.Show("WriteAllBytes " & err.Message)
Exit Sub
End Try
Else
'DevData file is present in current user directory
'We will first save the current registry copy of DevData
Try
byteArray = regVersion.GetValue("Adobe PDF", "Default Value")
Catch err As Exception
MessageBox.Show("GetValue Adobe PDF " & err.Message)
Exit Sub
End Try
'Save the current DevData
saveByteArray = byteArray
'Read the default DevData from drive C
Try
Dim fs As System.IO.FileStream = System.IO.File.Open(userDirectoryPath & "\DevModeData", IO.FileMode.Open, IO.FileAccess.Read)
Dim buff(fs.Length) As Byte
If fs.Length > 0 Then
fs.Read(buff, 0, fs.Length - 1)
'This creates a hexadecimal trace
'Dim strings As String() = Array.ConvertAll(buff, Function(b) b.ToString("X2"))
'Dim str As String = String.Join(" ", strings)
'MessageBox.Show(str)
'Replace the existing registry DevData with the defalut DevData
regVersion.SetValue("Adobe PDF", buff)
fs.Close()
buff = Nothing
fs = Nothing
Else
'Empty File
End If
Catch err As Exception
MessageBox.Show(err.Message)
Exit Sub
End Try
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top