Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In my web application, in one page I am displaying HTML data by using Literal.Text and i am having a button for printing this page. When I click the button Printer Dialog is coming and I can give print,Every thing is working fine till that.

But I need to change the page size and margins in Page Setup of IE and also for the default printer from code before going for print.

I tried PrintDialog Class, PrintDocument like this:
VB
Dim pp As New System.Drawing.Printing.PrintDocument 
For i = 0 To pp.DefaultPageSettings.PrinterSettings.PaperSizes.Count - 1 
If pp.DefaultPageSettings.PrinterSettings.PaperSizes.Item(i).Kind=System.Drawing.Printing.PaperKind.A4 Then 
pp.DefaultPageSettings.PaperSize = pp.DefaultPageSettings.PrinterSettings.PaperSizes.Item(i) 
Exit For 
End If 
Next

but it is giving Object Null reference error in the first line.
Can any one help with this..sample code or reference for doing this..

Thanks.
Posted
Updated 28-Mar-13 22:50pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900