A user can save their printer settings for 5 different kinds of printers (wide reports, narrow reports, mailing labels, shipping labels, and envelopes).
I store the printer settings in a database. If they havent setup their printers yet and they are changing the printer settings then they get the default settings in the PrintDialog.
If they have previously saved their printer settings, I set a PrintDocuments DefaultPageSettings for the Printer Name, Orientation, Paper Size, Print Resolution, Paper Source, and Duplex according to their saved settings.
They all work great with exception of Paper Size. The wide report uses Legal paper. In order to change the Papersize.Papername property you have to set the kind to custom. No problem, did that. I then set the Papername to Legal.
Here is the code I used:
The PrintDocument.DefaultPageSettings.PaperSize.PaperName is now set to "Legal".
So after I get all of the PrintDocument DefaultPageSettings setup, I set the PrintDialog Document = to the PrintDocument that I just setup the DefaultPageSettings.
These 3 settings are shown in correctly:
Landscape = True
PaperSize = Legal
PaperSource = Tray 2
This is displayed in the Console:
DLG Defaultpagesettings: [PageSettings: Color=False, Landscape=False, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Letter Kind=Letter Height=1100 Width=850], PaperSource=[PaperSource Automatically Select Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
But the PrintDialog when displayed shows the correct Landscape and PaperSource (which coincidentally are on the same form) but the PaperSize is still Letter (which you have to click the "Advanced.." button to see).
I just add 2 more Console.WriteLine statements:
Output:
pd Defaultpagesettings: [PageSettings: Color=False, Landscape=True, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Legal Kind=Custom Height=0 Width=0], PaperSource=[PaperSource Tray 2 Kind=Lower], PrinterResolution=[PrinterResolution X=600 Y=600]]
Output:
pd PrinterSettings Defaultpagesettings: [PageSettings: Color=False, Landscape=False, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Letter Kind=Letter Height=1100 Width=850], PaperSource=[PaperSource Automatically Select Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
Output:
DLG Defaultpagesettings: [PageSettings: Color=False, Landscape=False, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Letter Kind=Letter Height=1100 Width=850], PaperSource=[PaperSource Automatically Select Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
Any suggestions?
I store the printer settings in a database. If they havent setup their printers yet and they are changing the printer settings then they get the default settings in the PrintDialog.
If they have previously saved their printer settings, I set a PrintDocuments DefaultPageSettings for the Printer Name, Orientation, Paper Size, Print Resolution, Paper Source, and Duplex according to their saved settings.
They all work great with exception of Paper Size. The wide report uses Legal paper. In order to change the Papersize.Papername property you have to set the kind to custom. No problem, did that. I then set the Papername to Legal.
Here is the code I used:
Code:
pSz = New PaperSize("Custom Paper size", 0, 0)
pd.DefaultPageSettings.PaperSize = pSz
pd.DefaultPageSettings.PaperSize.PaperName = opt(3)
So after I get all of the PrintDocument DefaultPageSettings setup, I set the PrintDialog Document = to the PrintDocument that I just setup the DefaultPageSettings.
Code:
dlg.Document = pd
Console.WriteLine("DLG Defaultpagesettings: " & dlg.PrinterSettings.DefaultPageSettings.ToString)
Dim result As DialogResult = dlg.ShowDialog()
These 3 settings are shown in correctly:
Landscape = True
PaperSize = Legal
PaperSource = Tray 2
This is displayed in the Console:
DLG Defaultpagesettings: [PageSettings: Color=False, Landscape=False, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Letter Kind=Letter Height=1100 Width=850], PaperSource=[PaperSource Automatically Select Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
But the PrintDialog when displayed shows the correct Landscape and PaperSource (which coincidentally are on the same form) but the PaperSize is still Letter (which you have to click the "Advanced.." button to see).
I just add 2 more Console.WriteLine statements:
Code:
Console.WriteLine("pd Defaultpagesettings: " & pd.DefaultPageSettings.ToString)
pd Defaultpagesettings: [PageSettings: Color=False, Landscape=True, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Legal Kind=Custom Height=0 Width=0], PaperSource=[PaperSource Tray 2 Kind=Lower], PrinterResolution=[PrinterResolution X=600 Y=600]]
Code:
Console.WriteLine("pd PrinterSettings Defaultpagesettings: " & pd.PrinterSettings.DefaultPageSettings.ToString)
pd PrinterSettings Defaultpagesettings: [PageSettings: Color=False, Landscape=False, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Letter Kind=Letter Height=1100 Width=850], PaperSource=[PaperSource Automatically Select Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
Code:
Console.WriteLine("DLG Defaultpagesettings: " & dlg.PrinterSettings.DefaultPageSettings.ToString)
DLG Defaultpagesettings: [PageSettings: Color=False, Landscape=False, Margins=[Margins Left=100 Right=100 Top=100 Bottom=100], PaperSize=[PaperSize Letter Kind=Letter Height=1100 Width=850], PaperSource=[PaperSource Automatically Select Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
Any suggestions?