コード例 #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();
 }
コード例 #2
0
ファイル: PdfPrintJob.uwp.cs プロジェクト: haword/Printing
        /// <summary>
        /// Cache printable output
        /// </summary>
        /// <param name="p">Number of first page to print</param>
        /// <param name="count">Number of pages to print</param>
        /// <returns>Task that the caller is expected to await</returns>
        private async Task PrepareForPrintAsync(int p, int count /*, StorageFolder tempfolder*/)
        {
            if ((_pageImages is null) || (_pageImages.Count == 0))
            {
                ClearCachedPages();
                _pageImages = new List <Windows.UI.Xaml.Controls.Image>();
                _           = new Windows.UI.Xaml.Controls.Image();
                for (int i = p; i < count; i++)
                {
                    ApplicationLanguages.PrimaryLanguageOverride =
                        CultureInfo.InvariantCulture.TwoLetterISOLanguageName;
                    Windows.Data.Pdf.PdfPage pdfPage = _pdfDocument.GetPage(uint.Parse(i.ToString()));
                    double pdfPagePreferredZoom      = pdfPage.PreferredZoom;
                    IRandomAccessStream randomStream = new InMemoryRandomAccessStream();
                    global::Windows.Data.Pdf.PdfPageRenderOptions pdfPageRenderOptions =
                        new global::Windows.Data.Pdf.PdfPageRenderOptions();
                    Windows.Foundation.Size pdfPageSize = pdfPage.Size;
                    pdfPageRenderOptions.DestinationHeight = (uint)(pdfPageSize.Height * pdfPagePreferredZoom);
                    pdfPageRenderOptions.DestinationWidth  = (uint)(pdfPageSize.Width * pdfPagePreferredZoom);
                    await pdfPage.RenderToStreamAsync(randomStream, pdfPageRenderOptions);

                    Windows.UI.Xaml.Controls.Image imageCtrl = new Windows.UI.Xaml.Controls.Image();
                    BitmapImage src = new BitmapImage();
                    randomStream.Seek(0);
                    src.SetSource(randomStream);
                    imageCtrl.Source = src;
                    Windows.Graphics.Display.DisplayInformation DisplayInformation = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();

                    float dpi = DisplayInformation.LogicalDpi / 96;
                    imageCtrl.Height = src.PixelHeight / dpi;
                    imageCtrl.Width  = src.PixelWidth / dpi;
                    randomStream.Dispose();
                    pdfPage.Dispose();

                    _pageImages.Add(imageCtrl);
                    AddPageToCache(imageCtrl);
                }
            }
        }
コード例 #3
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);
            }
        }