comparison client/src/components/Pdftool.vue @ 2207:da902f0dac88 pdf-export

pdf-gen: add fixed coordinates and values * enter coordinates and values for scalebar and pageinfo to template 1,2 examples
author Fadi Abbud <fadi.abbud@intevation.de>
date Wed, 06 Feb 2019 09:56:36 +0100
parents 59c21dee6315
children 733cfc3db48a
comparison
equal deleted inserted replaced
2206:2e64d1be3dbc 2207:da902f0dac88
151 { 151 {
152 type: "docinfo", 152 type: "docinfo",
153 x_coordinate: 0, 153 x_coordinate: 0,
154 y_coordinate: 0, 154 y_coordinate: 0,
155 elementWidth: 118, 155 elementWidth: 118,
156 elementHeight: 8 156 elementHeight: 8,
157 textSize: 9
157 }, 158 },
158 { 159 {
159 type: "image", 160 type: "image",
160 imageType: "PNG", 161 imageType: "PNG",
161 imageUrl: "", 162 imageUrl: "",
164 imageWidth: 50, 165 imageWidth: 50,
165 imageHeight: 23 166 imageHeight: 23
166 }, 167 },
167 { 168 {
168 type: "scalebar", 169 type: "scalebar",
169 //x_coordinate:, 170 x_coordinate: 226.5,
170 y_coordinate: 204 171 y_coordinate: 204
171 //elementsize: 50 172 //elementsize: 50
172 }, 173 },
173 { 174 {
174 type: "textbox", 175 type: "textbox",
192 resolution: "120", 193 resolution: "120",
193 paperSize: "a3" 194 paperSize: "a3"
194 }, 195 },
195 elements: [ 196 elements: [
196 { 197 {
198 type: "docinfo",
199 x_coordinate: 0,
200 y_coordinate: 0,
201 elementWidth: 118,
202 elementHeight: 8,
203 textSize: 9
204 },
205 {
197 type: "image", 206 type: "image",
198 imageType: "PNG", 207 imageType: "PNG",
199 imageUrl: "", 208 imageUrl: "",
200 x_coordinate: 30, 209 x_coordinate: 30,
201 y_coordinate: 297, 210 y_coordinate: 297,
202 imageWidth: 50, 211 imageWidth: 50,
203 imageHeight: 23 212 imageHeight: 23
204 }, 213 },
205 { 214 {
206 type: "scalebar", 215 type: "scalebar",
207 //x_coordinate: 250, 216 x_coordinate: 247.3,
208 y_coordinate: 420 - 6 217 y_coordinate: 414
209 //elementsize: 50 218 //elementsize: 50
210 }, 219 },
211 { 220 {
212 type: "textbox", 221 type: "textbox",
213 x_coordinate: 50, 222 x_coordinate: 50,
214 y_coordinate: 50, 223 y_coordinate: 50,
215 elementSize: 22, 224 elementSize: 22,
216 text: "from template", 225 text: "from template",
217 color: "black" 226 color: "black"
218 },
219 {
220 type: "docinfo",
221 x_coordinate: 0,
222 y_coordinate: 0,
223 elementWidth: 118,
224 elementHeight: 8
225 }, 227 },
226 { 228 {
227 type: "aboutbox" 229 type: "aboutbox"
228 //x_coordinate: 0, 230 //x_coordinate: 0,
229 //y_coordinate: 210 - 20 231 //y_coordinate: 210 - 20
351 } 353 }
352 if (template) { 354 if (template) {
353 template.elements.forEach(t => { 355 template.elements.forEach(t => {
354 switch (t.type) { 356 switch (t.type) {
355 case "image": { 357 case "image": {
356 console.log("autobox from template");
357 if (t.imageUrl.length > 0) { 358 if (t.imageUrl.length > 0) {
358 pdf.addImage( 359 pdf.addImage(
359 t.imageUrl, 360 t.imageUrl,
360 t.imageType, 361 t.imageType,
361 t.x_coordinate, 362 t.x_coordinate,
370 self.addScaleBar( 371 self.addScaleBar(
371 pdf, 372 pdf,
372 width, 373 width,
373 height, 374 height,
374 scaleNominator, 375 scaleNominator,
376 t.x_coordinate,
375 t.y_coordinate 377 t.y_coordinate
376 ); 378 );
377 break; 379 break;
378 } 380 }
379 case "textbox": { 381 case "textbox": {
387 t.text 389 t.text
388 ); 390 );
389 break; 391 break;
390 } 392 }
391 case "docinfo": { 393 case "docinfo": {
392 self.addPageInfo(pdf); 394 self.addPageInfo(
395 pdf,
396 t.x_coordinate,
397 t.y_coordinate,
398 t.elementWidth,
399 t.elementHeight,
400 t.textSize
401 );
393 break; 402 break;
394 } 403 }
395 case "aboutbox": { 404 case "aboutbox": {
396 self.addAboutBox(pdf, width, height); 405 self.addAboutBox(pdf, width, height);
397 break; 406 break;
408 } 417 }
409 }); 418 });
410 419
411 pdf.save("map.pdf"); 420 pdf.save("map.pdf");
412 } else { 421 } else {
413 self.addScaleBar(pdf, width, height, scaleNominator, 204); 422 self.addScaleBar(pdf, width, height, scaleNominator, 226.5, 204);
414 self.addPageInfo(pdf); 423 self.addPageInfo(pdf, 0, 0, 110, 8, 9);
415 self.addAboutBox(pdf, width, height); 424 self.addAboutBox(pdf, width, height);
416 pdf.save("map.pdf"); 425 pdf.save("map.pdf");
417 } 426 }
418 // reset to original size 427 // reset to original size
419 map.setSize(mapSize); 428 map.setSize(mapSize);
461 // using jsPDF units 470 // using jsPDF units
462 doc.setDrawColor(255, 255, 255); 471 doc.setDrawColor(255, 255, 255);
463 doc.setFillColor(255, 255, 255); 472 doc.setFillColor(255, 255, 255);
464 doc.roundedRect(x, y, w, h, 3, 3, "FD"); 473 doc.roundedRect(x, y, w, h, 3, 3, "FD");
465 }, 474 },
466 addScaleBar(doc, docWidth, docHeight, scaleNominator, y) { 475 addScaleBar(doc, docWidth, docHeight, scaleNominator, x, y) {
467 // scaleNominator is the x in 1:x of the map scale 476 // scaleNominator is the x in 1:x of the map scale
468 477
469 // hardcode maximal width for now and place in lower right corner 478 // hardcode maximal width for now and place in lower right corner
470 let maxWidth = 80; // in mm 479 let maxWidth = 80; // in mm
471 480
520 length = factor; 529 length = factor;
521 } 530 }
522 531
523 let size = (length * unitConversionFactor) / scaleNominator / 4; 532 let size = (length * unitConversionFactor) / scaleNominator / 4;
524 533
525 let x = docWidth - (size * 4 + 8); 534 //let x = docWidth - (size * 4 + 8);
526 //let y = docHeight - 6; 535 //let y = docHeight - 6;
527 536
528 this.addRoundedBox(doc, x - 4, y - 4, size * 4 + 12, 10); 537 this.addRoundedBox(doc, x - 4, y - 4, size * 4 + 12, 10);
529 538
530 doc.setDrawColor(0, 0, 0); 539 doc.setDrawColor(0, 0, 0);
579 var textLines = doc.splitTextToSize(text, lineWidth); 588 var textLines = doc.splitTextToSize(text, lineWidth);
580 doc.setTextColor(color); 589 doc.setTextColor(color);
581 doc.setFontSize(size); 590 doc.setFontSize(size);
582 doc.text(postitionX, positionY, textLines); 591 doc.text(postitionX, positionY, textLines);
583 }, 592 },
584 addPageInfo(doc) { 593 addPageInfo(doc, x, y, width, height, textSize) {
585 this.addRoundedBox(doc, 0, 0, 110, 8); 594 this.addRoundedBox(doc, x, y, width, height);
586 let str = 595 let str =
587 this.$gettext("Date of publication:") + 596 this.$gettext("Date of publication:") +
588 " " + 597 " " +
589 new Date().toLocaleString(locale2) + 598 new Date().toLocaleString(locale2) +
590 " " + 599 " " +
591 this.$gettext("– generated by:") + 600 this.$gettext("– generated by:") +
592 " " + 601 " " +
593 this.user; 602 this.user;
594 this.addText(doc, 5, 5, 9, "black", 100, str); 603 this.addText(doc, x + 5, y + 5, textSize, "black", 100, str);
595 }, 604 },
596 addAboutBox(doc, docWidth, docHeight) { 605 addAboutBox(doc, docWidth, docHeight) {
597 let top = docHeight - 20; 606 let top = docHeight - 20;
598 this.addRoundedBox(doc, 0, top, 120, 20); 607 this.addRoundedBox(doc, 0, top, 120, 20);
599 608