VB 6.0 - Change the page layout of Crystal report in vb6

Asked By Anish V on 10-Oct-08 12:56 AM
Dear All, Is it possible to change the layout of a crystal report, say A4 to Letter type? Does anyone has idea? Immediate help will be highly appreciated. Thanks in advance Anish

re

Web Star replied to Anish V on 10-Oct-08 01:09 AM

If you need to change the size or orientation of a Crystal Report, you can do this in the VS IDE by right-clicking your report and navigating Designer >> Printer Setup.  On the first tab, you can choose the paper size and orientation.  Hit OK to return to the IDE, and the report canvas will automatically resize to what you just specified.

I don't recommend setting any of the advanced printer options in your report unless you know the people printing the report will be using the same printer (such as a network printer).  Also, if you can't fit your report on letter (or A4 for the metric world), the user is probably going to have to change the paper in the printer, which will more than likely cause some grumbling.

If your report is too wide for landscape, consider grouping the data into a more hierarchical report (not every report can be grouped, but many can).  Not only will this improve the readability, but it'll help fit the report on a standard paper size.


Right-click in the whitespace on your report, not on a section heading.  You get different menus when you right-click on a section head.

hi.. thanks for reply

Anish V replied to Web Star on 10-Oct-08 01:15 AM
hi.. thanks for the reply.. but i would like to change it using vb coding since the users may use the Letter or A4 sometimes. f.i. in US & CA they use Letter whereas in NL it is A4. Hence we have to do it by coding . Otherwise we have to keep the two copies of Crystal reports. Anish

reply

Perry replied to Anish V on 10-Oct-08 01:42 AM
Hi,

To change the page layout, you need not to do anything with crystel report but set the printer property from VB6 to use the selected page layout. You can download any of printer dll for VB6 from http://3d2f.com/tags/printer/dll/vb6/ and use it in your program. Also refer http://www.idautomation.com/visual_basic/

Regards,
Megha
Thanks for reply
Anish V replied to Perry on 10-Oct-08 02:01 AM
Hi Megha, Thanks for your reply. Is it possible to change the paper size without adding a dll for printer? Also is it possible to add a common one dll for this? regards Anish
I did not go over those dll...but it will be possible related to any paper size...but you have to dig into dlls.
Perry replied to Anish V on 10-Oct-08 02:25 AM
end of post
reply
Perry replied to Anish V on 10-Oct-08 02:36 AM

Hi,

You will need to add namespace for printer http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.printing.compatibility.vb6.printer.aspx

It should be something like below:

Code for setting type of paper:

Dim ppd As New PrintPreviewDialog()
Dim pd As New PrintDocument()
Dim pd1 As New PrintDialog()

AddHandler pd.PrintPage, AddressOf pdoc_PrintPage
pd.DefaultPageSettings.Landscape = True
pd1.Document = pd
pd1.ShowDialog()
ppd.Document = pd
ppd.ShowDialog()

To print the allowed paper siezes:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer where DeviceName = 'EPSON AL-C1900 Advanced' ")
For Each objPrinter in colPrinters
    objPrinter.PaperSize = "Legal"
    objPrinter.Put
Next

To Change Paper size:

code:

--------------------------------------------------
Printer.PaperSize = 258 'equivalent to A2 paper size
-------------------------------------------------------

or

code:

-------------------------------------------------
Printer.PaperSize = PrinterObjectConstants.vbPRPSUser
Printer.Width = 20000
Printer.Height = 20000
------------------------------------------------------

Finally to print form:  use form.printform

Regards,

Megha

change the paper size without adding a dll for printer
Binny ch replied to Anish V on 12-Oct-08 07:29 AM

After getting the printer name, get a handle to the printer:

bool bGotPrinter = OpenPrinter(printerName, out hPrinter, ref defaults);
At this point, we can delete the custom paper size by name:

// delete the form incase it already exists
DeleteForm(hPrinter, paperName);
And create the paper size:

// create and initialize the FORM_INFO_1 structure
FormInfo1 formInfo = new FormInfo1();
formInfo.Flags = 0;
formInfo.pName = paperName;
// all sizes in 1000ths of millimeters
formInfo.Size.width = (int)(widthMm * 1000.0);
formInfo.Size.height = (int)(heightMm * 1000.0);
formInfo.ImageableArea.left = 0;
formInfo.ImageableArea.right = formInfo.Size.width;
formInfo.ImageableArea.top = 0;
formInfo.ImageableArea.bottom = formInfo.Size.height;
Add the paper size to the printer's list of available paper sizes:

bool bFormAdded = AddForm(hPrinter, 1, ref formInfo);