I am looking at your web mapping tools and noticed in the Web AJAX edition you support printing to a PDF, is this feature available in the silverlight edition as well? If not, is it on the roadmap?
PDF Extension
Lyle,
The PDF Extension supports all the server side rendering, so I think it also can be used in SilverlightEdition, but for layers added into ServerOverlay. Please follow the steps below:
- Instance all the layers shown in Server side using SilverlightConnector.
BackgroundLayer backgroundLayer = new BackgroundLayer(new GeoSolidBrush(GeoColor.FromArgb(255, 156, 187, 216)));
ServerLayerOverlay layerOverlay = new ServerLayerOverlay("NativeServer");
layerOverlay.Layers.Add(backgroundLayer);
SilverlightMapConnector1.ServerLayerOverlays.Add(layerOverlay);
- Add a server side button to call the ToPdf method.
- Loop all the layers in ServerOverlay to print to PDF document.
private void btnToPdf_Click(object sender, EventArgs e)
{
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
if (pageOrientationLandscape.Checked == true)
{
page.Orientation = PageOrientation.Landscape;
}
PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();
// This allows you to control the area in which you want the
// map to draw in.
pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);
Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();
foreach (Layer layer in layerOverlay.Layers)
{
pdfGeoCanvas.BeginDrawing(page, ExtentHelper.GetDrawingExtent(mapEngine.CurrentExtent, pdfGeoCanvas.DrawingArea.Width,pdfGeoCanvas.DrawingArea.Height), GeographyUnit.DecimalDegree);
layer.Open();
layer.Draw(pdfGeoCanvas, labelsInLayers);
layer.Close();
pdfGeoCanvas.EndDrawing();
}
string filename = "MapSuite PDF Map.pdf";
document.Save(filename);
Process.Start(filename);
}
If you want the ToPdf button as a Silverlight button, please use wcf instead for printing.
Thanks,
Johnny
Johnny, can you provide a working sample for printing pdf using Silverligth button and WCF? Thanks!
Missing WCF files. And it seems that you are not going to print within WCF service.
I am not interested in printing PDF itself. I am interested in "through WCF" part.
JingWei,
The logic is very similar to use WCF and Httphandler. Instead of using Response.write, you can define a printToPdf method with a byte array return value in WCF, use webclient to request the WCF service, and then the result can be available in callback method. Please refer to the sample code.thinkgeo.com/projects/show/getdataserverwcf we made before about how to use WCF in SilverlightEdition.
Any question please let us knows.
Thanks,
Johnny
Hope the sample can give you some helps.
Thanks.