About Printing in Pre-released ArcGIS 10

558
6
06-04-2010 06:18 AM
DeminHu
New Contributor
Hi,

With pre-released ArcGIS Server 10, now, it is really easy to create a customized printing page without using IsolatedStorage or seding something to the server,  changing paper size would not distort the map.

But I still could not  find a same easy way to create a Printing Preview Page.  I also   hope I could create a printing preview page like google map, in the preview page, the user still could  zoom or pan the map,  I don't think using querystring is a good idea in my situation, if there is possible way to copy the main map ( current status:  different graphics,  layers on  or off) to the preview map which I still can  zoom and pan.

Thanks for help.
0 Kudos
6 Replies
dotMorten_esri
Esri Notable Contributor
The approach I've seen used is:

  • Grab a snapshot of the map using WriteableBitmap.

  • Remove the map and replace it with the snapshot image.

  • Popup a preview window on top, and insert the map in there.

  • When you click print, you simply print this preview window.

  • When you close the preview, move the map back and remove the temporary image snapshot.

It's a little tricky, but it gives a really good experience, and allows the user to adjust the map based on the paper size in the preview.
0 Kudos
DeminHu
New Contributor
Hi,

Thank you  so much, your suggestion works. in case somebody  may need, I put some  simple code here, PrintMap  is print template (userControl)I created:

private void PrintBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
               
                PrintDocument printDoc = new PrintDocument();
                printDoc.PrintPage +=new EventHandler<PrintPageEventArgs>(printDoc_PrintPage);
                printDoc.Print("deminhu");
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
//---------------------------------------
              void printDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            PrintMap printMap = new PrintMap();
            printMap.PrintTitle.Text = "Printing test !";
            WriteableBitmap bitmap = new WriteableBitmap(MyMap, new TranslateTransform());
            Image image = new Image();          
            image.Source = bitmap;           
            printMap.PrintMap.Child = image;

            e.PageVisual = printMap;
        }

Thanks again.
0 Kudos
CraigPerreault
New Contributor II
Would you share your PrintMap userControl ?  Thank you??
0 Kudos
DeminHu
New Contributor
Yes, PrintMap  is just a userControl,  the following is the simple one for test:

<UserControl x:Class="IrvingMap.PrintMap"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:esri="http://schemas.esri.com/arcgis/client/2009"       
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
   
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,10,10" >
            <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="#36648B"  CornerRadius="6" BorderThickness="2" Background="White" Height="50" >
                <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="2" TextWrapping="Wrap" Name="PrintTitle" FontSize="24" TextAlignment="Center" FontFamily="Lucida Sans Unicode" FontStyle="Italic" >
                </TextBlock>
            </Border>
            <Border x:Name="PrintMap"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="#36648B"  CornerRadius="6" Margin="0,10,0,0" BorderThickness="2" Background="White" Height="Auto" >               
            </Border>
        </StackPanel>
    </Grid>
</UserControl>

if you only want to  print simple  map, you don't need the template, you can do the following:

               
                PrintDocument doc = new PrintDocument();
                doc.PrintPage += (s, args) =>
                    {
                        args.PageVisual = this.MyMap;  // any control name which you want to print                     
                    };
                doc.Print("Printing Test");
              
         
I am still  working on  to see if possible the printing preview map could be a snapshot of the main map , and the user could zoom, pan , like google map printing, but I could not use querystring to pass params, my situation is  a little complicated.
0 Kudos
MatthewCarey
Occasional Contributor
Hi,

I know this thread is old, but I've found that this code works pretty well for me in the full ArcGIS 10 in terms of printing a map.

However, I can't get it to actually show the preview window at all, even though printing itself works fine. Even when I bring in the PrintMap user control to display on my main page, it remains blank.

I'm not the most knowledgeable programmer, so can you please tell me if I'm missing something elementary?

Thanks!
0 Kudos
DeeptiVB
New Contributor II
Thanks Demin Hu for posting your code, works for my project.
0 Kudos