High quality print with Flex

1195
13
09-28-2010 05:09 AM
erictruchon
New Contributor
Hello

Our firm has developed an application in Flex and we publish the assessment roll for many municipalities.

Prior to Flex, we were using ArcIMS.

Some of our clients find that our print tool in Flex has lost quality from ArcIMS and I agree with them.

I watched the new version of the API in Flex (version 2.1) and I have not seen an example of printing tool in high quality. (just a snap shot)

I tried to find an example and I have not found. But I read that it would be possible to do it.

Where could I find a solution?

Thank you in advance

Greetings
Tags (2)
0 Kudos
13 Replies
erictruchon
New Contributor
Thank you very much hawkeye81x for information, I understand better now

Last question: Does it requires ArcGIS is installed on the server?

Thanks again
0 Kudos
EokNgo
by
New Contributor III
Thank you very much hawkeye81x for information, I understand better now

Last question: Does it requires ArcGIS is installed on the server?

Thanks again


I assume by ArcGIS you mean ArcGIS Desktop, you shouldn't need it if you're printing just the map.
0 Kudos
erictruchon
New Contributor
Voilà

My solution with AlivePDF to produce good quality printing


private function generatePDF():void

{
              
              
  var layer:ArcGISDynamicMapServiceLayer = map.getLayer(map.layerIds[0]) as ArcGISDynamicMapServiceLayer;
  var imageParams:ImageParameters = new ImageParameters();
  var mapImage:MapImage = new MapImage();
      
  var extent_map:Extent = map.extent
  var x1:Number = extent_map.xmin
  var x2:Number = extent_map.xmax
  var y1:Number = extent_map.ymin
  var y2:Number = extent_map.ymax
      
  imageParams.format = "jpg"; //png
  imageParams.width = 2048;   // max default width arcgis server
       
  imageParams.height = Math.round(2048*(y2-y1)/(x2-x1));
      
  var extent:Extent = new Extent(x1, y1, x2, y2);
  var sr:SpatialReference = new SpatialReference(2145)
  imageParams.imageSpatialReference = sr;
  imageParams.extent = extent;
  imageParams.dpi = 150;

  layer.exportMapImage(imageParams,new AsyncResponder(onResult, onFault))
               
     function onResult(mi:MapImage, token:Object = null):void               
     {  
     try
     {
mapImage = mi;
var my_url:String = mapImage.href;
my_url = my_url.replace("server_name", "server_url")
var urlLoader:URLLoader = new URLLoader();  
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, loaderComplete);
        urlLoader.load(new URLRequest(my_url));
                 
      }
     catch (error:Error)
      {
Alert.show(info.toString(), "Export Problem"); 
      }
      }
     
    
      function onFault(info:Object, token:Object = null) : void
         {                   
     Alert.show(info.toString(), "Export Problem");   
  }
           
}
           
          
private function loaderComplete(event:Event):void
{
      
   switch  (my_page.text)
   {
case "8 1/2 x 11":
{
   var myPDF : PDF = new PDF (Orientation.LANDSCAPE, Unit.MM, Size.LETTER);
   myPDF.setDisplayMode(Display.FULL_PAGE,Layout.SINGLE_PAGE );
   myPDF.addPage();
     
   var rs:Resize= new Resize(Mode.FIT_TO_PAGE,Position.LEFT);
   myPDF.addImageStream(ByteArray(event.target.data), ColorSpace.DEVICE_RGB, rs  );
    
   myPDF.beginFill ( new RGBColor (0xFFFFFF));
   myPDF.lineStyle ( new RGBColor ( 0xFFFFFF ), 1, .1, 1, CapsStyle.SQUARE, JointStyle.MITER );
   myPDF.drawRect ( new Rectangle (221, 11, 60, 193 ));
   myPDF.endFill ( );
             
   myPDF.addImageStream( new logo as ByteArray, ColorSpace.DEVICE_RGB, null,224, 15, 25, 11 );
   myPDF.addImageStream( new legende as ByteArray, ColorSpace.DEVICE_RGB, null,216, 45, 37, 95 );

   ...
        
   break;
}
    
    
    
case "11 x 17":
{
    var myPDF : PDF = new PDF (Orientation.LANDSCAPE, Unit.MM, Size.TABLOID);
    myPDF.setDisplayMode(Display.FULL_PAGE,Layout.SINGLE_PAGE );
    myPDF.addPage();
     
    var rs:Resize= new Resize(Mode.FIT_TO_PAGE,Position.LEFT);
    myPDF.addImageStream(ByteArray(event.target.data), ColorSpace.DEVICE_RGB, rs  );
        
    myPDF.beginFill ( new RGBColor (0xFFFFFF));
    myPDF.lineStyle ( new RGBColor ( 0xFFFFFF ), 1, .1, 1, CapsStyle.SQUARE, JointStyle.MITER );
           myPDF.drawRect ( new Rectangle (365, 11, 80, 257 ));
           myPDF.endFill ( );
        
    myPDF.addImageStream( new logo as ByteArray, ColorSpace.DEVICE_RGB, null,370, 15, 30, 13 );
    myPDF.addImageStream( new legende as ByteArray, ColorSpace.DEVICE_RGB, null,365, 65, 40, 100 );

           ...

    break;
}
   }


myPDF.save(Method.REMOTE,"http://my_server_url/php/create.php",Download.INLINE,"map.pdf")

}


/****************************************************************************
/*php file create.php


<?php


$method = $_GET['method'];

$name = $_GET['name'];



if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
   

   $pdf = $GLOBALS["HTTP_RAW_POST_DATA"];
   
       
   header('Content-Type: application/pdf');
   
   header('Content-Length: '.strlen($pdf));
   
   header('Content-disposition:'.$method.'; filename="'.$name.'"');
   
   echo $pdf;
   

  
} else echo 'An error occured.';

?>

?>
0 Kudos
TomSchuller
Occasional Contributor III
This could also be an alternative if you are running on an ArcGIS server 10 (v10 is a requirement):

  http://www.arcgis.com/home/item.html?id=6809086326ea4c76bf026a32bb9dd698

It's based on a SOE (ServerObjectExtension) which runs on the Java and .Net version of ArcGISServer.
The communication is based on REST, so any client/platform can use it.

There is a Flex widget provided with.

Tom
0 Kudos