@progress/kendo-pdfviewer-common 0.5.1-develop.1 → 0.6.0

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.
@@ -935,61 +935,84 @@ export class PdfViewer extends Component {
935
935
  }
936
936
  downloadDocument({ options, fileName = "Document", saveOptions = {} }) {
937
937
  if (options.pdf) {
938
- let exportMethod = options.pdf.getData.bind(options.pdf);
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
- .finally(() => {
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 = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
982
- return;
981
+ if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
982
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
983
+ }
984
+ else {
985
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key];
983
986
  }
984
- const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
985
- Object.keys(currentAnnotationStorage).forEach((key) => {
986
- options.pdf.annotationStorage.remove(key);
987
- });
988
- Object.keys(originalAnnotationStorage).forEach((key) => {
989
- options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
990
- });
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 {
@@ -935,61 +935,84 @@ export class PdfViewer extends Component {
935
935
  }
936
936
  downloadDocument({ options, fileName = "Document", saveOptions = {} }) {
937
937
  if (options.pdf) {
938
- let exportMethod = options.pdf.getData.bind(options.pdf);
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
- .finally(() => {
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 = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
982
- return;
981
+ if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
982
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
983
+ }
984
+ else {
985
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key];
983
986
  }
984
- const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
985
- Object.keys(currentAnnotationStorage).forEach((key) => {
986
- options.pdf.annotationStorage.remove(key);
987
- });
988
- Object.keys(originalAnnotationStorage).forEach((key) => {
989
- options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
990
- });
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 {
@@ -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;
@@ -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
- let exportMethod = options.pdf.getData.bind(options.pdf);
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
- .finally(() => {
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 = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
985
- return;
984
+ if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
985
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
986
+ }
987
+ else {
988
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key];
986
989
  }
987
- const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
988
- Object.keys(currentAnnotationStorage).forEach((key) => {
989
- options.pdf.annotationStorage.remove(key);
990
- });
991
- Object.keys(originalAnnotationStorage).forEach((key) => {
992
- options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
993
- });
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 {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@progress/kendo-pdfviewer-common",
3
3
  "description": "Kendo UI TypeScript package exporting functions for PDFViewer component",
4
- "version": "0.5.1-develop.1",
4
+ "version": "0.6.0",
5
5
  "keywords": [
6
6
  "Kendo UI"
7
7
  ],