[mapserver-users] PDF Output: How?

Rodrigo Cabral cabral at yadata.net
Sat Feb 16 17:21:03 EST 2002


Ok, so now we're beginning to reach an ideal calling convention (i.e.
arguments) for a drawMapPDF (or drawPDF) function... I agree that maybe
passing $pagexmax and $pagexmin along with the origem (x,y) is a good idea,
as opposed to let mapfile's SIZE statement to control this info. SIZE
wouldn't need to be defined at all. So:

$map->drawpdf( $pdfobj, $pagexmin, $pageymin, $pagexmax, $pageymax );

is okay for us users (at least for Paul and I), so far =) Hope the
'mappdf.c' author don't mind us playing around with the subject.

Paul, a few comments on your email:

(a) It's a good approach. but as you said in (b) you don't have much control
on the PDF output. I couldn't go for that, that's why I'll keep with my
raster image embeding. I need to put text along with the map image. It's a 5
pages report...
(b.1) I guess your words are my words =) That's exacly what I said when I
talked about X,Y coordinates (which you called pagexmin, pageymin). Maybe I
wasn't clear enough, but hey, English is not my first language!
(b.2) Same thing =) Check my code (btw Left,Top,Right,Bottom are calculated
in page coordinates).

My R$0.02 (US$0.008)

Cheers,
Rod.

----- Original Message -----
From: "Paul Ramsey" <pramsey at refractions.net>
To: <mapserver-users at lists.gis.umn.edu>
Cc: "Rodrigo Cabral" <cabral at yadata.net>
Sent: Saturday, February 16, 2002 5:00 PM
Subject: Re: [mapserver-users] PDF Output: How?


(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_handler = 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