/// <summary> /// Initializes the components of a new PDFModel instance. /// </summary> /// <param name="dataFolder">The folder storing the in-app user data.</param> /// <returns></returns> private async Task InitializeComponents(StorageFolder dataFolder) { // Create backup folder backupFolder = await dataFolder.CreateFolderAsync(BACKUP_FOLDER, CreationCollisionOption.OpenIfExists); // Delete existing backup copies foreach (StorageFile file in await backupFolder.GetFilesAsync()) { try { await file.DeleteAsync(); } catch { } } // Create a backup copy backupFile = await pdfFile.CopyAsync(backupFolder, pdfFile.Name, NameCollisionOption.GenerateUniqueName); sfFile = await pdfFile.CopyAsync(backupFolder, "SF_" + pdfFile.Name, NameCollisionOption.GenerateUniqueName); // Load the file to Microsoft PDF document model // The Microsoft model is used to render the PDF pages. msPdf = await PdfModelMS.LoadFromFile(backupFile); // Return null if failed to load the file to Microsoft model if (msPdf == null) { return; } // Load the file to Syncfusion PDF document model // The Syncfusion model is used to save ink annotations. if (msPdf.IsPasswordProtected) { sfPdf = await PdfModelSF.LoadFromFile(sfFile, msPdf.Password); } else { sfPdf = await PdfModelSF.LoadFromFile(sfFile); } // Return null if failed to load the file to Syncfusion model if (sfPdf == null) { return; } ScaleRatio = sfPdf.GetPage(1).Size.Width / msPdf.GetPage(1).Dimensions.MediaBox.Width; }
public async Task ReloadFile() { msPdf = await PdfModelMS.LoadFromFile(pdfFile); }