Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Reporting / Printing

Reporting / Printing Discussion on output-creation components such as reporting, pdf, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-30-2008, 3:27 AM
VB.NET Forum Idol
.NET Framework: .NET 2.0
 
Join Date: Nov 2007
Location: Kent, UK
Age: 39
Posts: 527
Reputation: 168
InertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to ask
Default PrintPreview / Print differences

When I run the following code, the PrintPreview looks fine. If I then click the print button from within the Preview window, the page prints but is not in the same place as the print preview - it's all shifted about 5mm to the right and about 5mm down.

Code:
Option Explicit On
Option Strict On

Imports System.Drawing.Printing

Public Class Form1

    Public WithEvents pdPrinter As PrintDocument
    Public ppvwPrinter As PrintPreviewDialog

    Private shtPageNumber As Int16 = 0
    Private shtTotalPages As Int16 = 0


    Private Sub TestPrintPreview(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        pdPrinter = New PrintDocument
        ppvwPrinter = New PrintPreviewDialog
        ppvwPrinter.Document = pdPrinter
        ppvwPrinter.Width = Screen.PrimaryScreen.Bounds.Width
        ppvwPrinter.Height = Screen.PrimaryScreen.Bounds.Height
        ppvwPrinter.PrintPreviewControl.Zoom = 0.66
        ppvwPrinter.ShowDialog()
        pdPrinter.Dispose()
        ppvwPrinter.Dispose()
    End Sub

    Private Sub Begin_Printing(ByVal sender As System.Object, _
    ByVal e As System.Drawing.Printing.PrintEventArgs) _
     Handles pdPrinter.BeginPrint
        pdPrinter.DocumentName = "Test Document"
        pdPrinter.PrintController = New Printing.StandardPrintController()
        shtTotalPages = 1

        shtPageNumber = 0
    End Sub

    Private fArial18 As New Font("Arial", 18, FontStyle.Bold)

    Private Sub Test_PrintPage(ByVal sender As System.Object, _
    ByVal e As PrintPageEventArgs) Handles pdPrinter.PrintPage
        shtPageNumber += 1S
        With e.Graphics
            .PageUnit = GraphicsUnit.Millimeter

            .DrawString("TEST PAGE " & shtPageNumber.ToString(), fArial18, Brushes.Black, 15, 12 * shtPageNumber)
            '10mm border around an A4 Portrait page
            .DrawRectangle(Pens.Black, 10, 10, 210 - 10 - 10, 297 - 10 - 10)
        End With

        If shtPageNumber < shtTotalPages Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

End Class
If I put a TranslateTransform line in, it makes the PrintPreview wrong but the page prints correctly.

I've tried it to three different network printers, all with different printer drivers but still A4 Portrait as default, and the results are always the same.

Any ideas
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-30-2008, 7:43 AM
VB.NET Forum Idol
.NET Framework: .NET 2.0
 
Join Date: Nov 2007
Location: Kent, UK
Age: 39
Posts: 527
Reputation: 168
InertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to ask
Default

It seems to relate to the HardMargins (see link). This may not be the best way to solve it, but it seems to work :-

Code:
            .PageUnit = GraphicsUnit.Millimeter
            If Not pdPrinter.PrintController.IsPreview Then
                .TranslateTransform(Convert.ToSingle(-((e.PageSettings.HardMarginX / 100) * 25.4)), _
                Convert.ToSingle(-((e.PageSettings.HardMarginY / 100) * 25.4)))
            End If
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 9:34 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.