Print a map without using the layout control

Sep 15, 2011 at 12:30 AM

Hi all,

Is there a way to print a map without using the layout control ?

Evemar

Developer
Sep 15, 2011 at 1:16 PM

You can experiment with the Map.Print methods:

       /// <summary>
        /// Instead of using the usual buffers, this bypasses any buffering and instructs the layers
        /// to draw directly to the specified target rectangle on the graphics object.  This is useful
        /// for doing vector drawing on much larger pages.  The result will be centered in the
        /// specified target rectangle bounds.
        /// </summary>
        /// <param name="device">The graphics device to print to</param>
        /// <param name="targetRectangle">the rectangle where the map content should be drawn.</param>
        public void Print(Graphics device, Rectangle targetRectangle)
        {
            MapFrame.Print(device, targetRectangle);
        }

        /// <summary>
        /// Instead of using the usual buffers, this bypasses any buffering and instructs the layers
        /// to draw directly to the specified target rectangle on the graphics object.  This is useful
        /// for doing vector drawing on much larger pages.  The result will be centered in the
        /// specified target rectangle bounds.
        /// </summary>
        /// <param name="device">The graphics device to print to</param>
        /// <param name="targetRectangle">the rectangle where the map content should be drawn.</param>
        /// <param name="targetEnvelope">the extents to print in the target rectangle</param>
        public void Print(Graphics device, Rectangle targetRectangle, Extent targetEnvelope)
        {
            MapFrame.Print(device, targetRectangle, targetEnvelope);
        }

Sep 15, 2011 at 5:57 PM

Hi Kellison,

Thanks for help.

I already have tried those methods and a sort of things in many ways trying to make it works - without success (some code below).

It doesn't send anything to the printer... I can´t find out what I'm doing wrong.

            Bitmap b = new Bitmap(map1.MapFrame.ImageRectangle.Width, map1.MapFrame.ImageRectangle.Height);
            //map1.BackColor = Color.Transparent;
            map1.DrawToBitmap(b, map1.ClientRectangle);
            //Image img = bitmap;
      
           
            //map1.Print(bitmap);
           
            Rectangle r = new Rectangle(0, 0, map1.Width, map1.Height);

           // Bitmap b = new Bitmap(map1.Width, map1.Height);
            Graphics g = Graphics.FromImage(b);

            map1.Print(g, r);

Developer
Sep 15, 2011 at 6:22 PM

The Graphics object you send to Print needs to be the printer device.  Your code above would be printing to your bitmap.