@progress/kendo-pdfviewer-common 0.5.0 → 0.6.0-develop.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/widget/page.js +6 -7
- package/dist/es/widget/pdfviewer.js +74 -42
- package/dist/es2015/widget/page.js +6 -7
- package/dist/es2015/widget/pdfviewer.js +74 -42
- package/dist/npm/widget/page.js +6 -7
- package/dist/npm/widget/pdfviewer.d.ts +5 -0
- package/dist/npm/widget/pdfviewer.js +74 -42
- package/package.json +1 -1
package/dist/es/widget/page.js
CHANGED
|
@@ -163,9 +163,8 @@ export class Page extends Component {
|
|
|
163
163
|
const canvas = this.canvasForPrint;
|
|
164
164
|
const printContentLoadPromise = this.createPromise();
|
|
165
165
|
const printContent = new Image();
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const pageWidth = Math.floor(viewportRawDimensions.pageWidth);
|
|
166
|
+
const pageHeight = canvas.height;
|
|
167
|
+
const pageWidth = canvas.width;
|
|
169
168
|
printContent.src = canvas.toDataURL();
|
|
170
169
|
printContent.width = pageWidth;
|
|
171
170
|
printContent.height = pageHeight;
|
|
@@ -211,14 +210,14 @@ export class Page extends Component {
|
|
|
211
210
|
renderForPrintAsync() {
|
|
212
211
|
var _a, _b;
|
|
213
212
|
const printUnits = this.pdfViewer.getPrintUnits();
|
|
213
|
+
// this is how pdf.js prints
|
|
214
|
+
const printScale = 1;
|
|
214
215
|
const { canvasContext, canvas } = this.pdfViewer.createPageElements({
|
|
215
216
|
pdfPage: this.pdfPage,
|
|
216
|
-
zoom:
|
|
217
|
+
zoom: printScale,
|
|
217
218
|
printUnits
|
|
218
219
|
});
|
|
219
220
|
this.canvasForPrint = canvas;
|
|
220
|
-
// canvasWrapper.appendChild(canvas);
|
|
221
|
-
// pageElement.appendChild(canvasWrapper);
|
|
222
221
|
this.setState({
|
|
223
222
|
isPrintingInProgress: true
|
|
224
223
|
});
|
|
@@ -228,7 +227,7 @@ export class Page extends Component {
|
|
|
228
227
|
const renderContext = {
|
|
229
228
|
canvasContext: canvasContext,
|
|
230
229
|
transform: [printUnits, 0, 0, printUnits, 0, 0],
|
|
231
|
-
viewport: this.pdfPage.getViewport({ scale:
|
|
230
|
+
viewport: this.pdfPage.getViewport({ scale: printScale, rotation: this.viewport.rotation }),
|
|
232
231
|
intent: "print",
|
|
233
232
|
annotationMode: AnnotationMode.ENABLE_STORAGE,
|
|
234
233
|
optionalContentConfigPromise,
|
|
@@ -935,61 +935,84 @@ export class PdfViewer extends Component {
|
|
|
935
935
|
}
|
|
936
936
|
downloadDocument({ options, fileName = "Document", saveOptions = {} }) {
|
|
937
937
|
if (options.pdf) {
|
|
938
|
-
|
|
939
|
-
let serializedAnnotationStorage = {};
|
|
940
|
-
let originalAnnotationStorage = {};
|
|
941
|
-
if (options.pdf.annotationStorage.size > 0) {
|
|
942
|
-
exportMethod = options.pdf.saveDocument.bind(options.pdf);
|
|
943
|
-
// saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
|
|
944
|
-
// because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
|
|
945
|
-
// thus replace instances of editors with their serialized version
|
|
946
|
-
// and then revert
|
|
947
|
-
serializedAnnotationStorage = {};
|
|
948
|
-
originalAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
949
|
-
// With the form filling functionality enabled, values could be coming as pure JSON objects,
|
|
950
|
-
// thus the additional assertion.
|
|
951
|
-
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
952
|
-
var _a;
|
|
953
|
-
if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
|
|
954
|
-
serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
|
|
955
|
-
}
|
|
956
|
-
else {
|
|
957
|
-
serializedAnnotationStorage[key] = originalAnnotationStorage[key];
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
961
|
-
options.pdf.annotationStorage.remove(key);
|
|
962
|
-
});
|
|
963
|
-
Object.keys(serializedAnnotationStorage).forEach((key) => {
|
|
964
|
-
options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
exportMethod()
|
|
938
|
+
this.extractPdfData(options)
|
|
968
939
|
.then((data) => {
|
|
940
|
+
if (!data) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
969
943
|
return new Blob([data], { type: 'application/pdf' });
|
|
970
944
|
})
|
|
971
945
|
.then((blob) => {
|
|
972
|
-
if (!this.triggerDownload({ blob, fileName, saveOptions })) {
|
|
946
|
+
if (blob && !this.triggerDownload({ blob, fileName, saveOptions })) {
|
|
973
947
|
this.saveFile(blob, fileName, saveOptions);
|
|
974
948
|
}
|
|
975
949
|
})
|
|
976
950
|
.catch((e) => {
|
|
977
951
|
this.triggerError(e);
|
|
978
|
-
})
|
|
979
|
-
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
getFileAsByteArray() {
|
|
956
|
+
return this.extractPdfData({
|
|
957
|
+
options: {
|
|
958
|
+
pdf: this.state.pdfDocument
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
extractPdfData(options) {
|
|
963
|
+
if (!options.pdf) {
|
|
964
|
+
return Promise.resolve(null);
|
|
965
|
+
}
|
|
966
|
+
let exportMethod = options.pdf.getData.bind(options.pdf);
|
|
967
|
+
let serializedAnnotationStorage = {};
|
|
968
|
+
let originalAnnotationStorage = {};
|
|
969
|
+
if (options.pdf.annotationStorage.size > 0) {
|
|
970
|
+
exportMethod = options.pdf.saveDocument.bind(options.pdf);
|
|
971
|
+
// saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
|
|
972
|
+
// because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
|
|
973
|
+
// thus replace instances of editors with their serialized version
|
|
974
|
+
// and then revert
|
|
975
|
+
serializedAnnotationStorage = {};
|
|
976
|
+
originalAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
977
|
+
// With the form filling functionality enabled, values could be coming as pure JSON objects,
|
|
978
|
+
// thus the additional assertion.
|
|
979
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
980
980
|
var _a;
|
|
981
|
-
if (((_a =
|
|
982
|
-
|
|
981
|
+
if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
|
|
982
|
+
serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
|
|
983
983
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
984
|
+
else {
|
|
985
|
+
serializedAnnotationStorage[key] = originalAnnotationStorage[key];
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
989
|
+
options.pdf.annotationStorage.remove(key);
|
|
990
|
+
});
|
|
991
|
+
Object.keys(serializedAnnotationStorage).forEach((key) => {
|
|
992
|
+
options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
|
|
991
993
|
});
|
|
992
994
|
}
|
|
995
|
+
return exportMethod()
|
|
996
|
+
.then((data) => {
|
|
997
|
+
return data;
|
|
998
|
+
})
|
|
999
|
+
.catch((e) => {
|
|
1000
|
+
this.triggerError(e);
|
|
1001
|
+
return null;
|
|
1002
|
+
})
|
|
1003
|
+
.finally(() => {
|
|
1004
|
+
var _a;
|
|
1005
|
+
if (((_a = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
1009
|
+
Object.keys(currentAnnotationStorage).forEach((key) => {
|
|
1010
|
+
options.pdf.annotationStorage.remove(key);
|
|
1011
|
+
});
|
|
1012
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
1013
|
+
options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
993
1016
|
}
|
|
994
1017
|
saveFile(blob, fileName, saveOptions) {
|
|
995
1018
|
try {
|
|
@@ -1408,6 +1431,15 @@ export class PdfViewer extends Component {
|
|
|
1408
1431
|
setAnnotationEditorMode(modeDescriptor) {
|
|
1409
1432
|
this.annotationEditorMode = modeDescriptor;
|
|
1410
1433
|
}
|
|
1434
|
+
setAnnotationMode(mode) {
|
|
1435
|
+
__classPrivateFieldSet(this, _PdfViewer_annotationMode, mode, "f");
|
|
1436
|
+
}
|
|
1437
|
+
setEditAnnotationMode() {
|
|
1438
|
+
__classPrivateFieldSet(this, _PdfViewer_annotationMode, AnnotationMode.ENABLE_FORMS, "f");
|
|
1439
|
+
}
|
|
1440
|
+
resetAnnotationMode() {
|
|
1441
|
+
__classPrivateFieldSet(this, _PdfViewer_annotationMode, AnnotationMode.ENABLE, "f");
|
|
1442
|
+
}
|
|
1411
1443
|
setFreeTextColor(color) {
|
|
1412
1444
|
this.executeAnnotationCommand({
|
|
1413
1445
|
commandType: AnnotationEditorParamsType.FREETEXT_COLOR,
|
|
@@ -163,9 +163,8 @@ export class Page extends Component {
|
|
|
163
163
|
const canvas = this.canvasForPrint;
|
|
164
164
|
const printContentLoadPromise = this.createPromise();
|
|
165
165
|
const printContent = new Image();
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const pageWidth = Math.floor(viewportRawDimensions.pageWidth);
|
|
166
|
+
const pageHeight = canvas.height;
|
|
167
|
+
const pageWidth = canvas.width;
|
|
169
168
|
printContent.src = canvas.toDataURL();
|
|
170
169
|
printContent.width = pageWidth;
|
|
171
170
|
printContent.height = pageHeight;
|
|
@@ -211,14 +210,14 @@ export class Page extends Component {
|
|
|
211
210
|
renderForPrintAsync() {
|
|
212
211
|
var _a, _b;
|
|
213
212
|
const printUnits = this.pdfViewer.getPrintUnits();
|
|
213
|
+
// this is how pdf.js prints
|
|
214
|
+
const printScale = 1;
|
|
214
215
|
const { canvasContext, canvas } = this.pdfViewer.createPageElements({
|
|
215
216
|
pdfPage: this.pdfPage,
|
|
216
|
-
zoom:
|
|
217
|
+
zoom: printScale,
|
|
217
218
|
printUnits
|
|
218
219
|
});
|
|
219
220
|
this.canvasForPrint = canvas;
|
|
220
|
-
// canvasWrapper.appendChild(canvas);
|
|
221
|
-
// pageElement.appendChild(canvasWrapper);
|
|
222
221
|
this.setState({
|
|
223
222
|
isPrintingInProgress: true
|
|
224
223
|
});
|
|
@@ -228,7 +227,7 @@ export class Page extends Component {
|
|
|
228
227
|
const renderContext = {
|
|
229
228
|
canvasContext: canvasContext,
|
|
230
229
|
transform: [printUnits, 0, 0, printUnits, 0, 0],
|
|
231
|
-
viewport: this.pdfPage.getViewport({ scale:
|
|
230
|
+
viewport: this.pdfPage.getViewport({ scale: printScale, rotation: this.viewport.rotation }),
|
|
232
231
|
intent: "print",
|
|
233
232
|
annotationMode: AnnotationMode.ENABLE_STORAGE,
|
|
234
233
|
optionalContentConfigPromise,
|
|
@@ -935,61 +935,84 @@ export class PdfViewer extends Component {
|
|
|
935
935
|
}
|
|
936
936
|
downloadDocument({ options, fileName = "Document", saveOptions = {} }) {
|
|
937
937
|
if (options.pdf) {
|
|
938
|
-
|
|
939
|
-
let serializedAnnotationStorage = {};
|
|
940
|
-
let originalAnnotationStorage = {};
|
|
941
|
-
if (options.pdf.annotationStorage.size > 0) {
|
|
942
|
-
exportMethod = options.pdf.saveDocument.bind(options.pdf);
|
|
943
|
-
// saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
|
|
944
|
-
// because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
|
|
945
|
-
// thus replace instances of editors with their serialized version
|
|
946
|
-
// and then revert
|
|
947
|
-
serializedAnnotationStorage = {};
|
|
948
|
-
originalAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
949
|
-
// With the form filling functionality enabled, values could be coming as pure JSON objects,
|
|
950
|
-
// thus the additional assertion.
|
|
951
|
-
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
952
|
-
var _a;
|
|
953
|
-
if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
|
|
954
|
-
serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
|
|
955
|
-
}
|
|
956
|
-
else {
|
|
957
|
-
serializedAnnotationStorage[key] = originalAnnotationStorage[key];
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
961
|
-
options.pdf.annotationStorage.remove(key);
|
|
962
|
-
});
|
|
963
|
-
Object.keys(serializedAnnotationStorage).forEach((key) => {
|
|
964
|
-
options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
exportMethod()
|
|
938
|
+
this.extractPdfData(options)
|
|
968
939
|
.then((data) => {
|
|
940
|
+
if (!data) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
969
943
|
return new Blob([data], { type: 'application/pdf' });
|
|
970
944
|
})
|
|
971
945
|
.then((blob) => {
|
|
972
|
-
if (!this.triggerDownload({ blob, fileName, saveOptions })) {
|
|
946
|
+
if (blob && !this.triggerDownload({ blob, fileName, saveOptions })) {
|
|
973
947
|
this.saveFile(blob, fileName, saveOptions);
|
|
974
948
|
}
|
|
975
949
|
})
|
|
976
950
|
.catch((e) => {
|
|
977
951
|
this.triggerError(e);
|
|
978
|
-
})
|
|
979
|
-
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
getFileAsByteArray() {
|
|
956
|
+
return this.extractPdfData({
|
|
957
|
+
options: {
|
|
958
|
+
pdf: this.state.pdfDocument
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
extractPdfData(options) {
|
|
963
|
+
if (!options.pdf) {
|
|
964
|
+
return Promise.resolve(null);
|
|
965
|
+
}
|
|
966
|
+
let exportMethod = options.pdf.getData.bind(options.pdf);
|
|
967
|
+
let serializedAnnotationStorage = {};
|
|
968
|
+
let originalAnnotationStorage = {};
|
|
969
|
+
if (options.pdf.annotationStorage.size > 0) {
|
|
970
|
+
exportMethod = options.pdf.saveDocument.bind(options.pdf);
|
|
971
|
+
// saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
|
|
972
|
+
// because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
|
|
973
|
+
// thus replace instances of editors with their serialized version
|
|
974
|
+
// and then revert
|
|
975
|
+
serializedAnnotationStorage = {};
|
|
976
|
+
originalAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
977
|
+
// With the form filling functionality enabled, values could be coming as pure JSON objects,
|
|
978
|
+
// thus the additional assertion.
|
|
979
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
980
980
|
var _a;
|
|
981
|
-
if (((_a =
|
|
982
|
-
|
|
981
|
+
if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
|
|
982
|
+
serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
|
|
983
983
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
984
|
+
else {
|
|
985
|
+
serializedAnnotationStorage[key] = originalAnnotationStorage[key];
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
989
|
+
options.pdf.annotationStorage.remove(key);
|
|
990
|
+
});
|
|
991
|
+
Object.keys(serializedAnnotationStorage).forEach((key) => {
|
|
992
|
+
options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
|
|
991
993
|
});
|
|
992
994
|
}
|
|
995
|
+
return exportMethod()
|
|
996
|
+
.then((data) => {
|
|
997
|
+
return data;
|
|
998
|
+
})
|
|
999
|
+
.catch((e) => {
|
|
1000
|
+
this.triggerError(e);
|
|
1001
|
+
return null;
|
|
1002
|
+
})
|
|
1003
|
+
.finally(() => {
|
|
1004
|
+
var _a;
|
|
1005
|
+
if (((_a = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
1009
|
+
Object.keys(currentAnnotationStorage).forEach((key) => {
|
|
1010
|
+
options.pdf.annotationStorage.remove(key);
|
|
1011
|
+
});
|
|
1012
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
1013
|
+
options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
993
1016
|
}
|
|
994
1017
|
saveFile(blob, fileName, saveOptions) {
|
|
995
1018
|
try {
|
|
@@ -1408,6 +1431,15 @@ export class PdfViewer extends Component {
|
|
|
1408
1431
|
setAnnotationEditorMode(modeDescriptor) {
|
|
1409
1432
|
this.annotationEditorMode = modeDescriptor;
|
|
1410
1433
|
}
|
|
1434
|
+
setAnnotationMode(mode) {
|
|
1435
|
+
__classPrivateFieldSet(this, _PdfViewer_annotationMode, mode, "f");
|
|
1436
|
+
}
|
|
1437
|
+
setEditAnnotationMode() {
|
|
1438
|
+
__classPrivateFieldSet(this, _PdfViewer_annotationMode, AnnotationMode.ENABLE_FORMS, "f");
|
|
1439
|
+
}
|
|
1440
|
+
resetAnnotationMode() {
|
|
1441
|
+
__classPrivateFieldSet(this, _PdfViewer_annotationMode, AnnotationMode.ENABLE, "f");
|
|
1442
|
+
}
|
|
1411
1443
|
setFreeTextColor(color) {
|
|
1412
1444
|
this.executeAnnotationCommand({
|
|
1413
1445
|
commandType: AnnotationEditorParamsType.FREETEXT_COLOR,
|
package/dist/npm/widget/page.js
CHANGED
|
@@ -163,9 +163,8 @@ class Page extends component_1.Component {
|
|
|
163
163
|
const canvas = this.canvasForPrint;
|
|
164
164
|
const printContentLoadPromise = this.createPromise();
|
|
165
165
|
const printContent = new Image();
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const pageWidth = Math.floor(viewportRawDimensions.pageWidth);
|
|
166
|
+
const pageHeight = canvas.height;
|
|
167
|
+
const pageWidth = canvas.width;
|
|
169
168
|
printContent.src = canvas.toDataURL();
|
|
170
169
|
printContent.width = pageWidth;
|
|
171
170
|
printContent.height = pageHeight;
|
|
@@ -211,14 +210,14 @@ class Page extends component_1.Component {
|
|
|
211
210
|
renderForPrintAsync() {
|
|
212
211
|
var _a, _b;
|
|
213
212
|
const printUnits = this.pdfViewer.getPrintUnits();
|
|
213
|
+
// this is how pdf.js prints
|
|
214
|
+
const printScale = 1;
|
|
214
215
|
const { canvasContext, canvas } = this.pdfViewer.createPageElements({
|
|
215
216
|
pdfPage: this.pdfPage,
|
|
216
|
-
zoom:
|
|
217
|
+
zoom: printScale,
|
|
217
218
|
printUnits
|
|
218
219
|
});
|
|
219
220
|
this.canvasForPrint = canvas;
|
|
220
|
-
// canvasWrapper.appendChild(canvas);
|
|
221
|
-
// pageElement.appendChild(canvasWrapper);
|
|
222
221
|
this.setState({
|
|
223
222
|
isPrintingInProgress: true
|
|
224
223
|
});
|
|
@@ -228,7 +227,7 @@ class Page extends component_1.Component {
|
|
|
228
227
|
const renderContext = {
|
|
229
228
|
canvasContext: canvasContext,
|
|
230
229
|
transform: [printUnits, 0, 0, printUnits, 0, 0],
|
|
231
|
-
viewport: this.pdfPage.getViewport({ scale:
|
|
230
|
+
viewport: this.pdfPage.getViewport({ scale: printScale, rotation: this.viewport.rotation }),
|
|
232
231
|
intent: "print",
|
|
233
232
|
annotationMode: pdf_mjs_1.AnnotationMode.ENABLE_STORAGE,
|
|
234
233
|
optionalContentConfigPromise,
|
|
@@ -134,6 +134,8 @@ export declare class PdfViewer extends Component {
|
|
|
134
134
|
fileName?: string;
|
|
135
135
|
saveOptions?: {};
|
|
136
136
|
}): void;
|
|
137
|
+
getFileAsByteArray(): Promise<Uint8Array | null>;
|
|
138
|
+
private extractPdfData;
|
|
137
139
|
saveFile(blob: Blob, fileName: string, saveOptions: SaveOptions): boolean;
|
|
138
140
|
hasDocument(): boolean;
|
|
139
141
|
zoom(args: any): void;
|
|
@@ -196,6 +198,9 @@ export declare class PdfViewer extends Component {
|
|
|
196
198
|
deleteAnnotation(): void;
|
|
197
199
|
resetAnnotationEditorMode(): void;
|
|
198
200
|
setAnnotationEditorMode(modeDescriptor: any): void;
|
|
201
|
+
setAnnotationMode(mode: any): void;
|
|
202
|
+
setEditAnnotationMode(): void;
|
|
203
|
+
resetAnnotationMode(): void;
|
|
199
204
|
setFreeTextColor(color: any): void;
|
|
200
205
|
setFreeTextFontSize(fontSize: any): void;
|
|
201
206
|
executeAnnotationCommand({ commandType, commandValue }: {
|
|
@@ -938,61 +938,84 @@ class PdfViewer extends main_1.Component {
|
|
|
938
938
|
}
|
|
939
939
|
downloadDocument({ options, fileName = "Document", saveOptions = {} }) {
|
|
940
940
|
if (options.pdf) {
|
|
941
|
-
|
|
942
|
-
let serializedAnnotationStorage = {};
|
|
943
|
-
let originalAnnotationStorage = {};
|
|
944
|
-
if (options.pdf.annotationStorage.size > 0) {
|
|
945
|
-
exportMethod = options.pdf.saveDocument.bind(options.pdf);
|
|
946
|
-
// saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
|
|
947
|
-
// because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
|
|
948
|
-
// thus replace instances of editors with their serialized version
|
|
949
|
-
// and then revert
|
|
950
|
-
serializedAnnotationStorage = {};
|
|
951
|
-
originalAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
952
|
-
// With the form filling functionality enabled, values could be coming as pure JSON objects,
|
|
953
|
-
// thus the additional assertion.
|
|
954
|
-
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
955
|
-
var _a;
|
|
956
|
-
if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
|
|
957
|
-
serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
serializedAnnotationStorage[key] = originalAnnotationStorage[key];
|
|
961
|
-
}
|
|
962
|
-
});
|
|
963
|
-
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
964
|
-
options.pdf.annotationStorage.remove(key);
|
|
965
|
-
});
|
|
966
|
-
Object.keys(serializedAnnotationStorage).forEach((key) => {
|
|
967
|
-
options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
exportMethod()
|
|
941
|
+
this.extractPdfData(options)
|
|
971
942
|
.then((data) => {
|
|
943
|
+
if (!data) {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
972
946
|
return new Blob([data], { type: 'application/pdf' });
|
|
973
947
|
})
|
|
974
948
|
.then((blob) => {
|
|
975
|
-
if (!this.triggerDownload({ blob, fileName, saveOptions })) {
|
|
949
|
+
if (blob && !this.triggerDownload({ blob, fileName, saveOptions })) {
|
|
976
950
|
this.saveFile(blob, fileName, saveOptions);
|
|
977
951
|
}
|
|
978
952
|
})
|
|
979
953
|
.catch((e) => {
|
|
980
954
|
this.triggerError(e);
|
|
981
|
-
})
|
|
982
|
-
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
getFileAsByteArray() {
|
|
959
|
+
return this.extractPdfData({
|
|
960
|
+
options: {
|
|
961
|
+
pdf: this.state.pdfDocument
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
extractPdfData(options) {
|
|
966
|
+
if (!options.pdf) {
|
|
967
|
+
return Promise.resolve(null);
|
|
968
|
+
}
|
|
969
|
+
let exportMethod = options.pdf.getData.bind(options.pdf);
|
|
970
|
+
let serializedAnnotationStorage = {};
|
|
971
|
+
let originalAnnotationStorage = {};
|
|
972
|
+
if (options.pdf.annotationStorage.size > 0) {
|
|
973
|
+
exportMethod = options.pdf.saveDocument.bind(options.pdf);
|
|
974
|
+
// saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
|
|
975
|
+
// because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
|
|
976
|
+
// thus replace instances of editors with their serialized version
|
|
977
|
+
// and then revert
|
|
978
|
+
serializedAnnotationStorage = {};
|
|
979
|
+
originalAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
980
|
+
// With the form filling functionality enabled, values could be coming as pure JSON objects,
|
|
981
|
+
// thus the additional assertion.
|
|
982
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
983
983
|
var _a;
|
|
984
|
-
if (((_a =
|
|
985
|
-
|
|
984
|
+
if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
|
|
985
|
+
serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
|
|
986
986
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
987
|
+
else {
|
|
988
|
+
serializedAnnotationStorage[key] = originalAnnotationStorage[key];
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
992
|
+
options.pdf.annotationStorage.remove(key);
|
|
993
|
+
});
|
|
994
|
+
Object.keys(serializedAnnotationStorage).forEach((key) => {
|
|
995
|
+
options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
|
|
994
996
|
});
|
|
995
997
|
}
|
|
998
|
+
return exportMethod()
|
|
999
|
+
.then((data) => {
|
|
1000
|
+
return data;
|
|
1001
|
+
})
|
|
1002
|
+
.catch((e) => {
|
|
1003
|
+
this.triggerError(e);
|
|
1004
|
+
return null;
|
|
1005
|
+
})
|
|
1006
|
+
.finally(() => {
|
|
1007
|
+
var _a;
|
|
1008
|
+
if (((_a = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
|
|
1012
|
+
Object.keys(currentAnnotationStorage).forEach((key) => {
|
|
1013
|
+
options.pdf.annotationStorage.remove(key);
|
|
1014
|
+
});
|
|
1015
|
+
Object.keys(originalAnnotationStorage).forEach((key) => {
|
|
1016
|
+
options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
996
1019
|
}
|
|
997
1020
|
saveFile(blob, fileName, saveOptions) {
|
|
998
1021
|
try {
|
|
@@ -1411,6 +1434,15 @@ class PdfViewer extends main_1.Component {
|
|
|
1411
1434
|
setAnnotationEditorMode(modeDescriptor) {
|
|
1412
1435
|
this.annotationEditorMode = modeDescriptor;
|
|
1413
1436
|
}
|
|
1437
|
+
setAnnotationMode(mode) {
|
|
1438
|
+
tslib_1.__classPrivateFieldSet(this, _PdfViewer_annotationMode, mode, "f");
|
|
1439
|
+
}
|
|
1440
|
+
setEditAnnotationMode() {
|
|
1441
|
+
tslib_1.__classPrivateFieldSet(this, _PdfViewer_annotationMode, utils_2.AnnotationMode.ENABLE_FORMS, "f");
|
|
1442
|
+
}
|
|
1443
|
+
resetAnnotationMode() {
|
|
1444
|
+
tslib_1.__classPrivateFieldSet(this, _PdfViewer_annotationMode, utils_2.AnnotationMode.ENABLE, "f");
|
|
1445
|
+
}
|
|
1414
1446
|
setFreeTextColor(color) {
|
|
1415
1447
|
this.executeAnnotationCommand({
|
|
1416
1448
|
commandType: pdf_mjs_1.AnnotationEditorParamsType.FREETEXT_COLOR,
|