Hello all,

we have a vb.net windows appliacation that uses sql server as backend. we have created all reports for this application using crystal report that is embedded in visual studio 2005. everything is working fine except the reports specially which needs to be displayed is custome mode. we have used some code to dynamically set the printer settings because at runtime the original printer settings are unknown and we don't want to let user set printer settings manually everytime before taking the printout. so the question is, how to set a custom papersize programactically. here is the code snippet that we have used to set some printer settings in runtime :-

rpt.PrintOptions.PrinterName = Configuration.ConfigurationManager.AppSettings("DefaultPrinter")
rpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape
rpt.PrintOptions.PaperSize = PaperSize.PaperFanfoldUS

we have used reportdocument object to set printer options. we have two rpts which need to displayed in custom paper format. the formats are like 9X6 and 14X12. we have created these formats in server properties. now how to to set this from code? like in place of

rpt.PrintOptions.PaperSize = PaperSize.PaperFanfoldUS

.....some sort of syntax which will let us to put the papersize in place of PaperSize.PaperFanfoldUS...

hope i have explained the topic properly.....looking forward to any positive replies...any help/suggesstion or link to any resources will be greatly appreaciated....

thanks to all in advance...

regards
Shouvik

Hi,
Try These Functions
AddForm(hPrinter, nLevel, pForm) To Add a new Form To your printer,
you should declare a function like this

Private Declare Function AddForm Lib "winspool.drv" Alias "AddFormA" (ByVal hPrinter As IntPtr, ByVal Level As Integer, ByRef pForm As Byte) As Integer

and then define a structure Form_Info_1

Public Structure FORM_INFO_1
Dim Flags As Integer
Dim pName As String
Dim Size As SIZEL
Dim ImageableArea As RECTL
End Structure

Dim frmInf As FORM_INFO_1
ReDim arByte() As Byte

With frmInf
.Flags = 0
.pName = "MiCustomForm"
.Size.cx = 160000
.Size.cy = 250000
End With

you have to copy the structure to a byte array

ReDim arByte(Marshal.SizeOf(frmInf))

Marshal.Copy(frmInf, arByte, 0, Marshal.SizeOf(frmInf))

And Finally Call Then Function

Dim hPrinter As IntPtr
Dim defaultSetting As IntPtr
Dim PrnVar As System.Drawing.Printing.PrintDocument = New System.Drawing.Printing.PrintDocument

If OpenPrinter(PrnVar.PrinterSettings.PrinterName, hPrinter, defaultSetting) Then
Try
retVal = AddForm(hPrinter, 1, arByte(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
ClosePrinter(hPrinter)
End If

i have tried to create a costom paper size but printer does not print on that custom paper created

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.