[mapserver-users] PDF Output: How?
Paul Ramsey
pramsey at refractions.net
Sat Feb 16 12:00:50 PST 2002
(a) You can use the PDF drawing routines in your PHP/MapScript
applications right now, with just a little indirection. Use $map->save()
to write out a mapfile which reflects the current state of your map
objects (extents, layers, etc). Then use a php exec() call to run the
shp2pdf program against that mapfile. Voila, instant gratification. We
are using this right now, works great.
(b) In terms of implementation of PDF support in PHP/Mapscript, my
recommendation would be this:
(1) that the existing PDF support in PHP be examined, and depended on,
so that to create PDF version of a map you would first create a standard
PHP PDF object, then pass that object to the mapscript PDF writing
function. That would allow people to create more customized PDF output,
by using the PHP PDF support to add useful things like titles, dates,
disclaimers, etc etc, to their printable output, and just using the
Mapscript support to render the actual map.
(2) that the PDF writing function include parameters to control where on
the page the map is written. Probably best done using page coordinates
(since pages can be of different sizes).
$map->drawpdf($pdfobj, $pagexmin, $pageymin, $pagexmax, $pageymax);
My $0.02CA ($0.013US)
Paul.
Rodrigo Cabral wrote:
>
> Apparently PDF support is drawing lots of interest recently =) I, for one,
> have also successfully drawn map images in PDF files to generate reports,
> although I haven't used MapServer's PDF extension for a few reasons. Using
> PHP/MapScript, I embeded a 1800x1800 image in the PDF report, which is
> generated using mapscript plus a different mapfile than the one used for web
> browsing (created specifically for printing). The image is big enough to
> avoid seeing pixel artifacts in the print out, and the result is quite
> pleasant.
>
> HOWEVER, this approach will never match the quality of vector
> images drawn directly in PDF, and also makes the PDF file larger (I think).
> So, what I'm doing right now is just waiting for the PDF+MapScript support
> to be written....
>
> BUT.... I was thinking about the msDrawMapPDF(...) function arguments, and
> noticed that you cannot control the position (X,Y) of where the map is going
> to be drawn, it's always centered in the page and apparently the size of the
> map is defined with the mapfile SIZE statement.
>
> SO, I have a few suggestions to make, if ~frank~ (author of mappdf.c) would
> concur... Hope I'm not intruding about it.
>
> 1) Include X, Y coordinates in msDrawMapPDF function. So, in MapScript, one
> would simply do this:
>
> $pdf = pdf_new();
> $map = ms_newMapObj( $pdf_mapfile );
> // *** lots of processing here ***
> $map->drawMapPDF( $pdf_handler, $x, $y );
> // *** now, simply return the created PDF report
>
> 2) Assume that the width and height of the map (as defined in the mapfile
> SIZE statement) is in the same metrics of the PDF file. Therefore, the
> actual place where the map should be drawn in the PDF page is:
> Left: $x
> Top: $y
> Right: ($x + $map->{width})
> Bottom: ($y + $map->{height})
> I trust that most people would have a different mapfile for printing (rather
> than using the same one for browsing), so it wouldn't be much of a problem
> to use the mapfile image SIZE to store PDF targeted values.
>
> In time, the other draw methods could also be implemented with the same
> assumptions. Thus, one would be able to create a report with georeferenced
> information right alongside report text, plus legend, scalebar, etc...
>
> Any comments?
>
> Rod.
>
> ----- Original Message -----
> From: "Steve Lime" <steve.lime at dnr.state.mn.us>
> To: <Antti.Roppola at brs.gov.au>
> Cc: <mapserver-users at lists.gis.umn.edu>
> Sent: Friday, February 15, 2002 1:21 AM
> Subject: RE: [mapserver-users] PDF Output: How?
>
> The landview piece simply embeds a image rendered in mapserver into a pdf. I
> can share code.
>
> However, there are opportunities to create vector PDFs with MapServer. The
> shp2pdf program is an example. You can easily wrap that with perl or
> whatever pretty easily. I'll add scripting access to that once a C wrapper
> to writing a PDF file is done.
>
> Steve
>
> Stephen Lime
> Data & Applications Manager
>
> Minnesota DNR
> 500 Lafayette Road
> St. Paul, MN 55155
> 651-297-2937
> >>> <Antti.Roppola at brs.gov.au> 02/14/02 21:33 PM >>>
> Concidentally, Rasmus was here this week and talked about this. :o)
>
> Have a look at slide 51 onward at http://conf.php.net/oz2002/
> (BTW, I couldn't get the slide browser to work under IE, only Netscape).
>
> Slide 57 has an example of placing an image into a PDF.
> Putting Mapserver stuff into a PDF this way looks to be easy (it's on my
> list of things to try). Keeping vector map layers as vectors using
> SVG or something would be cooler still.
>
> The Shockwave stuff is even more interesting, animated maps anyone?
>
> Cheers,
>
> Antti
>
> Eliot wrote:
>
> > Basically I just want to have a print to pdf button on my application much
> > like the landview site. Could someone point me to some examples of how to
> do
> > this, or give me some clues and I can go from there?
>
> > I see the landview site is done with perl. Can the pdf functions be called
> > from php/mapscript as well?
More information about the MapServer-users
mailing list