@progress/kendo-pdfviewer-common 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/utils.js +20 -9
- package/dist/es2015/utils.js +20 -9
- package/dist/npm/utils.js +20 -9
- package/package.json +1 -1
package/dist/es/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { saveAs } from '@progress/kendo-file-saver';
|
|
2
2
|
import { getDocument, renderTextLayer } from 'pdfjs-dist';
|
|
3
|
+
const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
3
4
|
/**
|
|
4
5
|
* @hidden
|
|
5
6
|
*/
|
|
6
7
|
export const DEFAULT_ZOOM_LEVEL = 1.25;
|
|
7
|
-
const scale =
|
|
8
|
+
const scale = () => (isIOS() ? devicePixelRatio : devicePixelRatio * 3);
|
|
8
9
|
const parsePdfFromBase64String = (base64String) => {
|
|
9
10
|
return atob(base64String.replace(/^(data:application\/pdf;base64,)/gi, ''));
|
|
10
11
|
};
|
|
@@ -112,12 +113,13 @@ export const reloadDocument = (params) => {
|
|
|
112
113
|
export const print = (pages, done, error) => {
|
|
113
114
|
const dom = document.createElement('div');
|
|
114
115
|
const dones = pages.map(() => false);
|
|
116
|
+
const scaleNum = scale();
|
|
115
117
|
pages.forEach((page, index) => {
|
|
116
118
|
const viewport = renderCanvas(page, (el) => {
|
|
117
119
|
dom.appendChild(el);
|
|
118
120
|
dones[index] = true;
|
|
119
121
|
if (dones.every(Boolean)) {
|
|
120
|
-
openPrintDialog(dom, Math.floor(viewport.width /
|
|
122
|
+
openPrintDialog(dom, Math.floor(viewport.width / scaleNum), Math.floor(viewport.height / scaleNum), done, error);
|
|
121
123
|
}
|
|
122
124
|
}, error);
|
|
123
125
|
});
|
|
@@ -148,10 +150,11 @@ const openPrintDialog = (dom, width, height, done, onError) => {
|
|
|
148
150
|
}
|
|
149
151
|
};
|
|
150
152
|
const renderCanvas = (page, done, error) => {
|
|
151
|
-
const
|
|
153
|
+
const scaleNum = scale();
|
|
154
|
+
const viewport = page.getViewport({ scale: scaleNum });
|
|
152
155
|
const styles = {
|
|
153
|
-
width: Math.floor(viewport.width /
|
|
154
|
-
height: Math.floor(viewport.height /
|
|
156
|
+
width: Math.floor(viewport.width / scaleNum) + 'pt',
|
|
157
|
+
height: Math.floor(viewport.height / scaleNum) + 'pt'
|
|
155
158
|
};
|
|
156
159
|
const pageElement = createElement('div', '', styles);
|
|
157
160
|
const canvas = createElement('canvas', '', {
|
|
@@ -164,7 +167,7 @@ const renderCanvas = (page, done, error) => {
|
|
|
164
167
|
pageElement.appendChild(canvas);
|
|
165
168
|
page.render({ canvasContext, viewport })
|
|
166
169
|
.promise.then(() => {
|
|
167
|
-
const printContent = new Image(Math.floor((viewport.width /
|
|
170
|
+
const printContent = new Image(Math.floor((viewport.width / scaleNum)), Math.floor((viewport.height / scaleNum)));
|
|
168
171
|
printContent.src = canvas.toDataURL();
|
|
169
172
|
pageElement.removeChild(canvas);
|
|
170
173
|
pageElement.appendChild(printContent);
|
|
@@ -186,10 +189,11 @@ const createElement = function (name, className, styles) {
|
|
|
186
189
|
return element;
|
|
187
190
|
};
|
|
188
191
|
const renderPage = (page, zoom, error) => {
|
|
189
|
-
const
|
|
192
|
+
const scaleNum = scale();
|
|
193
|
+
const viewport = page.getViewport({ scale: scaleNum });
|
|
190
194
|
const styles = {
|
|
191
|
-
width: (Math.floor(viewport.width /
|
|
192
|
-
height: (Math.floor(viewport.height /
|
|
195
|
+
width: (Math.floor(viewport.width / scaleNum) * zoom) + 'pt',
|
|
196
|
+
height: (Math.floor(viewport.height / scaleNum) * zoom) + 'pt'
|
|
193
197
|
};
|
|
194
198
|
const pageElement = createElement('div', 'k-page', styles);
|
|
195
199
|
const canvas = createElement('canvas', '', {
|
|
@@ -211,6 +215,13 @@ const renderPage = (page, zoom, error) => {
|
|
|
211
215
|
textDivs: []
|
|
212
216
|
})
|
|
213
217
|
.promise.then(() => {
|
|
218
|
+
textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
|
|
219
|
+
textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
|
|
220
|
+
textLayer.querySelectorAll('span').forEach((el) => {
|
|
221
|
+
if (el.style.fontSize) {
|
|
222
|
+
el.style.fontSize = el.style.fontSize.replace(/px/g, 'pt');
|
|
223
|
+
}
|
|
224
|
+
});
|
|
214
225
|
pageElement.appendChild(textLayer);
|
|
215
226
|
})
|
|
216
227
|
.catch(error);
|
package/dist/es2015/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { saveAs } from '@progress/kendo-file-saver';
|
|
2
2
|
import { getDocument, renderTextLayer } from 'pdfjs-dist';
|
|
3
|
+
const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
3
4
|
/**
|
|
4
5
|
* @hidden
|
|
5
6
|
*/
|
|
6
7
|
export const DEFAULT_ZOOM_LEVEL = 1.25;
|
|
7
|
-
const scale =
|
|
8
|
+
const scale = () => (isIOS() ? devicePixelRatio : devicePixelRatio * 3);
|
|
8
9
|
const parsePdfFromBase64String = (base64String) => {
|
|
9
10
|
return atob(base64String.replace(/^(data:application\/pdf;base64,)/gi, ''));
|
|
10
11
|
};
|
|
@@ -112,12 +113,13 @@ export const reloadDocument = (params) => {
|
|
|
112
113
|
export const print = (pages, done, error) => {
|
|
113
114
|
const dom = document.createElement('div');
|
|
114
115
|
const dones = pages.map(() => false);
|
|
116
|
+
const scaleNum = scale();
|
|
115
117
|
pages.forEach((page, index) => {
|
|
116
118
|
const viewport = renderCanvas(page, (el) => {
|
|
117
119
|
dom.appendChild(el);
|
|
118
120
|
dones[index] = true;
|
|
119
121
|
if (dones.every(Boolean)) {
|
|
120
|
-
openPrintDialog(dom, Math.floor(viewport.width /
|
|
122
|
+
openPrintDialog(dom, Math.floor(viewport.width / scaleNum), Math.floor(viewport.height / scaleNum), done, error);
|
|
121
123
|
}
|
|
122
124
|
}, error);
|
|
123
125
|
});
|
|
@@ -148,10 +150,11 @@ const openPrintDialog = (dom, width, height, done, onError) => {
|
|
|
148
150
|
}
|
|
149
151
|
};
|
|
150
152
|
const renderCanvas = (page, done, error) => {
|
|
151
|
-
const
|
|
153
|
+
const scaleNum = scale();
|
|
154
|
+
const viewport = page.getViewport({ scale: scaleNum });
|
|
152
155
|
const styles = {
|
|
153
|
-
width: Math.floor(viewport.width /
|
|
154
|
-
height: Math.floor(viewport.height /
|
|
156
|
+
width: Math.floor(viewport.width / scaleNum) + 'pt',
|
|
157
|
+
height: Math.floor(viewport.height / scaleNum) + 'pt'
|
|
155
158
|
};
|
|
156
159
|
const pageElement = createElement('div', '', styles);
|
|
157
160
|
const canvas = createElement('canvas', '', {
|
|
@@ -164,7 +167,7 @@ const renderCanvas = (page, done, error) => {
|
|
|
164
167
|
pageElement.appendChild(canvas);
|
|
165
168
|
page.render({ canvasContext, viewport })
|
|
166
169
|
.promise.then(() => {
|
|
167
|
-
const printContent = new Image(Math.floor((viewport.width /
|
|
170
|
+
const printContent = new Image(Math.floor((viewport.width / scaleNum)), Math.floor((viewport.height / scaleNum)));
|
|
168
171
|
printContent.src = canvas.toDataURL();
|
|
169
172
|
pageElement.removeChild(canvas);
|
|
170
173
|
pageElement.appendChild(printContent);
|
|
@@ -186,10 +189,11 @@ const createElement = function (name, className, styles) {
|
|
|
186
189
|
return element;
|
|
187
190
|
};
|
|
188
191
|
const renderPage = (page, zoom, error) => {
|
|
189
|
-
const
|
|
192
|
+
const scaleNum = scale();
|
|
193
|
+
const viewport = page.getViewport({ scale: scaleNum });
|
|
190
194
|
const styles = {
|
|
191
|
-
width: (Math.floor(viewport.width /
|
|
192
|
-
height: (Math.floor(viewport.height /
|
|
195
|
+
width: (Math.floor(viewport.width / scaleNum) * zoom) + 'pt',
|
|
196
|
+
height: (Math.floor(viewport.height / scaleNum) * zoom) + 'pt'
|
|
193
197
|
};
|
|
194
198
|
const pageElement = createElement('div', 'k-page', styles);
|
|
195
199
|
const canvas = createElement('canvas', '', {
|
|
@@ -211,6 +215,13 @@ const renderPage = (page, zoom, error) => {
|
|
|
211
215
|
textDivs: []
|
|
212
216
|
})
|
|
213
217
|
.promise.then(() => {
|
|
218
|
+
textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
|
|
219
|
+
textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
|
|
220
|
+
textLayer.querySelectorAll('span').forEach((el) => {
|
|
221
|
+
if (el.style.fontSize) {
|
|
222
|
+
el.style.fontSize = el.style.fontSize.replace(/px/g, 'pt');
|
|
223
|
+
}
|
|
224
|
+
});
|
|
214
225
|
pageElement.appendChild(textLayer);
|
|
215
226
|
})
|
|
216
227
|
.catch(error);
|
package/dist/npm/utils.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const kendo_file_saver_1 = require("@progress/kendo-file-saver");
|
|
4
4
|
const pdfjs_dist_1 = require("pdfjs-dist");
|
|
5
|
+
const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
5
6
|
/**
|
|
6
7
|
* @hidden
|
|
7
8
|
*/
|
|
8
9
|
exports.DEFAULT_ZOOM_LEVEL = 1.25;
|
|
9
|
-
const scale =
|
|
10
|
+
const scale = () => (isIOS() ? devicePixelRatio : devicePixelRatio * 3);
|
|
10
11
|
const parsePdfFromBase64String = (base64String) => {
|
|
11
12
|
return atob(base64String.replace(/^(data:application\/pdf;base64,)/gi, ''));
|
|
12
13
|
};
|
|
@@ -114,12 +115,13 @@ exports.reloadDocument = (params) => {
|
|
|
114
115
|
exports.print = (pages, done, error) => {
|
|
115
116
|
const dom = document.createElement('div');
|
|
116
117
|
const dones = pages.map(() => false);
|
|
118
|
+
const scaleNum = scale();
|
|
117
119
|
pages.forEach((page, index) => {
|
|
118
120
|
const viewport = renderCanvas(page, (el) => {
|
|
119
121
|
dom.appendChild(el);
|
|
120
122
|
dones[index] = true;
|
|
121
123
|
if (dones.every(Boolean)) {
|
|
122
|
-
openPrintDialog(dom, Math.floor(viewport.width /
|
|
124
|
+
openPrintDialog(dom, Math.floor(viewport.width / scaleNum), Math.floor(viewport.height / scaleNum), done, error);
|
|
123
125
|
}
|
|
124
126
|
}, error);
|
|
125
127
|
});
|
|
@@ -150,10 +152,11 @@ const openPrintDialog = (dom, width, height, done, onError) => {
|
|
|
150
152
|
}
|
|
151
153
|
};
|
|
152
154
|
const renderCanvas = (page, done, error) => {
|
|
153
|
-
const
|
|
155
|
+
const scaleNum = scale();
|
|
156
|
+
const viewport = page.getViewport({ scale: scaleNum });
|
|
154
157
|
const styles = {
|
|
155
|
-
width: Math.floor(viewport.width /
|
|
156
|
-
height: Math.floor(viewport.height /
|
|
158
|
+
width: Math.floor(viewport.width / scaleNum) + 'pt',
|
|
159
|
+
height: Math.floor(viewport.height / scaleNum) + 'pt'
|
|
157
160
|
};
|
|
158
161
|
const pageElement = createElement('div', '', styles);
|
|
159
162
|
const canvas = createElement('canvas', '', {
|
|
@@ -166,7 +169,7 @@ const renderCanvas = (page, done, error) => {
|
|
|
166
169
|
pageElement.appendChild(canvas);
|
|
167
170
|
page.render({ canvasContext, viewport })
|
|
168
171
|
.promise.then(() => {
|
|
169
|
-
const printContent = new Image(Math.floor((viewport.width /
|
|
172
|
+
const printContent = new Image(Math.floor((viewport.width / scaleNum)), Math.floor((viewport.height / scaleNum)));
|
|
170
173
|
printContent.src = canvas.toDataURL();
|
|
171
174
|
pageElement.removeChild(canvas);
|
|
172
175
|
pageElement.appendChild(printContent);
|
|
@@ -188,10 +191,11 @@ const createElement = function (name, className, styles) {
|
|
|
188
191
|
return element;
|
|
189
192
|
};
|
|
190
193
|
const renderPage = (page, zoom, error) => {
|
|
191
|
-
const
|
|
194
|
+
const scaleNum = scale();
|
|
195
|
+
const viewport = page.getViewport({ scale: scaleNum });
|
|
192
196
|
const styles = {
|
|
193
|
-
width: (Math.floor(viewport.width /
|
|
194
|
-
height: (Math.floor(viewport.height /
|
|
197
|
+
width: (Math.floor(viewport.width / scaleNum) * zoom) + 'pt',
|
|
198
|
+
height: (Math.floor(viewport.height / scaleNum) * zoom) + 'pt'
|
|
195
199
|
};
|
|
196
200
|
const pageElement = createElement('div', 'k-page', styles);
|
|
197
201
|
const canvas = createElement('canvas', '', {
|
|
@@ -213,6 +217,13 @@ const renderPage = (page, zoom, error) => {
|
|
|
213
217
|
textDivs: []
|
|
214
218
|
})
|
|
215
219
|
.promise.then(() => {
|
|
220
|
+
textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
|
|
221
|
+
textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
|
|
222
|
+
textLayer.querySelectorAll('span').forEach((el) => {
|
|
223
|
+
if (el.style.fontSize) {
|
|
224
|
+
el.style.fontSize = el.style.fontSize.replace(/px/g, 'pt');
|
|
225
|
+
}
|
|
226
|
+
});
|
|
216
227
|
pageElement.appendChild(textLayer);
|
|
217
228
|
})
|
|
218
229
|
.catch(error);
|