Skip to content

Commit a6ba12c

Browse files
authored
Merge pull request #129 from Dataport/fix/embed-exported-pdf
Fix: PDF export with download:false
2 parents 988b98e + 8f2aa7c commit a6ba12c

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

packages/clients/snowbox/src/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
:root {
1818
--not-quite-white: #f2f3f4;
1919
--eigengrau: #16161d;
20+
--map-height: 600px;
2021
}
2122

2223
* {
@@ -60,13 +61,19 @@
6061
.polarstern {
6162
width: 100vw;
6263
max-width: calc(100% + 64px);
63-
height: 600px;
64+
height: var(--map-height);
6465
position: relative;
6566
margin-top: 10px;
6667
margin-bottom: 10px;
6768
left: -32px;
6869
outline: solid var(--eigengrau);
6970
}
71+
72+
#vuex-target-export-result {
73+
width: 100%;
74+
height: var(--map-height);
75+
}
76+
7077
</style>
7178
</head>
7279
<body>
@@ -100,7 +107,7 @@ <h2>Example for programmatic information binding</h2>
100107
</p>
101108
<p>
102109
Map export:
103-
<image id="vuex-target-export-result"></image>
110+
<embed id="vuex-target-export-result">
104111
</p>
105112
<script type="module" src="./polar-client.ts"></script>
106113
<script>

packages/plugins/Export/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unreleased
4+
5+
- Fix: PDF export with download:false now works correctly.
6+
37
## 1.2.0
48

59
- Feature: Improved implementation to make plugin SPA-ready.

packages/plugins/Export/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ map.$store.dispatch('plugin/export/exportAs', type)
3030

3131
### State
3232

33-
This shows how a callback can be used to immediately show a `Png` screenshot in an image tag. The value of the `screenshot` variable is a base64-encoded string.
33+
This shows how a callback can be used to show the exported data in a suitable html element. The value of the `screenshot` variable is a base64-encoded string.
3434

3535
```js
36-
const someImgTag = // ... however you retrieve your tag
36+
const someElement = // ... however you retrieve your html element
3737
map.subscribe('plugin/export/exportedMap', (screenshot) =>
38-
someImgTag.setAttribute('src', screenshot)
38+
someElement.setAttribute('src', screenshot)
3939
)
4040
```

packages/plugins/Export/src/store/actions.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,37 @@ const actions: PolarActionTree<ExportState, ExportGetters> = {
7272
}
7373
)
7474

75-
const src = mapCanvas.toDataURL(
75+
let src = mapCanvas.toDataURL(
7676
type === ExportFormat.PNG ? 'image/png' : 'image/jpeg'
7777
)
7878

79-
commit('setExportedMap', src)
80-
81-
if (!download) {
82-
/*
83-
commit(
84-
'plugin/toast/addToast',
85-
{
86-
message: 'Your image is awesome and stored.',
87-
},
88-
{ root: true }
89-
)
90-
*/
91-
} else if (type === ExportFormat.JPG || type === ExportFormat.PNG) {
92-
const link = document.createElement('a')
93-
link.download = 'map.' + (type === ExportFormat.PNG ? 'png' : 'jpeg')
94-
link.href = src
95-
document.body.appendChild(link)
96-
link.click()
97-
document.body.removeChild(link)
79+
if (type === ExportFormat.JPG || type === ExportFormat.PNG) {
80+
if (download) {
81+
const link = document.createElement('a')
82+
link.download = 'map.' + (type === ExportFormat.PNG ? 'png' : 'jpeg')
83+
link.href = src
84+
document.body.appendChild(link)
85+
link.click()
86+
document.body.removeChild(link)
87+
}
9888
} else {
9989
// TODO: decide on a format, scale map accordingly
10090
const format = 'a4'
10191
const dim = dims[format]
10292
// Import of jspdf is in mounted.
103-
const pdf = new jsPDF('landscape', undefined, format) // eslint-disable-line
93+
const pdf = new jsPDF('landscape', undefined, format) // eslint-disable-line
10494
pdf.addImage(src, 'JPEG', 0, 0, dim[0], dim[1])
105-
pdf.save('map.pdf')
10695
// Reset original map size
10796
map.setSize(size)
10897
map.getView().setResolution(viewResolution)
98+
src = pdf.output('datauristring')
99+
100+
if (download) {
101+
pdf.save('map.pdf')
102+
}
109103
}
104+
105+
commit('setExportedMap', src)
110106
})
111107
map.renderSync()
112108
},

0 commit comments

Comments
 (0)