Mike Broderick
asked on
How to control the Save PDF File As dialog in Visual Basic
How do I control if the Adobe "Save PDF File As" dialog shows, and the file name to save as. I am using Acrobat 8 and VB in visual studio 2008. I have found that if you set the printdocument's default page settings, the dialog box is skipped:
Public PgSets As New PageSettings
Private Sub Form2_Load... Handles MyBase.Load
pdlg1.Document = pdoc1
pdoc1.DefaultPageSettings = PgSets
pdoc1.PrinterSettings.Prin terName = "Adobe PDF"
pdlg1.PrinterSettings.Prin terName = "Adobe PDF"
End Sub
Private Sub btnGo_Click... Handles btnGo.Click
pdoc1.Print()
End Sub
The statement that sets the DefaultPageSettings is the key. If I comment that statement out, I see the "Save PDF File As" dialog dialog, if I leave it in I dont see the dialog. Is this a quirk (bug) or a supported feature? If it is a quirk I dont want to use it because when they fix it my code will stop working.
Also, how do I control the file name? The file I get is "document.pdf" on the user's desktop.
Thanks.
Public PgSets As New PageSettings
Private Sub Form2_Load... Handles MyBase.Load
pdlg1.Document = pdoc1
pdoc1.DefaultPageSettings = PgSets
pdoc1.PrinterSettings.Prin
pdlg1.PrinterSettings.Prin
End Sub
Private Sub btnGo_Click... Handles btnGo.Click
pdoc1.Print()
End Sub
The statement that sets the DefaultPageSettings is the key. If I comment that statement out, I see the "Save PDF File As" dialog dialog, if I leave it in I dont see the dialog. Is this a quirk (bug) or a supported feature? If it is a quirk I dont want to use it because when they fix it my code will stop working.
Also, how do I control the file name? The file I get is "document.pdf" on the user's desktop.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you set the registry key correctly to your program's path?
ASKER
Under the key PrinterJobControl, I didnt add a key (you cant put back slashes in the key name). I added a string value. The name of the string value is my program name:
C:\Mike\PGMS\Test\AdobePro blem\bin\D ebug\Adobe Problem.ex e
The value of the string value is the spot on disk that I want the output to go:
C:\td\zzz.pdf
I have checked the spelling closely.
C:\Mike\PGMS\Test\AdobePro
The value of the string value is the spot on disk that I want the output to go:
C:\td\zzz.pdf
I have checked the spelling closely.
Try it with WordPad - I know that that application works. This will verify that the mechanism works, then we can work out the kinks. Which version of Acrobat are you using?
ASKER
Wordpad worked correctly.
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?
ASKER
That explained it. Visual Studio creates another program, xxxxx.vshost.exe, and executes it. I corrected the setting or executed the program directly and can control the name of the output file.
My original problem is still unanswered (why changing the DefaultPageSettings causes the save dialog to be skipped), but I will assume that VB has a bug and hope MS or Adobe fixes it some day. This does what I want. I went through my print programs and removed the problem statement, and I am set. Thank you.
My original problem is still unanswered (why changing the DefaultPageSettings causes the save dialog to be skipped), but I will assume that VB has a bug and hope MS or Adobe fixes it some day. This does what I want. I went through my print programs and removed the problem statement, and I am set. Thank you.
ASKER