Added button for HPGL export.

This commit is contained in:
Gijs 2024-06-07 11:22:07 +02:00
parent 8b8a1cf80f
commit e972ffb387
2 changed files with 25 additions and 3 deletions

2
app.py
View File

@ -378,7 +378,7 @@ def hpgl (id):
with open(hpgl_file, 'r') as hpgl_handle:
r = Response(hpgl_handle.read(), mimetype='application/hpgl')
r.headers.extend({
'Content-Disposition': 'attachment; filename="cobbled-paths.hpgl"'
'Content-Disposition': f'attachment; filename="cobbled-paths-{id}.hpgl"'
})
# remove tmp file

View File

@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/FileSaver.js"></script>
<style>
#save-svg{
#save-buttons{
position: fixed;
top: 0.5em;
right: 0.5em;
@ -28,7 +28,10 @@
{{ svg|safe }}
<button id="save-svg">> SVG</button>
<div id="save-buttons">
<button id="save-svg">> SVG</button>
<button id="save-hpgl">> HPGL</button>
</div>
<script>
function get2bodyclass(){
@ -58,6 +61,25 @@
let blob = new Blob([source], {type: "text/plain;charset=utf-8"});
saveAs(blob, 'cobbled-paths.svg');
});
let save_button_hpgl = document.getElementById('save-hpgl');
save_button_hpgl.addEventListener('click', function () {
let url = document.URL,
parts = url.split('/'),
name = parts[parts.length-1],
hpgl_url = '/hpgl/' + name,
a = document.createElement('a');
a.href = hpgl_url;
a.setAttribute('download', 'download');
if (document.createEvent) {
const event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
a.dispatchEvent(event);
}
else {
a.click();
}
});
</script>
</body>