@@ -1057,31 +1057,40 @@ class AnnotationProcessing extends Component {
1057
1057
onPress = { async ( ) => {
1058
1058
const processedDocumentPath =
1059
1059
RNFS . DocumentDirectoryPath + "/embedded.pdf" ;
1060
- // First, save all annotations in the current document.
1061
- await this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1062
- if ( success ) {
1063
- // Then, embed all the annotations
1064
- PSPDFKit . processAnnotations (
1065
- "embed" ,
1066
- "all" ,
1067
- sourceDocumentPath ,
1068
- processedDocumentPath
1069
- )
1070
- . then ( success => {
1071
- if ( success ) {
1072
- // And finally, present the newly processed document with embedded annotations.
1073
- PSPDFKit . present ( processedDocumentPath , { } ) ;
1074
- } else {
1075
- alert ( "Failed to embed annotations." ) ;
1076
- }
1077
- } )
1078
- . catch ( error => {
1079
- alert ( JSON . stringify ( error ) ) ;
1080
- } ) ;
1081
- } else {
1082
- alert ( "Failed to save current document." ) ;
1083
- }
1084
- } ) ;
1060
+ // Delete the processed document if it already exists.
1061
+ RNFS . exists ( processedDocumentPath )
1062
+ . then ( exists => {
1063
+ if ( exists ) {
1064
+ RNFS . unlink ( processedDocumentPath ) ;
1065
+ }
1066
+ } )
1067
+ // First, save all annotations in the current document.
1068
+ . then ( ( ) => {
1069
+ this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1070
+ if ( success ) {
1071
+ // Then, embed all the annotations
1072
+ PSPDFKit . processAnnotations (
1073
+ "embed" ,
1074
+ "all" ,
1075
+ sourceDocumentPath ,
1076
+ processedDocumentPath
1077
+ )
1078
+ . then ( success => {
1079
+ if ( success ) {
1080
+ // And finally, present the newly processed document with embedded annotations.
1081
+ PSPDFKit . present ( processedDocumentPath , { } ) ;
1082
+ } else {
1083
+ alert ( "Failed to embed annotations." ) ;
1084
+ }
1085
+ } )
1086
+ . catch ( error => {
1087
+ alert ( JSON . stringify ( error ) ) ;
1088
+ } ) ;
1089
+ } else {
1090
+ alert ( "Failed to save current document." ) ;
1091
+ }
1092
+ } ) ;
1093
+ } ) ;
1085
1094
} }
1086
1095
title = "Embed All Annotations"
1087
1096
/>
@@ -1091,31 +1100,40 @@ class AnnotationProcessing extends Component {
1091
1100
onPress = { async ( ) => {
1092
1101
const processedDocumentPath =
1093
1102
RNFS . DocumentDirectoryPath + "/flattened.pdf" ;
1094
- // First, save all annotations in the current document.
1095
- await this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1096
- if ( success ) {
1097
- // Then, flatten all the annotations
1098
- PSPDFKit . processAnnotations (
1099
- "flatten" ,
1100
- "all" ,
1101
- sourceDocumentPath ,
1102
- processedDocumentPath
1103
- )
1104
- . then ( success => {
1105
- if ( success ) {
1106
- // And finally, present the newly processed document with flattened annotations.
1107
- PSPDFKit . present ( processedDocumentPath , { } ) ;
1108
- } else {
1109
- alert ( "Failed to embed annotations." ) ;
1110
- }
1111
- } )
1112
- . catch ( error => {
1113
- alert ( JSON . stringify ( error ) ) ;
1114
- } ) ;
1115
- } else {
1116
- alert ( "Failed to save current document." ) ;
1117
- }
1118
- } ) ;
1103
+ // Delete the processed document if it already exists.
1104
+ RNFS . exists ( processedDocumentPath )
1105
+ . then ( exists => {
1106
+ if ( exists ) {
1107
+ RNFS . unlink ( processedDocumentPath ) ;
1108
+ }
1109
+ } )
1110
+ . then ( ( ) => {
1111
+ // First, save all annotations in the current document.
1112
+ this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1113
+ if ( success ) {
1114
+ // Then, flatten all the annotations
1115
+ PSPDFKit . processAnnotations (
1116
+ "flatten" ,
1117
+ "all" ,
1118
+ sourceDocumentPath ,
1119
+ processedDocumentPath
1120
+ )
1121
+ . then ( success => {
1122
+ if ( success ) {
1123
+ // And finally, present the newly processed document with flattened annotations.
1124
+ PSPDFKit . present ( processedDocumentPath , { } ) ;
1125
+ } else {
1126
+ alert ( "Failed to embed annotations." ) ;
1127
+ }
1128
+ } )
1129
+ . catch ( error => {
1130
+ alert ( JSON . stringify ( error ) ) ;
1131
+ } ) ;
1132
+ } else {
1133
+ alert ( "Failed to save current document." ) ;
1134
+ }
1135
+ } ) ;
1136
+ } ) ;
1119
1137
} }
1120
1138
title = "Flatten All Annotations"
1121
1139
/>
@@ -1125,31 +1143,40 @@ class AnnotationProcessing extends Component {
1125
1143
onPress = { async ( ) => {
1126
1144
const processedDocumentPath =
1127
1145
RNFS . DocumentDirectoryPath + "/removed.pdf" ;
1128
- // First, save all annotations in the current document.
1129
- await this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1130
- if ( success ) {
1131
- // Then, remove all the annotations
1132
- PSPDFKit . processAnnotations (
1133
- "remove" ,
1134
- "all" ,
1135
- sourceDocumentPath ,
1136
- processedDocumentPath
1137
- )
1138
- . then ( success => {
1139
- if ( success ) {
1140
- // And finally, present the newly processed document with removed annotations.
1141
- PSPDFKit . present ( processedDocumentPath , { } ) ;
1142
- } else {
1143
- alert ( "Failed to remove annotations." ) ;
1144
- }
1145
- } )
1146
- . catch ( error => {
1147
- alert ( JSON . stringify ( error ) ) ;
1148
- } ) ;
1149
- } else {
1150
- alert ( "Failed to save current document." ) ;
1151
- }
1152
- } ) ;
1146
+ // Delete the processed document if it already exists.
1147
+ RNFS . exists ( processedDocumentPath )
1148
+ . then ( exists => {
1149
+ if ( exists ) {
1150
+ RNFS . unlink ( processedDocumentPath ) ;
1151
+ }
1152
+ } )
1153
+ . then ( ( ) => {
1154
+ // First, save all annotations in the current document.
1155
+ this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1156
+ if ( success ) {
1157
+ // Then, remove all the annotations
1158
+ PSPDFKit . processAnnotations (
1159
+ "remove" ,
1160
+ "all" ,
1161
+ sourceDocumentPath ,
1162
+ processedDocumentPath
1163
+ )
1164
+ . then ( success => {
1165
+ if ( success ) {
1166
+ // And finally, present the newly processed document with removed annotations.
1167
+ PSPDFKit . present ( processedDocumentPath , { } ) ;
1168
+ } else {
1169
+ alert ( "Failed to remove annotations." ) ;
1170
+ }
1171
+ } )
1172
+ . catch ( error => {
1173
+ alert ( JSON . stringify ( error ) ) ;
1174
+ } ) ;
1175
+ } else {
1176
+ alert ( "Failed to save current document." ) ;
1177
+ }
1178
+ } ) ;
1179
+ } ) ;
1153
1180
} }
1154
1181
title = "Remove All Annotations"
1155
1182
/>
@@ -1159,31 +1186,40 @@ class AnnotationProcessing extends Component {
1159
1186
onPress = { async ( ) => {
1160
1187
const processedDocumentPath =
1161
1188
RNFS . DocumentDirectoryPath + "/printed.pdf" ;
1162
- // First, save all annotations in the current document.
1163
- await this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1164
- if ( success ) {
1165
- // Then, print all the annotations
1166
- PSPDFKit . processAnnotations (
1167
- "print" ,
1168
- "all" ,
1169
- sourceDocumentPath ,
1170
- processedDocumentPath
1171
- )
1172
- . then ( success => {
1173
- if ( success ) {
1174
- // And finally, present the newly processed document with printed annotations.
1175
- PSPDFKit . present ( processedDocumentPath , { } ) ;
1176
- } else {
1177
- alert ( "Failed to print annotations." ) ;
1178
- }
1179
- } )
1180
- . catch ( error => {
1181
- alert ( JSON . stringify ( error ) ) ;
1182
- } ) ;
1183
- } else {
1184
- alert ( "Failed to save current document." ) ;
1185
- }
1186
- } ) ;
1189
+ // Delete the processed document if it already exists.
1190
+ RNFS . exists ( processedDocumentPath )
1191
+ . then ( exists => {
1192
+ if ( exists ) {
1193
+ RNFS . unlink ( processedDocumentPath ) ;
1194
+ }
1195
+ } )
1196
+ . then ( ( ) => {
1197
+ // First, save all annotations in the current document.
1198
+ this . refs . pdfView . saveCurrentDocument ( ) . then ( success => {
1199
+ if ( success ) {
1200
+ // Then, print all the annotations
1201
+ PSPDFKit . processAnnotations (
1202
+ "print" ,
1203
+ "all" ,
1204
+ sourceDocumentPath ,
1205
+ processedDocumentPath
1206
+ )
1207
+ . then ( success => {
1208
+ if ( success ) {
1209
+ // And finally, present the newly processed document with printed annotations.
1210
+ PSPDFKit . present ( processedDocumentPath , { } ) ;
1211
+ } else {
1212
+ alert ( "Failed to print annotations." ) ;
1213
+ }
1214
+ } )
1215
+ . catch ( error => {
1216
+ alert ( JSON . stringify ( error ) ) ;
1217
+ } ) ;
1218
+ } else {
1219
+ alert ( "Failed to save current document." ) ;
1220
+ }
1221
+ } ) ;
1222
+ } ) ;
1187
1223
} }
1188
1224
title = "Print All Annotations"
1189
1225
/>
0 commit comments