1
/******************************************************************************
2
* $Id: shp2pdf.c 8489 2009-02-03 20:35:24Z tomkralidis $
5
* Purpose: Commandline shape to pdf converter.
6
* Author: Steve Lime and the MapServer team.
8
******************************************************************************
9
* Copyright (c) 1996-2005 Regents of the University of Minnesota.
11
* Permission is hereby granted, free of charge, to any person obtaining a
12
* copy of this software and associated documentation files (the "Software"),
13
* to deal in the Software without restriction, including without limitation
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
* and/or sell copies of the Software, and to permit persons to whom the
16
* Software is furnished to do so, subject to the following conditions:
18
* The above copyright notice and this permission notice shall be included in
19
* all copies of this Software or works derived from this Software.
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
* DEALINGS IN THE SOFTWARE.
28
****************************************************************************/
30
#include "mapserver.h"
32
MS_CVSID("$Id: shp2pdf.c 8489 2009-02-03 20:35:24Z tomkralidis $")
38
initializePDF(char *filename)
41
PDF_open_file(pdf, filename);
42
PDF_set_info(pdf, "Creator", "Mapserver");
43
PDF_set_info(pdf, "Author", "Mapserver");
44
PDF_set_info(pdf, "Title", "Mapserver PDF Map");
58
int main(int argc, char *argv[])
61
fprintf(stdout, "%s\n", msGetVersion());
62
fprintf(stdout, "Compiled without PDF support.");
70
outputFormatObj *format=NULL;
71
/* gdImagePtr img=NULL; */
77
char *invalid_layer=NULL;
79
char *outfile=NULL; /* no -o sends image to STDOUT */
82
int PagePixelWidth = 595;
83
int PagePixelHeight = 842;
84
int PagePixelMargin = 50;
86
if(argc > 1 && strcmp(argv[1], "-v") == 0) {
87
printf("%s\n", msGetVersion());
91
/* ---- check the number of arguments, return syntax if not correct ---- */
93
fprintf(stdout, "\nPurpose: convert a mapfile to a PDF document\n\n");
94
fprintf(stdout,"Syntax: shp2pdf -m mapfile -o pdf [-e minx miny maxx maxy] [-l \"layer1 [layers2...]\"] [-t] [-d layername datavalue]\n" );
95
fprintf(stdout," -m mapfile: Map file to operate on - required\n" );
96
fprintf(stdout," -o pdf: output filename (stdout if not provided)\n");
97
fprintf(stdout," -e minx miny maxx maxy: extents to render\n");
98
fprintf(stdout," -l layers: layers to enable - make sure they are quoted and space seperated if more than one listed\n" );
99
fprintf(stdout," -t : turn on transparency\n");
100
fprintf(stdout," -d layername datavalue: change DATA value for a layer\n" );
104
for(i=1;i<argc;i++) { /* Step though the user arguments, 1st to find map file */
106
if(strncmp(argv[i],"-m",2) == 0) {
107
map = msLoadMap(argv[i+1], NULL);
109
msWriteError(stderr);
116
fprintf(stderr, "Mapfile (-m) option not specified.\n");
120
for(i=1;i<argc;i++) { /* Step though the user arguments */
122
if(strncmp(argv[i],"-m",2) == 0) { /* skip it */
126
if(strncmp(argv[i],"-o",2) == 0) {
127
outfile = strdup(argv[i+1]);
131
if(strncmp(argv[i],"-d",2) == 0) { /* swap layer data */
132
for(j=0; j<map->numlayers; j++) {
133
if(strcmp(GET_LAYER(map, j)->name, argv[i+1]) == 0) {
134
free(GET_LAYER(map, j)->data);
135
GET_LAYER(map, j)->data = strdup(argv[i+2]);
142
/*if(strncmp(argv[i], "-t", 2) == 0) transparency
143
map->transparent = MS_ON;*/
145
if(strncmp(argv[i],"-e",2) == 0) { /* change extent */
146
map->extent.minx = atof(argv[i+1]);
147
map->extent.miny = atof(argv[i+2]);
148
map->extent.maxx = atof(argv[i+3]);
149
map->extent.maxy = atof(argv[i+4]);
152
format = msCreateDefaultOutputFormat(map, "pdf");
153
map->outputformat = format;
155
if(strncmp(argv[i],"-l",2) == 0) { /* load layer list */
156
layers = msStringSplit(argv[i+1], ' ', &(num_layers));
158
for(j=0; j<num_layers; j++) { /* loop over -l */
160
for(k=0; k<map->numlayers; k++) {
161
if(GET_LAYER(map, k)->name && strcmp(GET_LAYER(map, k)->name, layers[j]) == 0) {
166
invalid_layer = strdup(layers[j]);
169
if (layer_found==0) {
170
fprintf(stderr, "Layer (-l) %s not found\n", invalid_layer);
176
for(j=0; j<map->numlayers; j++) {
177
if(GET_LAYER(map, j)->status == MS_DEFAULT)
180
GET_LAYER(map, j)->status = MS_OFF;
181
for(k=0; k<num_layers; k++) {
182
if(strcmp(GET_LAYER(map, j)->name, layers[k]) == 0) {
183
GET_LAYER(map, j)->status = MS_ON;
189
msFreeCharArray(layers, num_layers);
195
/*gdImageDestroy(img);*/
196
map->height = PagePixelHeight-(2*PagePixelMargin);
197
map->width = PagePixelWidth-(2*PagePixelMargin);
198
image = msDrawMap(map, MS_FALSE);
199
msSaveImage(map, image, outfile);
205
} /* ---- END Main Routine ---- */