private async void ExportDocumentContinueButton_Tapped(object sender, EventArgs e) { await HideExportDocumentLayout(); try { // Delete last saved temp file when user taps on "Share" button (this will contain the zip file path if the shared document // format is SVG, since it doesn't support multipage and the document will be virtual document that consists of multiple documents). if (!string.IsNullOrWhiteSpace(_tempFileToDeleteAfterShare) && File.Exists(_tempFileToDeleteAfterShare)) { File.Delete(_tempFileToDeleteAfterShare); } } catch (Exception) { } if (Document != null && (!_documentAlreadyConverted || (HasAnnotations && IsPdfFormat(SourceDocumentFormat)))) { _shareAfterConversion = true; ConvertDocument(); return; } if (_documentAlreadyConverted) { _tempFileToDeleteAfterShare = await LEADDocumentHelper.ShareDocument(Document, null, OutputDocumentNameLabel.Text); } }
private async void DocumentConverterPage_PageClosing(object sender, DocumentConvertEventArgs e) { string oldDocumentId = _documentViewer.Document.DocumentId; DocumentConvertResult result = e.Results[oldDocumentId]; if (result == null) { return; } try { if (result.Error != null) { await Device.InvokeOnMainThreadAsync(async() => { await DisplayAlert("Error", $"Error converting document: {result.Error.Message}", "OK"); }); } else { if (result.Status != DocumentConverterJobStatus.Aborted) { await Device.InvokeOnMainThreadAsync(async() => { try { Exception error = null; LEADDocument convertedDocument = null; // if we have no documents yet or if we are sharing document and burning annotations into the document then this // document is a temp and we shouldn't update the document viewer with it. if (_documents == null || (_shareAfterConversion && _annotationsMode == DocumentConverterAnnotationsMode.Overlay)) { List <Exception> errors = null; convertedDocument = LEADDocumentHelper.CreateDocument(result.OutputDocumentFiles, null, null, out errors); if (errors != null && errors.Count > 0) { error = errors[0]; } } else { convertedDocument = LEADDocumentHelper.ReplaceDocument(oldDocumentId, result.OutputDocumentFiles, _documents, _documentIndexInList, out error); } if (convertedDocument != null) { if (!(_shareAfterConversion && _annotationsMode == DocumentConverterAnnotationsMode.Overlay)) { SetDocument(null); _documentAlreadyConverted = true; _annObjectsModified = false; // Change the SourceDocumentFormat since we converted the document. SourceDocumentFormat = e.OutputFormat; SetDocument(convertedDocument); Document = _documentViewer.Document; } if (_shareAfterConversion) { _tempFileToDeleteAfterShare = await LEADDocumentHelper.ShareDocument(convertedDocument, null, !string.IsNullOrWhiteSpace(OutputDocumentNameLabel.Text) ? OutputDocumentNameLabel.Text : PageTitle.Text); } } else if (error != null) { await Device.InvokeOnMainThreadAsync(async() => { await DisplayAlert("Error", $"Error converting document: {error.Message}", "OK"); }); } } catch (Exception ex) { await Device.InvokeOnMainThreadAsync(async() => { await DisplayAlert("Error", $"Error converting document: {ex.Message}", "Ok"); }); } }); } } } finally { _annotationsMode = DocumentConverterAnnotationsMode.External; } }