Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello

Thanx to zimvbcoder / sandeep mewara / HimanshuJoshi for your advice to spell the problem more specifically.
I want to use dotmatrix printer to print documents of variable size(not width but length). Depending on length of text I must adjust paper size.
MSDN suggests following

VB
Dim pkSize As Printing.PaperSize
For i = 0 To PrintDocument1.PrinterSettings.PaperSizes.Count - 1
    pkSize = PrintDocument1.PrinterSettings.PaperSizes.Item(i)
    Combopapersize.Items.Add(pkSize)
Next


Create a PaperSize and specify the custom paper size through the constructor and add to combobox.

VB
e.PageSettings.PaperSize.Kind = Printing.PaperKind.Custom
Dim pkCustomSize1 As New Printing.PaperSize("MySize", 100, 50) 


Which can be added to a combo to be selected by user.
My Problem: How to asign this size to papersize?

I tried:

VB
e.PageSettings.PaperSize.Height = 40
e.PageSettings.PaperSize.Width = 100


which throw error that set Kind property to custom.

I tried:

VB
PrintDocument1.PrinterSettings.PrinterName = "Epson LX-300+"
Dim psz As New Printing.PaperSize
With psz
    .RawKind = Printing.PaperKind.Custom
    .Width = 120
    .Height = 100
    PrintDocument1.DefaultPageSettings.PaperSize = psz
End With


The above code did not report error but did not work. Changing width and height values had no effect.

I want the printer to stop printing and stop spooling the paper as soon as the last line is printer.

Hope you have faced this and solved...
Expecting your valuable solution
Posted
Updated 15-Aug-10 0:51am
v4
Comments
Wayne Gaylard 13-Aug-10 2:58am    
Why don't you post the code that you have written and then maybe someone would be able to help you. Are you using GDI+, PrintDocument or what?
leckey 13-Aug-10 11:34am    
Reason for my vote of 1
"Having problem" is very generic. What is the specific issue, and post your code.
Sandeep Mewara 13-Aug-10 11:37am    
What problem?
HimanshuJoshi 13-Aug-10 12:57pm    
Reason for my vote of 1
need specific problem information
Kunal Chowdhury «IN» 15-Aug-10 0:35am    
Reason for Edit: Formatted the Code for better visibility and removing the Email Address.
Never mention email address if you hate Spammers.

1 solution

VB
Private Sub prnDocument_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prnDocument.PrintPage
       leftMargin = Convert.ToInt32(e.MarginBounds.Left)
       rightMargin = Convert.ToInt32(e.MarginBounds.Right)
       topMargin = Convert.ToInt32(e.MarginBounds.Top)
       bottomMargin = Convert.ToInt32(e.MarginBounds.Bottom)
       InvoiceWidth = Convert.ToInt32(e.MarginBounds.Width)
       InvoiceHeight = Convert.ToInt32(e.MarginBounds.Height)

       'If (Not ReadInvoice) Then patinfo()

       SetInvoiceHead(e.Graphics) ' Draw Invoice Head
       SetOrderData(e.Graphics) ' Draw Order Data
       Dim psz As New Printing.PaperSize
       With psz
           .RawKind = Printing.PaperKind.Custom
           .Width = 830
           .Height = CurrentY + 50
           prnDocument.DefaultPageSettings.PaperSize = psz
       End With
       'ReadInvoice = True
   End Sub
 
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