ArcGIS Server 9.2建立的web Application实现打印的一篇文章。

Description:


This sample demonstrates printing from a Web ADF application. The sample is a custom task that prints the contents of a Map control by merging its resources into a single image. It also enables the user to choose results from a TaskResults control to print below the map. A user-customizable title is displayed at the head of the page. The page is opened as a new browser window from the current window.
The sample task may be used as-is or may be customized. See directions below for both options.
In addition to demonstrating how a task works and the use of Web ADF features such as the use of CallbackResults to handle client callbacks, the code for the task illustrates:
  • Export of map resources in the Map to bitmaps, and the use of GDI+ in ASP.NET to merge the bitmaps into a single image for printing.
  • Printing at specific scale, size and resolution in the browser.
  • Dynamic detection of changes in the TaskResults in order to update the list of available tasks for printing.
  • Output from a task result node to a GridView for table-formatted view.
  • Streaming of the print image to the client from server memory.

Using the Print Task


To use this sample as-is, without compiling it or opening it in Visual Studio, use the steps below. For more details, see the Readme.doc file included with the downloaded zip file.
  1. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. Extract either the Common_PrintTask_CSharp.zip or Common_PrintTask_VBNet.zip file to a location of your choice. An example would be to C:\ArcGIS\CustomTasks. You should have a Common_PrintTask_CSharp or Common_PrintTask_VBNet folder after extracting the files.
  3. Register the PrintTask_<language>.dll in the Global Assembly Cache (GAC). The <language> variable may be either CSharp or VBNet. Open two Windows Explorer windows, one to the bin\Release subfolder of the sample (e.g., C:\ArcGIS\CustomTasks\Common_PrintTask_CSharp\PrintTask_CSharp\bin\Release), and the other to the C:\Windows\Assembly folder. Drag the PrintTask_<language>.dll file into the C:\Windows\Assembly folder. Verify that PrintTask_<language> is now in the list.
  4. If desired, add the task to the Visual Studio toolbox. Open Visual Studio 2005 to any Web page, right-click on the location in the toolbox where you want the task, and use Choose Items to browse to the PrintTask_<language>.dll. Click Open, then OK. The tool should now appear every time you open a Web page in Visual Studio. Now the task may be added to any Web ADF application by dragging the task onto the page (into a TaskManager if available).
  5. If desired, add the task into Manager. Open the C:\Inetpub\wwwroot\ArcGIS\Manager\Applications\App_Data\Tasks.xml file in Visual Studio, Notepad or other XML or text editor. Just before the closing </Tasks> tag, insert the following (all on one line):

    For the CSharp version:
    <Task Name="PrintTask_CSharp"
    
        DisplayName="Print Task CSharp"
    
        Type="PrintTask_CSharp.PrintTask_CSharp, PrintTask_CSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=2a7e7966c16048d7"
    
        TagPrefix="printTaskCS" />


    For the VBNet version:
    <Task Name="PrintTask_VBNet"
    
        DisplayName="Print Task VBNet"
    
        Type="PrintTask_VBNet.PrintTask_VBNet, PrintTask_VBNet,Version=1.1.0.0, Culture=neutral, PublicKeyToken=2a7e7966c16048d7"
    
        TagPrefix="printTaskVB" />


    Then restart IIS using Control Panel-Administrative Tools-Services. Now the task should appear in the available tasks list when creating or editing a Web applications. You can add the task to the application. Remember to click Configure so that the task will actually be added into the application.
Products:
Server: C#, VB.NET

 

 

Platforms: Windows

 

Minimum ArcGIS Release: 9.2

How to use:
  1. Design Time:
    1. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
    2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit\SamplesNet\Server\Web_Applications and unzip Common_PrintTaskCSharp.zip or Common_PrintTaskVBNet.zip (if available) to a location of your choice. You should see either a CSharp or VBNet folder appear where you unzipped the files.
    3. In Windows Explorer, open the directory referencing the language of your choice: CSharp or VBNet. Copy the folder, Common_PrintTask_<language>, to c:\inetpub\wwwroot. The <language> variable may be either CSharp or VBNet.
    4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services
    5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site.
    6. Open the Common_PrintTask_<language> folder, right-click the PrintTaskWebApp_<language> folder and click Properties.
    7. On the Directory tab, click the Create button in the Application Settings section of this panel. Click OK to dismiss the Properties dialog.
    8. Launch Microsoft Visual Studio 2005 and open the Common_PrintTask_<language> solution (for example, Common_PrintTask_CSharp.sln) located in c:\inetpub\wwwroot\Common_PrintTask_<language>.
    9. In the Solution Explorer, right-click the PrintTaskWebApp_<language> project and select 'Set as StartUp Project'. Also, right-click Default.aspx and select 'Set As Start Page'.
    10. Save the solution.
    11. Click the "Debug" drop-down menu and choose "Start". The custom task class library should build successfully and be added to the GAC using build events in the task project. The Default.aspx should start and display a menu item to initialize the custom task and the dialog for the custom task control.
    12. To add the custom task to the Visual Studio toolbox:
      1. Right-click on the toolbar and select Add Tab.  Enter a name for the new tab, for example "Custom Task Controls".
      2. Right-click on the new tab and select "Choose Items...".
      3. On the Choose Items dialog, click the Browse button and navigate to the location of the PrintTask_<language>.dll and click the Open button.  Two new controls will be added to and selected in the Choose Items dialog.  Select and check the box next to the "PrintTask_<language>" item.  Click OK to exit the dialog.
      4. The new tab should contain the custom task control.
    13. You may choose to distribute this custom task for use in the Manager application. To add this custom task, do the following:
      1. Confirm that the assembly is signed. By default, the task project includes a key it uses to sign the class library. In Visual Studio, right-click on the class library project and select Properties in the context menu. Click the Signing tab and confirm the "Sign the assembly" check box is checked. Optionally, you can change this by generating your own key using the sn.exe utility included with the .NET SDK. To do this, open a Visual Studio 2005 Command Prompt and enter:
        sn -k MyKeyPair.snk
        
                    
      2. Confirm that the assembly has been added to the GAC. By default, the task project uses build events to register the assembly in the GAC. Optionally, you can use the gacutil.exe utility included with the .NET SDK to add the assembly to the GAC. To do this, open a Visual Studio 2005 Command Prompt and enter (using the CSharp version as an example):
        gacutil -i PrintTask_CSharp.dll
        
                    
      3. Add the custom task details to the Manager Tasks.xml file. In the App_Data folder for the Manager Web application (e.g. C:\Inetpub\wwwroot\ArcGIS\Manager\Applications\App_Data) open the Tasks.xml file in a text editor. Add the following line within the <Tasks> tags (using the CSharp version as an example):
        <Task Name="PrintTask_CSharp"
        
                    DisplayName="Print Task CSharp"
        
                    Type="PrintTask_CSharp.PrintTask_CSharp, PrintTask_CSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=2a7e7966c16048d7"
        
                    TagPrefix="customTask" />
        
                    
        Confirm the content of this entry, namely the version, and public key token. In a Visual Studio 2005 Command Prompt and enter (using the CSharp version as an example):
        gacutil -l PrintTask_CSharp
        
                    
      4. Restart IIS. Manager should recognize the new task and make it available in the Tasks dialog during new Web application creation. In a Visual Studio 2005 Command Prompt and enter:
        iisreset
        
                    
  2. Run Time:
    1. Run in debug mode to open the Web application as above.
    2. Zoom or pan the map to an area to be printed (use the Ctrl/Shift keys with the mouse to zoom in/out).
    3. If you added a query task at design time, use it to find a set of features.
    4. Open the Print task if necessary from the task menu. In the task dialog, set the print options such as size and task results to print, if any are available.
    5. Click Print to display the print page. Note that any popup blockers may need to be disabled or set to allow popups for this site. Print the page to your local printer if desired.

Download the C# files
Common_PrintTask_CSharp.sln The solution file. References two projects: a class library and web site.
PrintTask_CSharp.csproj Class library project file for print task control.
Default.aspx User interface for the Web application.
Common_PrintTask_CSharp/PrintTaskWebApp_CSharp/Default.aspx.cs The code behind the user interface.
Common_PrintTask_CSharp/PrintTask_CSharp/PrintTask_CSharp.cs Custom task implementation code.
Common_PrintTask_CSharp/PrintTask_CSharp/PagePrinter.cs Creates the output for the print page.
Common_PrintTask_CSharp/PrintTask_CSharp/MapPrinter.cs Called by PagePrinter to create the output for the map.
Common_PrintTask_CSharp/PrintTask_CSharp/ScaleBarPrinter.cs Creates the output version of the scalebar.
Common_PrintTask_CSharp/PrintTask_CSharp/Utilities.cs Utility methods for the custom task.
Common_PrintTask_CSharp/PrintTask_CSharp/PrintTaskWebConfigurator_CSharp.cs Class for configuring the custom task in Manager.
Common_PrintTask_CSharp/PrintTask_CSharp/Properties/AssemblyInfo.cs Assembly specific information used when compiling the assembly. Note the custom tagprefix.
Common_PrintTask_CSharp/PrintTask_CSharp/Designer/MapControlsEditor.cs Design-time control used to display a list of Map controls to buddy to the Print Task.

Download the files for all languages

你可能感兴趣的:(application)