# HG changeset patch # User Fadi Abbud # Date 1549380781 -3600 # Node ID 59c21dee63150a55a6e942be125b30319dd9f00f # Parent af136b1a854e8703df4d0ac20c85aa119fe521a2 pdf-gen: improve pdftool to use value from template * change download function to check the commig values for template * old coordinates are still used , improve it to get them from template is still needed #: src/components/Logs.vue:25 msgid "Accesslog" msgstr "Zugriffs-Protokoll" diff -r af136b1a854e -r 59c21dee6315 client/src/components/Pdftool.vue --- a/client/src/components/Pdftool.vue Tue Feb 05 14:46:26 2019 +0100 +++ b/client/src/components/Pdftool.vue Tue Feb 05 16:33:01 2019 +0100 @@ -146,7 +146,44 @@ format: "landscape", resolution: "80", paperSize: "a4" - } + }, + elements: [ + { + type: "docinfo", + x_coordinate: 0, + y_coordinate: 0, + elementWidth: 118, + elementHeight: 8 + }, + { + type: "image", + imageType: "PNG", + imageUrl: "", + x_coordinate: 30, + y_coordinate: 297, + imageWidth: 50, + imageHeight: 23 + }, + { + type: "scalebar", + //x_coordinate:, + y_coordinate: 204 + //elementsize: 50 + }, + { + type: "textbox", + x_coordinate: 50, + y_coordinate: 190, + elementSize: 8, + text: "textfrom template", + color: "black" + }, + { + type: "aboutbox" + //x_coordinate: 0, + //y_coordinate: 210 - 20 + } + ] }, { name: "Template 2", @@ -154,7 +191,44 @@ format: "portrait", resolution: "120", paperSize: "a3" - } + }, + elements: [ + { + type: "image", + imageType: "PNG", + imageUrl: "", + x_coordinate: 30, + y_coordinate: 297, + imageWidth: 50, + imageHeight: 23 + }, + { + type: "scalebar", + //x_coordinate: 250, + y_coordinate: 420 - 6 + //elementsize: 50 + }, + { + type: "textbox", + x_coordinate: 50, + y_coordinate: 50, + elementSize: 22, + text: "from template", + color: "black" + }, + { + type: "docinfo", + x_coordinate: 0, + y_coordinate: 0, + elementWidth: 118, + elementHeight: 8 + }, + { + type: "aboutbox" + //x_coordinate: 0, + //y_coordinate: 210 - 20 + } + ] } ], logoImageForPDF: null, // a HTMLImageElement instance @@ -194,6 +268,7 @@ }); }, download() { + let template = this.templates.find(t => t.name === this.form.template); // disable button while working on it this.readyToGenerate = false; @@ -266,16 +341,80 @@ var data = canvas.toDataURL("image/jpeg"); pdf.addImage(data, "JPEG", 0, 0, width, height); - self.addScaleBar(pdf, width, height, scaleNominator); + //self.addScaleBar(pdf, width, height, scaleNominator); self.addNorthArrow(pdf, 15, 9, northarrowSize); - self.addPageInfo(pdf); - self.addAboutBox(pdf, width, height); + //self.addPageInfo(pdf); + //self.addAboutBox(pdf, width, height); if (self.getLayerByName("Bottleneck isolines").isVisible) { self.addLegend(pdf, width, height); } + if (template) { + template.elements.forEach(t => { + switch (t.type) { + case "image": { + console.log("autobox from template"); + if (t.imageUrl.length > 0) { + pdf.addImage( + t.imageUrl, + t.imageType, + t.x_coordinate, + t.y_coordinate, + t.imageWidth, + t.imageHeight + ); + } + break; + } + case "scalebar": { + self.addScaleBar( + pdf, + width, + height, + scaleNominator, + t.y_coordinate + ); + break; + } + case "textbox": { + self.addText( + pdf, + t.x_coordinate, + t.y_coordinate, + t.elementSize, + t.color, + 100, + t.text + ); + break; + } + case "docinfo": { + self.addPageInfo(pdf); + break; + } + case "aboutbox": { + self.addAboutBox(pdf, width, height); + break; + } + /* case "docinfo": { + self.addAboutBox( + pdf, + t.x_coordinate, + t.y_coordinate, + t.elementWidth, + t.elementHeight + ); + } */ + } + }); - pdf.save("map.pdf"); + pdf.save("map.pdf"); + } else { + self.addScaleBar(pdf, width, height, scaleNominator, 204); + self.addPageInfo(pdf); + self.addAboutBox(pdf, width, height); + pdf.save("map.pdf"); + } // reset to original size map.setSize(mapSize); map.getView().fit(mapExtent, { size: mapSize }); @@ -324,7 +463,7 @@ doc.setFillColor(255, 255, 255); doc.roundedRect(x, y, w, h, 3, 3, "FD"); }, - addScaleBar(doc, docWidth, docHeight, scaleNominator) { + addScaleBar(doc, docWidth, docHeight, scaleNominator, y) { // scaleNominator is the x in 1:x of the map scale // hardcode maximal width for now and place in lower right corner @@ -353,7 +492,7 @@ unit = "km"; unitConversionFactor = 1e6; } else if (maxLength >= 1e4) { - // >= 10 m + // >= 10 m) unit = "m"; unitConversionFactor = 1e3; } @@ -384,7 +523,7 @@ let size = (length * unitConversionFactor) / scaleNominator / 4; let x = docWidth - (size * 4 + 8); - let y = docHeight - 6; + //let y = docHeight - 6; this.addRoundedBox(doc, x - 4, y - 4, size * 4 + 12, 10);