Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I m using following code to print the form in a5 size but it prints half of A4 size paper and remaining half page is blank.

VB
Dim a As New System.Drawing.Printing.PaperSize("A5 (210 x 148 mm)", 400, 200)
Dim ps As New PageSettings
ps.PaperSize = a
ps.Landscape = True
ps.Margins.Top = 0
ps.Margins.Bottom = 0
ps.Margins.Left = 5
ps.Margins.Right = 5

PrintDocument1.DefaultPageSettings = ps
Me.PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
Me.PrintForm1.Print()
Posted
Updated 10-Mar-11 1:56am
v2
Comments
Albin Abel 10-Mar-11 8:00am    
By the way is it prints the whole content? in the half of the A4
Manfred Rudolf Bihy 10-Mar-11 8:16am    
That's what it sounds like to me. Since A5 is half the size of A4 that should even be OK!
Parshu2378 10-Mar-11 8:18am    
ya it prints the hole content but remaining page is blank instead of i hv to break that page after completion of print of content.
Manfred Rudolf Bihy 10-Mar-11 10:22am    
Hi parshu, I've updated my solution. I tryed it and it worked fine for me.

So what is your issue? A5 is exactly 1/2 the size of A4. So considering that you specified size A5 but printed it on A4, what would you expect?

Modification:
Setting the PrintForm's PageSettings involves using an event handler. I tried this code and it looked good to me. Please try it if it fits your needs:

VB
Public Class Form1
    Public Sub test()
        Dim instance As New QueryPageSettingsEventHandler(AddressOf SettingsHandler)
        Me.PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
        Me.PrintForm1.Print()
    End Sub

    Public Sub SettingsHandler(ByVal sender As Object, ByVal e As QueryPageSettingsEventArgs) Handles PrintForm1.QueryPageSettings
        Dim a As New System.Drawing.Printing.PaperSize("A5 (148 x 210 mm)", 584, 827)
        Dim ps As New PageSettings
        ps.PaperSize = a
        ps.Landscape = True
        ps.Margins.Top = 0
        ps.Margins.Bottom = 0
        ps.Margins.Left = 5
        ps.Margins.Right = 5
        e.PageSettings = ps
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        test()
    End Sub
End Class


I also corrected the values for the paper dimension. You specified the format in landscape. I specified it how A5 is defined and the width and height must be given in 1/100 of an inch. You can switch width with height of course but then you'd have to set ps.Landscape = False

Cheers!
 
Share this answer
 
v2
Comments
Parshu2378 10-Mar-11 8:15am    
but in print preview it shows that half of the page is blank.
i have to use hole paper and that should be A5 only so that my next print on next A5 page
Sergey Alexandrovich Kryukov 10-Mar-11 11:44am    
My 5, but how about real thing (as I describe in my Answer)? This is easy enough...
--SA
Suggestion.
Put A5 paper into the printer.

Then the whole page will be printed!

Success!
 
Share this answer
 
Comments
Richard MacCutchan 10-Mar-11 11:30am    
This has to deserve a 5!
Sergey Alexandrovich Kryukov 10-Mar-11 11:38am    
Best answer so far, my 5.
--SA
Sergey Alexandrovich Kryukov 10-Mar-11 11:44am    
I suggested doing real thing instead, please see.
--SA
This all is very nice, but how about doing real thing?
Print from the application should not depend on paper size. The paper size should be defined before printing by the user, and not in your application but in printer options. You print job should fit in it. This is quite feasible and this is what is usually done.

Or you're doing something super-puper special, so A5 is a world constant for you, like a speed of light and Plank's constant?

—SA
 
Share this answer
 

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