[mapguide-users] PDF Report with image from mapguide

Jamo adam.jamison at portbris.com.au
Thu Sep 30 18:49:59 EDT 2010


I'm attempting to automate some PDF report creation from mapguide.....
basically I've setup a map in maestro and styled it up how I'd like it to be
printed :) works a charm

The following creates the pdf but I have to call another page each time to
produce the image....
I'd like to somehow use the same mapguide session to produce the image ( I
belive this would be a lot quicker .... the process takes nearly 10 minutes
to produce a 40 page pdf)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using OSGeo.MapGuide;
using Root.Reports;
using System;
using System.Net;
using System.Text;
using System.IO;


public partial class markup_report_WaterSet : System.Web.UI.Page
{
    String sessionID;
    String mapName;
    protected void Page_Load(object sender, EventArgs e)
    {

       
MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "../webconfig.ini");
        MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
        MgSite site = new MgSite();
        //connect to site
        site.Open(userInfo);
        String sessionId = site.CreateSession();
        userInfo.SetMgSessionId(sessionId);
        MgSiteConnection siteConnection = new MgSiteConnection();
        //open site connection
        siteConnection.Open(userInfo);
        MgResourceService ResourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
        MgFeatureService FeatureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
        MgRenderingService RenderService =
siteConnection.CreateService(MgServiceType.RenderingService) as
MgRenderingService;
        MgResourceIdentifier mgResourceID = new
MgResourceIdentifier("Library://portbris/data/SQLvmsql02Portbris.FeatureSource");
        //get portbris map information
        


        Response.ContentType = "application/pdf";

        Response.AddHeader("content-disposition", "attachment;
filename=WaterSet_" + DateTime.Now.ToShortDateString().ToString() + ".pdf");
        //pdfdoc.formatter.Create(pdfdoc, Response.OutputStream);
        PdfFormatter pf = new PdfFormatter();
        pf.pageLayout = PageLayout.OneColumn;
        
        Report report = new Report(pf);
        
        FontDef fd = new FontDef(report, "Helvetica");
        FontProp h1 = new FontPropMM(fd, 5);
        FontProp h2 = new FontPropMM(fd, 5);
        PenProp pen1 = new PenPropMM(report, 1);
        PenProp pen2 = new PenPropMM(report, 0.35);
        //Root.Report

        MgFeatureQueryOptions opts = new MgFeatureQueryOptions();
        MgStringCollection str = new MgStringCollection();
        str.Add("gridRef");

        opts.SetOrderingFilter(str, MgOrderingOption.Descending);

        MgFeatureReader prints2500 =
FeatureService.SelectFeatures(mgResourceID,
"gisgeom:watPrintCentroids",opts);

        while (prints2500.ReadNext())
        {
            Root.Reports.Page page = new Root.Reports.Page(report);
            page.rHeightMM = 297;
            page.rWidthMM = 420;

            MgAgfReaderWriter agf = new MgAgfReaderWriter();

            MgPoint myPoint = agf.Read(prints2500.GetGeometry("geomcol1"))
as MgPoint;

            WebClient wc = new WebClient();
            byte[] originalData =
wc.DownloadData("http://vmapp04/mapguide2010/portbris/makeImage/waterSupplyImage.aspx?X="
+ myPoint.Centroid.Coordinate.X + "&Y=" + myPoint.Centroid.Coordinate.Y);
            MemoryStream stream = new MemoryStream(originalData);

            page.AddMM(5, 292, new RepImageMM(stream, Double.NaN, 287));

            page.AddCenteredMM(292, new RepRectMM(pen1, 410, 287));
            page.AddMM(355, 292, new RepRectMM(pen2, 60, 287));
        }
        prints2500.Close();

        report.formatter.Create(report, Response.OutputStream);
        Response.End();
    }
}



The page reffered to in this part of code simply return an image at the
requested coordinate... 

WebClient wc = new WebClient();
            byte[] originalData =
wc.DownloadData("http://vmapp04/mapguide2010/portbris/makeImage/waterSupplyImage.aspx?X="
+ myPoint.Centroid.Coordinate.X + "&Y=" + myPoint.Centroid.Coordinate.Y);
            MemoryStream stream = new MemoryStream(originalData);


is it possible to get renderMap to output a stream? the pdf create image
class only accpets a stream .... how to convert MgByteReader to a
memoryStream is the question i guess....
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/PDF-Report-with-image-from-mapguide-tp5589714p5589714.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list