Can I use a custom size paper with PrintDocument?
Hello,
I'm building a report using PrintDocument.
I need this report output in a custom paper size (8,5" x 5,5")...
I created a new form in the "Forms" tab of "Server Properties" menu in "Printer and Faxes" tool of WinXP (SP2). I named this form "myPaper".
The PrintDocument object is named "pDoc".
Before call the pDoc.Print method, I created a PrinterSettings object named "myPrintSet", and I wrote the following code:
'Set the printer name
Dim myPrintSet As New Printing.PrinterSettings
myPrintSet.PrinterName = "\\station\Epson AP-2500"
'Set the paper size
Dim paper As Drawing.Printing.PaperSize
For Each paper In myPrintSet.PaperSizes
If paper.PaperName = "myPaper" Then
myPrintSet.DefaultPageSettings.PaperSize = paper
Exit For
End If
Next
'Set other properties
myPrintSet.Collate = False
myPrintSet.Copies = 1
myPrintSet.FromPage = 1
myPrintSet.ToPage = 1
pDoc.PrinterSettings = myPrintSet
Finally I call the print method:
pDoc.Print()
Obviously, in the pDoc_PrintPage event I create the report using, mainly, the DrawString method:
ev.Graphics.DrawString("The Word", myFont, Brushes.Black, myX, myY, myDirection)
Even though I'm selecting my custom paper, the report output is in 8.5" x 11"
I realized that, if I show a PrintDialog before "myPrintSet" the output size is "myPaper"... but I need a "direct" print, don't show a PrintDialog...
Can somebody help me?
What am I doing wrong?
Thanks in advance...