Skip to Content
0

preview size is different from pagesize by vb.net

Jul 26, 2017 at 01:24 PM

149

avatar image

I working crystal report with visual studio 2012 and try to print out invoice with specified size 8 inch x 7 inch and print out by dot matrix printer (EPSON LQ-300+II ESC/P2), I set up print server property's form size.

When I preview from crystal report, It seem fine

But I preview from visual studio, it showing different size of this crystal report

it tried to fix it by vb.net code, but it doesn't work

        Dim margins As CrystalDecisions.Shared.PageMargins
        margins = objRpt.PrintOptions.PageMargins
        margins.bottomMargin = 0
        margins.leftMargin = 0
        margins.rightMargin = 0
        margins.topMargin = 0
        objRpt.PrintOptions.ApplyPageMargins(margins)
        Dim c As Integer
        Dim pd As New System.Drawing.Printing.PrintDocument()
        pd.PrinterSettings.PrinterName = "EPSON LQ-300+II ESC/P2"
        Dim rawKind As Integer = 0
        For c = 0 To pd.PrinterSettings.PaperSizes.Count - 1
            If pd.PrinterSettings.PaperSizes(c).PaperName = "kennam" Then
                rawKind = CInt(pd.PrinterSettings.PaperSizes(c).GetType().GetField("kind", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(pd.PrinterSettings.PaperSizes(c)))
                Exit For
            End If
        Next
        objRpt.PrintOptions.PrinterName = "EPSON LQ-300+II ESC/P2"
        objRpt.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)
        objRpt.SetDataSource(dsinvoice)
        objRpt.SetParameterValue("deliverynote", deliverynote)
        Dim frm As New invoicereportForm
        frm.CrystalReportViewer1.ReportSource = objRpt
        frm.CrystalReportViewer1.Refresh()
        frm.ShowInTaskbar = False
        frm.Show()

Is that something on crystal report or vb.net coding?

anyone willing to help?

preview.png (176.6 kB)
program-preview.png (141.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Don Williams
Jul 27, 2017 at 09:19 PM
0

Hello,

The embedded Report Designer is not 100% when previewing or printing.

Try my test app prints the write size, it' sin C# but does the same thing. Requires a report with saved data.

Use SP 20 also:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

Open the app, Select the printer, and it must be capable of defining a custom paper size. If it's not it will default to it's default paper size.

And don't refresh () the report, it can nullify any options you may have set.

Also, in SP 20 you can set the default Viewers print button to use the POC API, uses the same dialog box that CR Designer uses.

Don

Show 1 Share
10 |10000 characters needed characters left characters exceeded

It seem the page size is depend on dissociated formatting page size and printer paper size.

when I unchecked no printer and checked dissociated formatting page size and printer paper size.

The result is look fine (I still not try to print out on dot matrix paper)

By vb.net code on my case is not works fine

        Dim c As Integer
        Dim pd As New System.Drawing.Printing.PrintDocument()
        pd.PrinterSettings.PrinterName = "EPSON LQ-300+II ESC/P2"
        Dim rawKind As Integer = 0
        For c = 0 To pd.PrinterSettings.PaperSizes.Count - 1
            If pd.PrinterSettings.PaperSizes(c).PaperName = "kennam" Then
                rawKind = CInt(pd.PrinterSettings.PaperSizes(c).GetType().GetField("kind", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(pd.PrinterSettings.PaperSizes(c)))
                Exit For
            End If
        Next
        objRpt.PrintOptions.PrinterName = "EPSON LQ-300+II ESC/P2"
        objRpt.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)

Is Crystal Report able to print with specified paper size on dot matrix printers? (may be not a4 size. In my case 8 inch x 7 inch)

dissociated.png (151.6 kB)
dissociated.png (151.6 kB)
0