ThinkGeo.com    |     Documentation    |     Premium Support

Printing, Pointsymbols will be scaled

Hi,



some problems with printing.

I have implemented the PrintingSample but when changing the scale of a printing area point symbols will bescaled:

Changing from current scale 1:500 to 1:1000 symbols will increase size. Scaling down symbols will decrease.

I’m using the GeoImage objects to display points.

Do I have to handle them with a special way when printing?



Regards

Hardy

Hi Hardy, 
  
 It looks GeoImage should be keep in same size, and I haven’t found its size change. 
  
 Are you using our Printing sample or created your project? Please tell me more detail about how to reproduce it if you are using our sample, and please provide me more detail code if you found that in your project.  
  
 That should be helpful for reproduce this problem, and I want to know the detail verison of your dlls. 
  
 Regards, 
  
 Don

Hi Don,



sorry getting back late…we have a bit of bank holidays…



I’m using the Printing sample (attached my code).

We are using different projection (EPSG: 25832, 31466, 31467) and we use Centimeter or Meter.



Maybe that’s causing the problems?



I hvae copied my code from the editor and reduced, so there should be only the relevant sub’s.



Regards



Here is my code:



Imports PdfSharp
Imports PdfSharp.Pdf
Imports System.Collections.ObjectModel
Imports ThinkGeo.MapSuite.Core
Imports ThinkGeo.MapSuite.DesktopEdition
Imports System.Drawing.Printing



Public Class PlotForm
    Public ParentMap As WinformsMap
    Public ScaleFactor As Double = 2.54 / 100
    Public PointScale As Double = 595 / 21
    Public Plotframe As DataRow
    Public Frameparts As DataTable
    Public MyParent As Host
    Public mapPrinterLayer As New MapPrinterLayer



    Private Sub Sample_Load(sender As Object, e As EventArgs) Handles Me.Load
        RibbonBar.StartButtonImage = Host.RibbonBar.StartButtonImage
        SetupMapWithBlankPage()



        'load parts if defined…
        If Frameparts.Select(“frame=” & Plotframe.Item(“id”)).GetLength(0) > 0 Then
            For Each part As DataRow In Frameparts.Select(“frame=” & Plotframe.Item(“id”))
                Select Case part.Item(“typ”)
                    Case “Label”
                        AddCenteredLabel(part)
                    Case “Drawing”
                        AddMapLayer(part.Item(“width”), part.Item(“height”), part.Item(“partvalue”), part.Item(“center_x”), part.Item(“center_y”))
                    Case “Image”
                        AddImage(part)
                    Case “Grid”
                    Case “Scalebar”
                    Case “Legend”
                End Select
            Next
        Else
            AddCenteredTitleLabel()
            AddMapLayer()
            AddLogoImage()
        End If






        SetPageSize()



        winformsMap1.Refresh()
    End Sub



    Private Sub SetupMapWithBlankPage()
        ’ Setup the map unit, you want to always use feet or meters for printer layout maps
        winformsMap1.MapUnit = GeographyUnit.Meter



        ’ Here we create the default zoom levels for the sample.  We have pre-created a PrinterZoomLevelSet
        ’ That pre-defines commonly used zoom levels based on percentages of zoom
        winformsMap1.ZoomLevelSet = New PrinterZoomLevelSet(winformsMap1.MapUnit, PrinterHelper.GetPointsPerGeographyUnit(winformsMap1.MapUnit))



        ’ Here we set the background color to gray so there is contrast with the while page
        winformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.StandardColors.LightGray)



        ’ Create the PrinterInteractiveOverlay to contain all of the PrinterLayers.
        ’ The interactive overlay allows the layers to be interacted with
        Dim printerOverlay As New PrinterInteractiveOverLay()
        winformsMap1.InteractiveOverlays.Add(“PrintPreviewOverlay”, printerOverlay)
        winformsMap1.InteractiveOverlays.MoveToBottom(“PrintPreviewOverlay”)



        ’ Create the PagePrinterLayer which shows the page boundary and is the area the user will
        ’ arrange all of the other layer on top of.
        Dim pagePrinterLayer As New PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait)
        pagePrinterLayer.Open()
        printerOverlay.PrinterLayers.Add(“PageLayer”, pagePrinterLayer)



        ’ Get the pages extent, slightly scale it up, and then set that as the default current extent
        winformsMap1.CurrentExtent = RectangleShape.ScaleUp(pagePrinterLayer.GetPosition(), 0).GetBoundingBox()



        ’ Set the minimum scale of the map to the last zoom level
        winformsMap1.MinimumScale = winformsMap1.ZoomLevelSet.ZoomLevel20.Scale
    End Sub



    Private Sub AddCenteredTitleLabel()
        Dim labelPrinterLayer As New LabelPrinterLayer()



        'Setup the text and the font…
        labelPrinterLayer.Text = “gisME®”
        labelPrinterLayer.Font = New GeoFont(“Arial”, 20, DrawingFontStyles.Bold)
        labelPrinterLayer.TextBrush = New GeoSolidBrush(GeoColor.StandardColors.Black)
        labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText



        ’ Set the labels position so that is it centered on the page one inch from the top                        
        Dim pageBoundingbox As RectangleShape = GetPageBoundingBox(PrintingUnit.Centimeter)
        Dim labelCenter As New PointShape()
        labelCenter.X = pageBoundingbox.UpperRightPoint.X - pageBoundingbox.Width / 2
        labelCenter.Y = Plotframe.Item(“height”) / 2 - 1.5 'pageBoundingbox.UpperLeftPoint.Y '- pageBoundingbox.Height / 2 + 0.5



        labelPrinterLayer.SetPosition(5, 1, labelCenter, PrintingUnit.Centimeter)



        ’ Find the PrinterInteractiveOverlay so we can add the new LabelPrinterLayer
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        printerInteractiveOverLay.PrinterLayers.Add(“LabelLayer”, labelPrinterLayer)
    End Sub



    Public Function GetGeoColor(argb As String) As GeoColor
        Try
            Dim color() As String = Split(argb, “,”)
            Return GeoColor.FromArgb(CInt(color(0)), CInt(color(1)), CInt(color(2)), CInt(color(3)))
        Catch ex As Exception
            Return Nothing
        End Try
    End Function



    Private Sub AddCenteredLabel(part As DataRow)
        Try
            Dim labelPrinterLayer As New LabelPrinterLayer()
            With part
                'Setup the text and the font…
                labelPrinterLayer.Text = .Item(“partvalue”).ToString
                labelPrinterLayer.Font = New GeoFont(.Item(“font”).ToString, .Item(“size”), .Item(“style”))
                labelPrinterLayer.TextBrush = New GeoSolidBrush(GetGeoColor(.Item(“txtcolor”).ToString))
                labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText



                ’ Set the labels position so that is it centered on the page one inch from the top                        
                'Dim pageBoundingbox As RectangleShape = GetPageBoundingBox(PrintingUnit.Centimeter)
                Dim labelCenter As New PointShape()
                labelCenter.X = .Item(“center_x”)
                labelCenter.Y = .Item(“center_y”)



                labelPrinterLayer.SetPosition(.Item(“width”), .Item(“height”), labelCenter, PrintingUnit.Centimeter)



                ’ Find the PrinterInteractiveOverlay so we can add the new LabelPrinterLayer
                Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
                printerInteractiveOverLay.PrinterLayers.Add(“LabelLayer” & .Item(“id”).ToString, labelPrinterLayer)
            End With



        Catch e As Exception
        End Try
    End Sub






    Private Sub AddMapLayer(width As Double, height As Double, scale As Double, Optional x As Double = 0, Optional y As Double = 0)



        ’ Create the MapPrinterLayer and set the position
        Dim mapPrinterLayer As New MapPrinterLayer()
        mapPrinterLayer.MapUnit = ParentMap.MapUnit
        mapPrinterLayer.BackgroundMask = New AreaStyle(New GeoPen(GeoColor.StandardColors.Black, 1))
        mapPrinterLayer.DrawingMode = MapPrinterDrawingMode.Raster
        mapPrinterLayer.Open()



        Dim pageBoundingbox As RectangleShape = GetPageBoundingBox(PrintingUnit.Centimeter)
        If x <= 0 Then
            x = pageBoundingbox.GetCenterPoint().X
        End If
        If y <= 0 Then
            y = pageBoundingbox.GetCenterPoint().Y '+ 1
        End If



        mapPrinterLayer.SetPosition(width, height, x, y, PrintingUnit.Centimeter)



        'Setup the intial extent and ensure they snap to the default ZoomLevel
        Dim zoomLevelSet As ZoomLevelSet = New ZoomLevelSet()
        Try
             mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(scale, ParentMap.CurrentExtent, mapPrinterLayer.MapUnit, mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.GetBoundingBox().Height)
        Catch ex As Exception



        End Try



        Dim MyOverlay As LayerOverlay = Nothing
        For Each MyOverlay In ParentMap.Overlays
            For Each MyLayer In MyOverlay.Layers
                mapPrinterLayer.Layers.Add(MyLayer)
            Next
        Next



        ’ Add the MapPrinterLayer to the PrinterInteractiveOverlay
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        printerInteractiveOverLay.PrinterLayers.Add(“MapLayer” & Now.Ticks, mapPrinterLayer)
    End Sub



    Private Sub AddMapLayer(Optional X As Double = 0, Optional y As Double = 0)



        ’ Create the MapPrinterLayer and set the position



        mapPrinterLayer.MapUnit = ParentMap.MapUnit
        mapPrinterLayer.BackgroundMask = New AreaStyle(New GeoPen(GeoColor.StandardColors.Black, 1))
        mapPrinterLayer.DrawingMode = MapPrinterDrawingMode.Raster
        mapPrinterLayer.Open()



        Dim pageBoundingbox As RectangleShape = GetPageBoundingBox(PrintingUnit.Centimeter)
        If X <= 0 Then
            X = pageBoundingbox.GetCenterPoint().X
        End If
        If y <= 0 Then
            y = pageBoundingbox.GetCenterPoint().Y '+ 1
        End If



        mapPrinterLayer.SetPosition(Plotframe.Item(“width”) - 2, Plotframe.Item(“height”) - 2, X, y, PrintingUnit.Centimeter)



        'Setup the intial extent and ensure they snap to the default ZoomLevel
        Dim zoomLevelSet As ZoomLevelSet = New ZoomLevelSet()
        Try
            mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(ParentMap.CurrentScale, ParentMap.CurrentExtent, mapPrinterLayer.MapUnit, mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.GetBoundingBox().Height)
        Catch ex As Exception



        End Try



        Dim MyOverlay As LayerOverlay = Nothing
        For Each MyOverlay In ParentMap.Overlays
            For Each MyLayer In MyOverlay.Layers
                mapPrinterLayer.Layers.Add(MyLayer)
            Next
        Next



        ’ Add the MapPrinterLayer to the PrinterInteractiveOverlay
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        printerInteractiveOverLay.PrinterLayers.Add(“MapLayer”, mapPrinterLayer)
    End Sub






#Region “Export Buttons”



    Private Sub btnPrintPreview_Click(sender As Object, e As EventArgs) Handles btnPrintPreview.Click
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim pagePrinterLayer As PagePrinterLayer = TryCast(printerInteractiveOverLay.PrinterLayers(“PageLayer”), PagePrinterLayer)



        Dim printDialog As New PrintDialog()
        Dim printDocument As New PrintDocument()
        printDocument.DefaultPageSettings.Landscape = True
        If pagePrinterLayer.Orientation = PrinterOrientation.Portrait Then
            printDocument.DefaultPageSettings.Landscape = False
        End If



        printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer)



        Dim printerGeoCanvas As New PrinterGeoCanvas()
        printerGeoCanvas.DrawingArea = printDocument.DefaultPageSettings.Bounds
        printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), winformsMap1.MapUnit)



        ’ Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
        ’ except for the PagePrinterLayer                
        Dim labelsInAllLayers As New Collection(Of SimpleCandidate)()
        For Each printerLayer As PrinterLayer In printerInteractiveOverLay.PrinterLayers
            printerLayer.IsDrawing = True
            If Not (TypeOf printerLayer Is PagePrinterLayer) Then
                printerLayer.Draw(printerGeoCanvas, labelsInAllLayers)
            End If
            printerLayer.IsDrawing = False
        Next



        printerGeoCanvas.Flush()



        Dim printPreviewDialog As New PrintPreviewDialog()
        printPreviewDialog.Document = printDocument
        Dim dialogResult As DialogResult = printPreviewDialog.ShowDialog()
    End Sub



    Private Sub btnExportBitmap_Click(sender As Object, e As EventArgs) Handles btnExportBitmap.Click
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim pagePrinterLayer As PagePrinterLayer = TryCast(printerInteractiveOverLay.PrinterLayers(“PageLayer”), PagePrinterLayer)



        ’ Create a bitmap that is the size of the pages bounding box.  The page by default is in points unit
        ’ system which is very similar to pixels so that ampping is nice.
        Dim bitmap As Bitmap = Nothing
        Try
            bitmap = New Bitmap(CInt(pagePrinterLayer.GetBoundingBox().Width), CInt(pagePrinterLayer.GetBoundingBox().Height))



            ’ Create a GdiPlusGeoCanvas and start the drawing
            Dim gdiPlusGeoCanvas As New GdiPlusGeoCanvas()
            gdiPlusGeoCanvas.BeginDrawing(bitmap, pagePrinterLayer.GetBoundingBox(), winformsMap1.MapUnit)



            ’ Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
            ’ except for the PagePrinterLayer                
            Dim labelsInAllLayers As New Collection(Of SimpleCandidate)()
            For Each printerLayer As PrinterLayer In printerInteractiveOverLay.PrinterLayers
                printerLayer.IsDrawing = True
                If Not (TypeOf printerLayer Is PagePrinterLayer) Then
                    printerLayer.Draw(gdiPlusGeoCanvas, labelsInAllLayers)
                End If
                printerLayer.IsDrawing = False
            Next






            ’ End the drawing
            gdiPlusGeoCanvas.EndDrawing()



            'Save the resulting bitmap to a file and open the file to show the user
            Dim filename As String = “PrintingResults.bmp”
            bitmap.Save(filename)
            Process.Start(filename)
        Catch ex As Exception
            MessageBox.Show(ex.Message + " " + ex.StackTrace, “Exception”)
        Finally
            If bitmap IsNot Nothing Then
                bitmap.Dispose()
            End If
        End Try
    End Sub



    Private Sub btnExportToPdf_Click(sender As Object, e As EventArgs) Handles btnExportToPdf.Click



        ’ Get the PrinterInteractiveOverlay and PagePrinterLayer as we are going to need them below
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim pagePrinterLayer As PagePrinterLayer = TryCast(printerInteractiveOverLay.PrinterLayers(“PageLayer”), PagePrinterLayer)



        Dim pdfDocument As PdfDocument = Nothing
        Dim pdfPage As PdfPage = Nothing



        Try
            ’ Create the PDF documents, pages, and configure them
            pdfDocument = New PdfDocument()
            pdfPage = pdfDocument.AddPage()
            If Plotframe.Item(“portrait”) Then
                pdfPage.Orientation = PageOrientation.Portrait
            Else
                pdfPage.Orientation = PageOrientation.Landscape
            End If



            Dim currentSize As Integer = GetPdfPageSize(pagePrinterLayer.PageSize)



            If currentSize = PageSize.Undefined Then
                pdfPage.Width = pagePrinterLayer.CustomWidth * ScaleFactor * PointScale
                pdfPage.Height = pagePrinterLayer.CustomHeight * ScaleFactor * PointScale
            Else
                pdfPage.Size = currentSize
            End If



            Dim pdfPrintDialog As New PDF_Printer



            pdfPrintDialog.ShowDialog()



            If pdfPrintDialog.SelectedFileName = “” Then
                Exit Sub
            End If



            With pdfDocument.Info
                .Author = pdfPrintDialog.selAutor
                .Keywords = pdfPrintDialog.selBeschreibung
                .Subject = pdfPrintDialog.selThema
                .Title = pdfPrintDialog.selTitle
            End With
            ’ Create the PdfGeoCanvas and pass tha PdfPage into the BeginDrawing 
            Dim pdfGeoCanvas As New PdfGeoCanvas()
            pdfGeoCanvas.BeginDrawing(pdfPage, pagePrinterLayer.GetBoundingBox(), winformsMap1.MapUnit)



            ’ Loop through all of the PrinterLayers and draw them to the canvas except for the
            ’ PagePrinterLayer which is just used for the visual layout
            Dim labelsInAllLayers As New Collection(Of SimpleCandidate)()
            For Each printerLayer As PrinterLayer In printerInteractiveOverLay.PrinterLayers
                printerLayer.IsDrawing = True
                If Not (TypeOf printerLayer Is PagePrinterLayer) Then
                    printerLayer.Draw(pdfGeoCanvas, labelsInAllLayers)
                End If
                printerLayer.IsDrawing = False
            Next



            ’ Finish up the drawing
            pdfGeoCanvas.EndDrawing()



            ’ Dave the PDF document and launch it in the default viewer to show the user



            Dim filename As String = pdfPrintDialog.SelectedFileName
            Try
                pdfDocument.Save(filename)
                System.Diagnostics.Process.Start(filename)
            Catch ex As Exception
                MsgBox(“Fehler bei der Erstellung der PDF-Datei.” & ex.Message, MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
            End Try



        Catch ex As Exception
            MessageBox.Show(ex.Message + " " + ex.StackTrace, “Exception”)
        Finally
            If pdfDocument IsNot Nothing Then
                pdfDocument.Dispose()
            End If
        End Try
    End Sub



    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim pagePrinterLayer As PagePrinterLayer = TryCast(printerInteractiveOverLay.PrinterLayers(“PageLayer”), PagePrinterLayer)



        Dim printDocument As New PrintDocument()
        printDocument.DefaultPageSettings.Landscape = True
        If pagePrinterLayer.Orientation = PrinterOrientation.Portrait Then
            printDocument.DefaultPageSettings.Landscape = False
        End If



        printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer)



        Dim printerGeoCanvas As New PrinterGeoCanvas()
        printerGeoCanvas.DrawingArea = New Rectangle(0, 0, Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Width), Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Height))
        printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), winformsMap1.MapUnit)



        ’ Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
        ’ except for the PagePrinterLayer                
        Dim labelsInAllLayers As New Collection(Of SimpleCandidate)()
        For Each printerLayer As PrinterLayer In printerInteractiveOverLay.PrinterLayers
            printerLayer.IsDrawing = True
            If Not (TypeOf printerLayer Is PagePrinterLayer) Then
                printerLayer.Draw(printerGeoCanvas, labelsInAllLayers)
            End If
            printerLayer.IsDrawing = False
        Next



        printerGeoCanvas.EndDrawing()
    End Sub
#End Region



#Region “Map Events”
    Private Sub winformsMap1_CurrentScaleChanged(sender As Object, e As CurrentScaleChangedWinformsMapEventArgs)
        ’ Here we sync up the zoom combox to the map’s zoom level.
        Dim printerZoomLevelSet As PrinterZoomLevelSet = DirectCast(winformsMap1.ZoomLevelSet, PrinterZoomLevelSet)
        Dim currentZoomLevel As ThinkGeo.MapSuite.Core.ZoomLevel = printerZoomLevelSet.GetZoomLevel(winformsMap1.CurrentExtent, winformsMap1.Width, winformsMap1.MapUnit)
        'cboZoom.SelectedItem = printerZoomLevelSet.GetZoomPercentage(currentZoomLevel) & “%”
        currentScale.Text = CInt(winformsMap1.CurrentScale)
    End Sub



    Private Sub winformsMap1_MapClick(sender As Object, e As MapClickWinformsMapEventArgs)
        ’ Here we loop through all of the PrinterLayers to find the one the user right mouse clicked on.
        ’ Then we show the right click menu to give the user some options
        If e.MouseButton = MapMouseButton.Right Then
            Dim printerOverlay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
            For i As Integer = printerOverlay.PrinterLayers.Count - 1 To 0 Step -1
                If printerOverlay.PrinterLayers(i).[GetType]() <> GetType(PagePrinterLayer) Then
                    Dim boundingBox As RectangleShape = printerOverlay.PrinterLayers(i).GetPosition()
                    If boundingBox.Contains(e.WorldLocation) Then
                        cmRightClick.Tag = printerOverlay.PrinterLayers(i)
                        cmRightClick.Show(winformsMap1, New Point(CInt(e.ScreenX), CInt(e.ScreenY)))
                        Exit For
                    End If
                End If
            Next
        End If
    End Sub
#End Region



#Region “Pan & Zoom Buttons”



    Private Sub btnZoomIn_Click(sender As Object, e As EventArgs) Handles btnZoomIn.Click
        ’ Grab the MapPrinterLayer and adjust the extent
        Dim printerOverlay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim mapPrinterLayer As MapPrinterLayer = DirectCast(printerOverlay.PrinterLayers(“MapLayer”), MapPrinterLayer)



        ’ Here we snap the current scale to the default zoomLevelSet when we zoom in
        Dim zoomLevelSet__1 As New ZoomLevelSet()
        Dim newScale As Double = ZoomLevelSet.GetLowerZoomLevelScale(ExtentHelper.GetScale(mapPrinterLayer.MapExtent, CSng(mapPrinterLayer.GetBoundingBox().Width), mapPrinterLayer.MapUnit), zoomLevelSet__1)
        mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, CSng(mapPrinterLayer.GetBoundingBox().Width), CSng(mapPrinterLayer.GetBoundingBox().Height))



        winformsMap1.Refresh()
    End Sub



    Private Sub btnZoomOut_Click(sender As Object, e As EventArgs) Handles btnZoomOut.Click
        ’ Grab the MapPrinterLayer and adjust the extent
        Dim printerOverlay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim mapPrinterLayer As MapPrinterLayer = DirectCast(printerOverlay.PrinterLayers(“MapLayer”), MapPrinterLayer)



        ’ Here we snap the current scale to the default zoomLevelSet when we zoom out
        Dim zoomLevelSet__1 As New ZoomLevelSet()
        Dim newScale As Double = ZoomLevelSet.GetHigherZoomLevelScale(ExtentHelper.GetScale(mapPrinterLayer.MapExtent, CSng(mapPrinterLayer.GetBoundingBox().Width), mapPrinterLayer.MapUnit), zoomLevelSet__1)
        mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, CSng(mapPrinterLayer.GetBoundingBox().Width), CSng(mapPrinterLayer.GetBoundingBox().Height))



        winformsMap1.Refresh()
    End Sub



    Private Sub btnPan_Click(sender As Object, e As EventArgs) Handles btnPanUp.Click, btnPanRight.Click, btnPanLeft.Click, btnPanDown.Click
        ’ Grab the MapPrinterLayer and adjust the extent
        Dim printerOverlay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)



        Dim mapPrinterLayer As MapPrinterLayer = DirectCast(printerOverlay.PrinterLayers(“MapLayer”), MapPrinterLayer)
        Dim b As Button = sender
        Select Case b.Name
            Case “btnPanUp”
                mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Up, 30)
            Case “btnPanDown”
                mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Down, 30)
            Case “btnPanLeft”
                mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Left, 30)
            Case “btnPanRight”
                mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Right, 30)
        End Select



        winformsMap1.Refresh()
    End Sub



#End Region



#Region “Combo Boxes”






    Sub SetPageSize()
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim pagePrinterLayer As PagePrinterLayer = DirectCast(printerInteractiveOverLay.PrinterLayers(“PageLayer”), PagePrinterLayer)



        With pagePrinterLayer
            .CustomWidth = Plotframe.Item(“width”) / ScaleFactor
            .CustomHeight = Plotframe.Item(“height”) / ScaleFactor
            .PageSize = PrinterPageSize.Custom



            If .CustomWidth > .CustomHeight Then
                .Orientation = PrinterOrientation.Portrait
                'Else
                ’    .Orientation = PrinterOrientation.Portrait
            End If
        End With



        winformsMap1.Refresh()
    End Sub






#End Region



#Region “Toolbox”
    Private Sub toolStrip1_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs)
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim printerLayer As PrinterLayer = Nothing



        Dim name As String = e.ClickedItem.Text.ToLower()
        Select Case name
            Case “label”
                printerLayer = New LabelPrinterLayer()
                printerLayer.SetPosition(2, 1, 0, 0, PrintingUnit.Centimeter)
                Exit Select
            Case “image”
                printerLayer = New ImagePrinterLayer()
                Exit Select
            Case “scale line”
                MessageBox.Show(“NotImplemented”)
                Exit Select
            Case “scale bar”
                MessageBox.Show(“NotImplemented”)
                Exit Select
            Case “data grid”
                printerLayer = New DataGridPrinterLayer()
                printerLayer.SetPosition(1, 1, 0, 0, PrintingUnit.Centimeter)
                Exit Select
            Case Else
                Exit Select
        End Select



        'If printerLayer IsNot Nothing AndAlso ShowPrinterLayerProperties(printerLayer) = DialogResult.OK Then
        ’    printerInteractiveOverLay.PrinterLayers.Add(printerLayer)
        ’    winformsMap1.Refresh()
        'End If
    End Sub
#End Region



#Region “Right Click and Dialogs”
    Private Sub cmRightClick_Click(sender As Object, e As EventArgs)



    End Sub



#End Region



#Region “Helper Methods”



    Private Function GetPageBoundingBox(unit As PrintingUnit) As RectangleShape
        ’ This helper method gets the pages bounding box in the unit requested
        Dim printerInteractiveOverLay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
        Dim pagePrinterLayer As PagePrinterLayer = DirectCast(printerInteractiveOverLay.PrinterLayers(“PageLayer”), PagePrinterLayer)
        Return pagePrinterLayer.GetPosition(unit)
    End Function



    Private Function GetPdfPageSize(pageSize1 As PrinterPageSize) As PageSize
        Dim pdfPageSize As PageSize = PageSize.A4
        Select Case pageSize1
            Case PrinterPageSize.AnsiA
                pdfPageSize = PageSize.Letter
                Exit Select
            Case PrinterPageSize.AnsiB
                pdfPageSize = PageSize.Ledger
                Exit Select
            Case PrinterPageSize.AnsiC
                pdfPageSize = PageSize.A2
                Exit Select
            Case PrinterPageSize.AnsiD
                pdfPageSize = PageSize.A1
                Exit Select
            Case PrinterPageSize.AnsiE
                pdfPageSize = PageSize.A0
                Exit Select
            Case PrinterPageSize.[Custom]
                pdfPageSize = PageSize.Undefined



            Case Else
                Throw New NotSupportedException()
        End Select
        Return pdfPageSize
    End Function



    Private Function GetPrintPreviewPaperSize(pagePrinterLayer As PagePrinterLayer) As PaperSize
        Dim printPreviewPaperSize As New PaperSize(“AnsiA”, 850, 1100)
        Select Case pagePrinterLayer.PageSize
            Case PrinterPageSize.AnsiA
                printPreviewPaperSize = New PaperSize(“AnsiA”, 850, 1100)
                Exit Select
            Case PrinterPageSize.AnsiB
                printPreviewPaperSize = New PaperSize(“AnsiB”, 1100, 1700)
                Exit Select
            Case PrinterPageSize.AnsiC
                printPreviewPaperSize = New PaperSize(“AnsiC”, 1700, 2200)
                Exit Select
            Case PrinterPageSize.AnsiD
                printPreviewPaperSize = New PaperSize(“AnsiD”, 2200, 3400)
                Exit Select
            Case PrinterPageSize.AnsiE
                printPreviewPaperSize = New PaperSize(“AnsiE”, 3400, 4400)
                Exit Select
            Case PrinterPageSize.[Custom]
                printPreviewPaperSize = New PaperSize(“Custom Size”, CInt(pagePrinterLayer.CustomWidth), CInt(pagePrinterLayer.CustomHeight))
                Exit Select
            Case Else
                Exit Select
        End Select



        Return printPreviewPaperSize
    End Function



#End Region



    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            Dim printerOverlay As PrinterInteractiveOverLay = DirectCast(winformsMap1.InteractiveOverlays(“PrintPreviewOverlay”), PrinterInteractiveOverLay)
            Dim mapPrinterLayer As MapPrinterLayer = DirectCast(printerOverlay.PrinterLayers(“MapLayer”), MapPrinterLayer)



            ’ Here we snap the current scale to the default zoomLevelSet when we zoom in
            Dim newScale As Double = cbScale.Text
            mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, CSng(mapPrinterLayer.GetBoundingBox().Width), CSng(mapPrinterLayer.GetBoundingBox().Height))



            winformsMap1.Refresh()
        Catch ex As Exception
        End Try
    End Sub



    Public Sub New()



        ’ Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()



        ’ Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        MyParent = My.Forms.Host
       
        MyParent.SetRibbon(PlotRibbon)
    End Sub



End Class




Hi Hartwig, 
  
 What a long source code! Thanks for sharing. Unfortunately, I found there are some something interferes me, so that I cannot get the point nor make it work. Could you try to upload an executable sample project or modify our existing sample (wiki.thinkgeo.com/mediawiki/images/f/fb/ServicesEditionSample_PrintPreview_CS_WPF_111115.zip) to show your issue? Also, it is good to provide us an exported XPS file, that will be a great help. 
  
 Thanks and looking forward your feedback, 
 Howard 


Hi Howard,

I will extract the code and setup a smaller example…

But it’s a lot of work…



Get back to you asap.



Regards

Hardy

Hi Hartwig, 
  
 Thanks for your help on that, any update please let us know. 
  
 Regards, 
  
 Don