Ejemplo n.º 1
0
 private void DisplayStatus()
 {
     if (PdfDocument == null)
     {
         return;
     }
     tbPagesCount.Text = PdfDocument.PageCount.ToString();
     Windows.Data.Pdf.PdfPage page = PdfDocument.GetPage(0);
     tbDpi.Text = page.Size.Height.ToString();
     page.Dispose();
 }
Ejemplo n.º 2
0
        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;
                }
            }
        }
Ejemplo n.º 3
0
        //ロックじゃない開き方
        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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private async void DisplayImage(int pageIndex, double dpi)
        {
            if (MyPdfDocument == null)
            {
                return;
            }
            MyDpi = dpi;
            using (Windows.Data.Pdf.PdfPage page = MyPdfDocument.GetPage((uint)pageIndex))
            {
                double h       = page.Size.Height;
                var    options = new Windows.Data.Pdf.PdfPageRenderOptions();
                options.DestinationHeight = (uint)Math.Round(page.Size.Height * (dpi / 96.0), MidpointRounding.AwayFromZero);
                tbDpi.Text    = $"dpi : {dpi.ToString()}";
                tbHeight.Text = $"縦ピクセル : {options.DestinationHeight.ToString()}";

                using (var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                {
                    await page.RenderToStreamAsync(stream, options);

                    BitmapImage image = new BitmapImage();
                    image.BeginInit();
                    image.CacheOption  = BitmapCacheOption.OnLoad;
                    image.StreamSource = stream.AsStream();//using System.IOがないとエラーになる
                    image.EndInit();
                    MyImage.Source = image;
                    MyImage.Width  = image.PixelWidth;
                    MyImage.Height = image.PixelHeight;
                }
            }
        }
Ejemplo n.º 5
0
        private async Task <Windows.Storage.Streams.InMemoryRandomAccessStream> RenderPageBitmapAsync()
        {
            using (Windows.Data.Pdf.PdfPage pdfPage = _pdfDoc.GetPage(_currentPageIndex))
            {
                var memStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                await pdfPage.RenderToStreamAsync(memStream);

                return(memStream);
            }
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }