private async void ButtonOpenScale_Click(object sender, RoutedEventArgs e) { var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(@"D:\ブログ用\1708_04.pdf"); try { PdfDocument = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(file); } catch (Exception) { } if (PdfDocument != null) { using (Windows.Data.Pdf.PdfPage page = PdfDocument.GetPage(0)) { BitmapImage image = new BitmapImage(); using (var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream()) { var options = new Windows.Data.Pdf.PdfPageRenderOptions(); options.DestinationHeight = 1000; await page.RenderToStreamAsync(stream, options); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.StreamSource = stream.AsStream(); image.EndInit(); } ImagePDF.Source = image; } } }
//ロックじゃない開き方 private async void ButtonFree_Click(object sender, RoutedEventArgs e) { Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(@"D:\ブログ用\1708_04.pdf"); //ここから using (Windows.Storage.Streams.IRandomAccessStream RAStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { Windows.Data.Pdf.PdfDocument MyPdfDocument = await Windows.Data.Pdf.PdfDocument.LoadFromStreamAsync(RAStream); //ここまで using (Windows.Data.Pdf.PdfPage page = MyPdfDocument.GetPage(0)) { using (var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream()) { await page.RenderToStreamAsync(stream); var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.StreamSource = stream.AsStream(); image.EndInit(); MyImage.Source = image; } } } }
private async void LoadPdf(string filePath) { var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(filePath); try { PdfDocument = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(file); } catch (Exception) { } }
private async void LoadPdf(string filePath) { var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(filePath); try { MyPdfDocument = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(file); MyPdfDirectory = System.IO.Path.GetDirectoryName(filePath); MyPdfName = System.IO.Path.GetFileNameWithoutExtension(filePath); MyDpi = 96; DisplayImage(0, 96); tbPageCount.Text = $"ページ数 : {MyPdfDocument.PageCount.ToString()}"; } catch (Exception) { } }
private async void Button_Click_2(object sender, RoutedEventArgs e) { if (txtfile == null || pdffile == null) { await new Windows.UI.Popups.MessageDialog(loader.GetString("error_pleasechoosefilefirst")).ShowAsync(); return; } ct.IsEnabled = false; cp.IsEnabled = false; start.IsEnabled = false; try { Windows.Data.Pdf.PdfDocument pd = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(pdffile); if (pd.IsPasswordProtected) { await new Windows.UI.Popups.MessageDialog(loader.GetString("error_pdfwithpassword")).ShowAsync(); return; } pro.Value = 0; pro.Maximum = pd.PageCount; var ocre = lang == null?OcrEngine.TryCreateFromUserProfileLanguages() : OcrEngine.TryCreateFromLanguage(lang); if (ocre == null && lang == null) { await new Windows.UI.Popups.MessageDialog(loader.GetString("error_notsupport")).ShowAsync(); return; } using (Stream txtstr = await txtfile.OpenStreamForWriteAsync()) { using (StreamWriter sw = new StreamWriter(txtstr)) { for (uint i = 0; i < pd.PageCount; i++) { using (var page = pd.GetPage(i)) { await page.PreparePageAsync(); using (var str = new Windows.Storage.Streams.InMemoryRandomAccessStream()) { await page.RenderToStreamAsync(str); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(str); var re = await ocre.RecognizeAsync(await decoder.GetSoftwareBitmapAsync()); sw.WriteLine(re.Text); } } pro.Value++; } } } } catch { await new Windows.UI.Popups.MessageDialog(loader.GetString("error")).ShowAsync(); } finally { ct.IsEnabled = true; cp.IsEnabled = true; start.IsEnabled = true; txtfile = null; pdffile = null; } }
private async void btnCombinar_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (model.Etiquetas.Count() > 0) { try { model.ScenarioRunning = true; Models.Etiquetas.Etiquetas_GetArchivosBindingModel mdl = new Models.Etiquetas.Etiquetas_GetArchivosBindingModel(); mdl.Aplicacion = model.Aplicacion; mdl.Categoria = model.Categoria; mdl.Etiquetas = model.Etiquetas; long IDArchivo = await Models.EtiquetasModel.Get(mdl); Models.Archivos.Archivos_GetBindingModel model2 = new Models.Archivos.Archivos_GetBindingModel(); model2.ID = IDArchivo; IBuffer buffer = await Models.ArchivosModel.Get(model2); Windows.Data.Pdf.PdfDocument pdf = await Windows.Data.Pdf.PdfDocument.LoadFromStreamAsync(buffer.AsStream().AsRandomAccessStream()); for (uint i = 0; i < pdf.PageCount; i++) { Windows.Data.Pdf.PdfPage page = pdf.GetPage(i); StorageFile bmpFile = await model.DestinationFolder.CreateFileAsync(string.Format("Pagina {0}.bmp", i + 1), CreationCollisionOption.GenerateUniqueName); IRandomAccessStream stream = await bmpFile.OpenAsync(FileAccessMode.ReadWrite); await page.RenderToStreamAsync(stream); await stream.FlushAsync(); stream.Dispose(); page.Dispose(); Utils.SetImageSourceFromFile(bmpFile, DisplayImage); rootPage.NotifyUser("Apertura en progreso...", NotifyType.StatusMessage); Utils.UpdateFileData(bmpFile, model); ScanerListView.SelectedItem = model.FileList.Last(); } rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage); } catch (Exception) { // No pasa nada } finally { model.ScenarioRunning = false; } } else { rootPage.NotifyUser("Debe ingresar primero los datos", NotifyType.ErrorMessage); } }
public async Task <uint> LoadPdfDocumentAsync(Windows.Storage.StorageFile pdfFile) { _pdfDoc = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(pdfFile); return(this.PageCount); }