That is very useful ram282, I succeeded to do what you did in java using iText, but the quality of the resulting image is not very good.
I saw in your code that you generated a view of the map as a PNG file, mapguide allows you to generate a view of the map as a DWF file, that act's as a SVG file, the quality is just perfect. I have found that Autodesk is giving for free the DWF Toolkit, and we ca use that two read the contents of a DWF file and write it in a PDF file, and the resulting PDF file will contain the map as a SVG rather than a PNG picture. I am working on an application that will do that, but I do not know if our clients will allow me to post the code after I finish it. :( ________________________________ From: ram282 <[email protected]> To: [email protected] Sent: Fri, July 9, 2010 7:18:25 AM Subject: [mapguide-users] Re: Generate a pdf view of the current map I had successfully generated pdf in this way.... In this, I am temporarily saving the image files and after generating the pdf, I am deleting them. Yo should require the php file called fpdf.php, through which u are going to generate the pdf. And I also changed some configuration settings in the php.ini (LOCATED AT C:\Program Files\OSGeo\MapGuide\Web\Php\php.ini) remove the semicolon at the start of the lines ;extension=php_curl.dll ;extension=php_gd2.dll in the php.ini file.... Here is the code.. <?php $fusionMGpath = '../../layers/MapGuide/php/'; include $fusionMGpath . 'Common.php'; require($fusionMGpath . 'fpdf.php'); $locale = "en"; $mapName = ""; $sessionId = ""; $isTitle = ""; $isLegend = ""; $isArrow = ""; $title = ""; $scale = ""; $centerX = ""; $centerY = ""; $dpi = ""; $Server= ""; $clAgent = "Fusion%20Viewer"; $tempMapImgPath=""; GetRequestParameters(); $agent = GetRootVirtualFolder() . "/mapagent/mapagent.fcgi"; $imgRequest = $Server . $agent . "?OPERATION=GETMAPIMAGE&VERSION=1.0.0&FORMAT=PNG&LOCALE=en&MAPNAME=" . $mapName . "&SESSION=" . $sessionId . "&SETDISPLAYWIDTH=480&SETDISPLAYHEIGHT=580&SETDISPLAYDPI=" . $dpi . "&SETVIEWSCALE=" . $scale . "&SETVIEWCENTERX=" . $centerX . "&SETVIEWCENTERY=" . $centerY . "&SEQ=0.2873515576651681&CLIENTAGENT=" . $clAgent; $LegendImgRequest = $Server . $agent . "?OPERATION=GETMAPLEGENDIMAGE&VERSION=1.0.0&MAPNAME=" . $mapName . "&SESSION=" . $sessionId . "&CLIENTAGENT=" . $clAgent . "&WIDTH=180&HEIGHT=580&FORMAT=PNG"; // declaring the abcissa and ordinates of the images for the pdf. $LegendA=10; $LegendO=20; $MapA=45; $MapO=20; $NorthA=145; $NorthO=120; class PDF extends FPDF { //Page header function Header() { global $isTitle; global $title; if($isTitle=='1') { $this->SetFont('Arial','B',15); $this->Cell(80); $this->Cell(30,10,$title,0,1,'C'); $this->Ln(20); } } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','I',8); //Page number $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); if($isTitle=='0') { $LegendO=$LegendO-10; $MapO=$MapO-10; $NorthO=$NorthO-10; } if($isLegend=='0') { $MapA=$MapA-40; $NorthA=$NorthA-40; saveImage($imgRequest,$sessionId,"Map",".png"); $pdf->Image($tempMapImgPath,$MapA,$MapO,100,100); unlink($tempMapImgPath); } if($isLegend=='1') { saveImage($LegendImgRequest,$sessionId,"Legend",".png"); $pdf->Image($tempMapImgPath,$LegendA,$LegendO,35,100); unlink($tempMapImgPath); } saveImage($imgRequest,$sessionId,"Map",".png"); $pdf->Image($tempMapImgPath,$MapA,$MapO,100,100); unlink($tempMapImgPath); if($isArrow=='1') { $pdf->Image("pr_north.gif",$NorthA,$NorthO,15,15); } $pdf->Output(); function saveImage($imageSource,$sessionId,$ImageType,$ImageFormat) { global $tempMapImgPath; $ch = curl_init($imageSource); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close($ch); $tempMapImgPath = $ImageType.$sessionId.time().$ImageFormat; $fp = fopen($tempMapImgPath,'w'); fwrite($fp, $rawdata); fclose($fp); } function GetParameters($params) { global $mapName, $sessionId, $title, $locale; global $scale, $centerX, $centerY, $dpi; global $isTitle, $isLegend, $isArrow; global $Server; if(isset($params['LOCALE'])) $locale = $params['LOCALE']; $mapName = $params['MAPNAME']; $sessionId = $params['SESSION']; $isTitle = $params['ISTITLE']; $isLegend = $params['ISLEGEND']; $isArrow = $params['ISARROW']; $title = $params['TITLE']; $scale = $params['SCALE']; $centerX = $params['CENTERX']; $centerY = $params['CENTERY']; $dpi = $params['DPI']; $Server = $params['SERVER']; } function GetRequestParameters() { if($_SERVER['REQUEST_METHOD'] == "POST") GetParameters($_POST); else GetParameters($_GET); } ?> save the above code as some file mappdf.php in the folder C:\Program Files\OSGeo\MapGuide\Web\www\fusion\widgets\Print I will call this pdf file from print.js (widget) showPdf: function() { var mainMap = this.getMap(); // this.printablePdfURL is Fusion.getFusionURL() + widgetTag.location + 'Print/mappdf.php'; var url = this.printablePdfURL + '?'; var extents = mainMap.getCurrentExtents(); var centerX = (extents.left + extents.right) / 2; var centerY = (extents.top + extents.bottom) / 2; var dpi = mainMap._nDpi; var scale = mainMap.getScale(); var maps = mainMap.getAllMaps(); url = url + 'MAPNAME=' + mainMap.getMapName(); url = url + '&SESSION=' + maps[0].getSessionID(); url = url + '&CENTERX=' + centerX; url = url + '&CENTERY=' + centerY; url = url + '&DPI=' + dpi; url = url + '&SCALE=' + scale; url = url + '&ISTITLE=' + (this.showTitle != '' ? '1' : '0'); url = url + '&ISLEGEND=' + (this.showLegend ? '1' : '0'); url = url + '&ISARROW=' + (this.showNorthArrow ? '1' : '0'); url = url + '&SERVER=' + Fusion.getFusionURL().split('/mapguide')[0]; if (this.pageTitle != '') { url = url + '&TITLE=' + this.pageTitle; } window.open(url, 'printablepdf', ''); } -- View this message in context: http://osgeo-org.1803224.n2.nabble.com/Generate-a-pdf-view-of-the-current-map-tp5264270p5272913.html Sent from the MapGuide Users mailing list archive at Nabble.com. _______________________________________________ mapguide-users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/mapguide-users
_______________________________________________ mapguide-users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/mapguide-users
