Select to view content in your preferred language

API 2.0 and Printing to scale

1691
16
08-01-2010 08:40 PM
BrianBorg
Emerging Contributor
I am using the API 2.0 and I want to print maps using pre-defined scales (e.g. 1:1000, 1:2500, etc.) on different papersizes up to A0. I also want to use print templates. I think that I need to use some sort of services (e.g. ArcObjects) to generate such maps. Are there any examples around? or can someone point me to the right direction please?

I have read that there is something called layout SOE. What is it? How to use it?
0 Kudos
16 Replies
DominiqueBroux
Esri Frequent Contributor
Strange.

The code to enable the print command is quite simple:
 
private bool CanPrint(object param)
{
return IsPrinting == false && Map != null;
}

So very likely the Map property is null, but I can't figure out why.

If you want, send me your code by mail dbroux@esri.com, I'll take a look.
0 Kudos
KevinSesock
Emerging Contributor
Strange. 
  
The code to enable the print command is quite simple: 
 
private bool CanPrint(object param)
{
return IsPrinting == false && Map != null;
}

So very likely the Map property is null, but I can't figure out why. 
  
If you want, send me your code by mail   dbroux@esri.com, I'll take a look.


Dominique: My printing control has started working. The print preview isn't working, but I may have an idea of what's wrong. I'll keep working on it and let you know if I need additional help. Thanks again!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I just added a WPF version of the map printing sample.

With this version, an intermediary XPS document is created and can be previewed before printing.
Test it live.
0 Kudos
DanielWalton
Frequent Contributor
Dominique,

Thanks again for your excellent work on the printing sample. I have been using the direct printing sample a lot. After your most recent changes, it appears that the direct printing sample is broken. I have a feeling it's related to the code you've added to free the cloned map layers, but I don't know for sure.

-Dan
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Dan,

You are right, there is a bug. To fix it, line 424 of MapPrinter.cs, move the initialization of _oldMap inside the test Map!=null:
if (Map != null)
{
  _oldMap = Map;
  Map = null;
}
ResetDefineExtent();


I will update the sample ASAP (I guess I should even revisit this badly designed part of the sample)
0 Kudos
DanielWalton
Frequent Contributor
Thanks Dominique. That works on my end. I thought I would share a couple of snippets I added/modded to MapPrinter.theme.xaml:

[HTML]<ControlTemplate TargetType="local:MapPrinter">
...
<!-- Body-->
<Grid Grid.Row="1">
<!-- Map-->
<esri:Map x:Name="PrintMap" ...
</esri:Map>

<!-- Scale Bar -->
<esri:ScaleBar Map="{Binding ElementName=PrintMap}" HorizontalAlignment="Left" VerticalAlignment="Bottom"
        Margin="20" TextColor="Black" RenderTransformOrigin="0,1">
    <esri:ScaleBar.RenderTransform>
        <RotateTransform Angle="{Binding Rotation, ElementName=PrintMap}" />
    </esri:ScaleBar.RenderTransform>
</esri:ScaleBar>

<!-- North Arrow -->
<Grid Width="50" Height="50" Margin="20"
                HorizontalAlignment="Right" VerticalAlignment="Top"
                RenderTransformOrigin=".5,.5" Opacity="0.7">
    <Grid.RenderTransform>
        <RotateTransform Angle="{Binding Rotation, ElementName=PrintMap}" />
    </Grid.RenderTransform>
    <Path Data="M0.5,0 L0,1 L0.5,0.8 L1,1 z" Fill="White" Stretch="Fill" Stroke="Black" UseLayoutRounding="False" />
    <TextBlock Text="N" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" FontSize="22" RenderTransformOrigin="0.5,0.5" >
        <TextBlock.RenderTransform>
            <CompositeTransform TranslateY="4"/>
        </TextBlock.RenderTransform>
    </TextBlock>
</Grid>
...
</Grid>
...
</ControlTemplate>[/HTML]
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Thanks Dan,

A North Arrow is a good idea  (furthermore well oriented:))
I will integrate your enhancement in the next version of the sample.
0 Kudos