예제 #1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string pageNumber = "";

            if (NavigationContext.QueryString.TryGetValue("pagenumber", out pageNumber))
            {
                PdfFixedDocument document = (Application.Current as App).Document;

                var t = Task <PdfArgbIntRenderingSurface> .Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer      = new PdfPageRenderer(document.Pages[int.Parse(pageNumber)]);
                    PdfArgbIntRenderingSurface rs = renderer.CreateRenderingSurface <PdfArgbIntRenderingSurface>(96, 96);
                    PdfRendererSettings settings  = new PdfRendererSettings(96, 96, rs);
                    renderer.ConvertPageToImage(settings);

                    return(rs);
                })
                        .ContinueWith(value =>
                {
                    PdfArgbIntRenderingSurface rs = value.Result;
                    WriteableBitmap wb            = new WriteableBitmap(rs.Width, rs.Height);
                    Array.Copy(rs.Bitmap, wb.Pixels, rs.Bitmap.Length);
                    pageImage.Width  = wb.PixelWidth;
                    pageImage.Height = wb.PixelHeight;
                    pageImage.Source = wb;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
예제 #2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string pageNumber = "";
            if (NavigationContext.QueryString.TryGetValue("pagenumber", out pageNumber))
            {
                PdfFixedDocument document = (Application.Current as App).Document;

                var t = Task<PdfArgbIntRenderingSurface>.Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[int.Parse(pageNumber)]);
                    PdfArgbIntRenderingSurface rs = renderer.CreateRenderingSurface<PdfArgbIntRenderingSurface>(96, 96);
                    PdfRendererSettings settings = new PdfRendererSettings(96, 96, rs);
                    renderer.ConvertPageToImage(settings);

                    return rs;
                })
                    .ContinueWith(value =>
                    {
                        PdfArgbIntRenderingSurface rs = value.Result;
                        WriteableBitmap wb = new WriteableBitmap(rs.Width, rs.Height);
                        Array.Copy(rs.Bitmap, wb.Pixels, rs.Bitmap.Length);
                        pageImage.Width = wb.PixelWidth;
                        pageImage.Height = wb.PixelHeight;
                        pageImage.Source = wb;

                    }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
예제 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Assembly asm       = Assembly.GetExecutingAssembly();
            Stream   pdfStream = asm.GetManifestResourceStream("PDFToImage.xfinium.pdf");

            document = new PdfFixedDocument(pdfStream);
            pdfStream.Close();

            Spinner pageNumbers           = FindViewById <Spinner>(Resource.Id.pageNumberSpinner);
            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);

            pageNumbers.Adapter = adapter;
            adapter.Add("Please select a page number");
            for (int i = 1; i <= document.Pages.Count; i++)
            {
                adapter.Add(i.ToString());
            }
            Button button = FindViewById <Button> (Resource.Id.btnConvertToImage);

            button.Click += delegate {
                if ((pageNumbers.SelectedItemPosition >= 1) && (pageNumbers.SelectedItemPosition <= document.Pages.Count))
                {
                    PdfPageRenderer renderer  = new PdfPageRenderer(document.Pages [pageNumbers.SelectedItemPosition - 1]);
                    Bitmap          pageImage = renderer.ConvertPageToImage(96);

                    ImageView pageImageView = FindViewById <ImageView> (Resource.Id.pageImageView);
                    pageImageView.SetImageBitmap(pageImage);
                }
            };
        }
예제 #4
0
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Provides data for navigation methods and event
        /// handlers that cannot cancel the navigation request.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            int pageNumber            = (int)e.Parameter;
            PdfFixedDocument document = (Application.Current as App).Document;

            var t = Task <PdfBgraByteRenderingSurface> .Factory.StartNew(() =>
            {
                PdfPageRenderer renderer       = new PdfPageRenderer(document.Pages[pageNumber]);
                PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface <PdfBgraByteRenderingSurface>(96, 96);
                PdfRendererSettings settings   = new PdfRendererSettings(96, 96, rs);
                renderer.ConvertPageToImage(settings);

                return(rs);
            })
                    .ContinueWith(value =>
            {
                PdfBgraByteRenderingSurface rs = value.Result;
                WriteableBitmap pageBitmap     = new WriteableBitmap(rs.Width, rs.Height);
                Stream imageStream             = pageBitmap.PixelBuffer.AsStream();
                imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);
                pageImage.Width  = pageBitmap.PixelWidth;
                pageImage.Height = pageBitmap.PixelHeight;
                pageImage.Source = pageBitmap;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
예제 #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            Assembly asm = Assembly.GetExecutingAssembly();
            Stream pdfStream = asm.GetManifestResourceStream("PDFToImage.xfinium.pdf");
            document = new PdfFixedDocument (pdfStream);
            pdfStream.Close();

            Spinner pageNumbers = FindViewById<Spinner>(Resource.Id.pageNumberSpinner);
            ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            pageNumbers.Adapter = adapter;
            adapter.Add("Please select a page number");
            for (int i = 1; i <= document.Pages.Count; i++)
            {
                adapter.Add(i.ToString());
            }
            Button button = FindViewById<Button> (Resource.Id.btnConvertToImage);

            button.Click += delegate {
                if ((pageNumbers.SelectedItemPosition >= 1) && (pageNumbers.SelectedItemPosition <= document.Pages.Count))
                {
                    PdfPageRenderer renderer = new PdfPageRenderer (document.Pages [pageNumbers.SelectedItemPosition - 1]);
                    Bitmap pageImage = renderer.ConvertPageToImage (96);

                    ImageView pageImageView = FindViewById<ImageView> (Resource.Id.pageImageView);
                    pageImageView.SetImageBitmap(pageImage);
                }
            };
        }
예제 #6
0
        public static response GenerateImgThumbNail(string sType, string path, string fileName, int width, int height)
        {
            FileInfo fi = new FileInfo(Path.Combine(path, fileName));
            //string outputFile = fileName.Replace(fi.Extension, sType == "s" ? "_s.gif" : "_m.gif");
            string outputFile = fileName.Replace(fi.Extension, "_" + sType + ".jpg");

            switch (fi.Extension.ToLower())
            {
            case ".pdf":
                try
                {
                    FileStream       fs   = new FileStream(Path.Combine(path, fileName), FileMode.Open, FileAccess.Read);
                    PdfFixedDocument pDoc = new PdfFixedDocument(fs);
                    fs.Dispose();
                    PdfPageRenderer     renderer = new PdfPageRenderer(pDoc.Pages[0]);
                    PdfRendererSettings s        = new PdfRendererSettings();
                    s.DpiX = s.DpiY = 96;

                    FileStream pngStream = File.OpenWrite(Path.Combine(path, fileName.Replace(".pdf", ".png")));
                    renderer.ConvertPageToImage(pngStream, PdfPageImageFormat.Png, s);
                    pngStream.Flush();
                    pngStream.Dispose();

                    response r = SaveThumbNail(sType, path, fileName.Replace(".pdf", ".png"), null, width, height);
                    try
                    {
                        File.Delete(Path.Combine(path, fileName.Replace(".pdf", ".png")));
                    }
                    catch { }
                    return(r);

                    //return new response(false, "eroare", null, null, null);
                }
                catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
                    {
                        new Error(exp)
                    })); }

            case ".jpg":
            case ".jpeg":
            case ".png":
            case ".bmp":
                try
                {
                    return(SaveThumbNail(sType, path, fileName, null, width, height));
                }
                catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
                    {
                        new Error(exp)
                    })); }

            default:
                Error err = ErrorParser.ErrorMessage("unsupportedFormat");
                return(new response(false, err.ERROR_MESSAGE, null, null, new System.Collections.Generic.List <Error>()
                {
                    err
                }));
            }
        }
예제 #7
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            if (selectedPageNumber != -1)
            {
                PdfPageRenderer renderer   = new PdfPageRenderer(document.Pages[selectedPageNumber]);
                WriteableBitmap pageBitmap = renderer.ConvertPageToImage(96);

                pageImage.Source = pageBitmap;
            }
        }
예제 #8
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            if (selectedPageNumber != -1)
            {
                PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[selectedPageNumber]);
                WriteableBitmap pageBitmap = renderer.ConvertPageToImage(96);

                pageImage.Source = pageBitmap;
            }
        }
예제 #9
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;

            Stream pdfStream =
                assembly.GetManifestResourceStream("Xfinium.Pdf.Samples.Pro.WP81.PageThumbnails.xfinium.pdf");
            PdfFixedDocument document = new PdfFixedDocument(pdfStream);

            pdfStream.Dispose();

            int i = 0;

            pageThumbnailImages = new Image[document.Pages.Count];

            for (i = 0; i < document.Pages.Count; i++)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush     = new SolidColorBrush(Colors.Black);
                border.Margin          = new Thickness(10, 10, 0, 0);

                Image pageImage = new Image();
                border.Child           = pageImage;
                pageThumbnailImages[i] = pageImage;

                pageThumbnails.Children.Add(border);
            }

            for (i = 0; i < document.Pages.Count; i++)
            {
                int index = i;

                var t = Task <PdfBgraByteRenderingSurface> .Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer       = new PdfPageRenderer(document.Pages[index]);
                    PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface <PdfBgraByteRenderingSurface>(thumbnailDpi, thumbnailDpi);
                    PdfRendererSettings settings   = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
                    renderer.ConvertPageToImage(settings);

                    return(rs);
                })
                        .ContinueWith(value =>
                {
                    PdfBgraByteRenderingSurface rs = value.Result;
                    WriteableBitmap pageBitmap     = new WriteableBitmap(rs.Width, rs.Height);
                    Stream imageStream             = pageBitmap.PixelBuffer.AsStream();
                    imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);

                    pageThumbnailImages[index].Width  = pageBitmap.PixelWidth;
                    pageThumbnailImages[index].Height = pageBitmap.PixelHeight;
                    pageThumbnailImages[index].Source = pageBitmap;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
예제 #10
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            StreamResourceInfo xfiniumPdf = Application.GetResourceStream(new Uri("xfinium.pdf", UriKind.Relative));
            PdfFixedDocument   document   = new PdfFixedDocument(xfiniumPdf.Stream);

            xfiniumPdf.Stream.Close();
            (Application.Current as App).Document = document;

            int i = 0;

            pageThumbnailImages = new Image[document.Pages.Count];

            for (i = 0; i < document.Pages.Count; i++)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush     = new SolidColorBrush(Colors.Black);
                border.Margin          = new Thickness(10, 10, 0, 0);

                Image pageImage = new Image();
                pageImage.Tag          = i;
                pageImage.Tap         += pageImage_Tap;
                border.Child           = pageImage;
                pageThumbnailImages[i] = pageImage;

                pageThumbnails.Children.Add(border);
            }

            for (i = 0; i < document.Pages.Count; i++)
            {
                int index = i;

                var t = Task <PdfArgbIntRenderingSurface> .Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer      = new PdfPageRenderer(document.Pages[index]);
                    PdfArgbIntRenderingSurface rs = renderer.CreateRenderingSurface <PdfArgbIntRenderingSurface>(thumbnailDpi, thumbnailDpi);
                    PdfRendererSettings settings  = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
                    renderer.ConvertPageToImage(settings);

                    return(rs);
                })
                        .ContinueWith(value =>
                {
                    PdfArgbIntRenderingSurface rs = value.Result;
                    WriteableBitmap wb            = new WriteableBitmap(rs.Width, rs.Height);
                    Array.Copy(rs.Bitmap, wb.Pixels, rs.Bitmap.Length);
                    pageThumbnailImages[index].Width  = wb.PixelWidth;
                    pageThumbnailImages[index].Height = wb.PixelHeight;
                    pageThumbnailImages[index].Source = wb;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
partial         void ConvertPageButtonTouchUp(UIButton sender)
        {
            PageRenderingIndicator.StartAnimating();

            var t = Task<CGImage>.Factory.StartNew(() =>
                {
                    CGImage pageImage = null;
                    PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[currentPageNumber]);
                    pageImage = renderer.ConvertPageToImage(96);
                    return pageImage;
                })
                .ContinueWith(value =>
                    {
                        PageImageView.Image = new UIImage(value.Result);
                        PageRenderingIndicator.StopAnimating();
                    }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        partial void ConvertPageButtonTouchUp(UIButton sender)
        {
            PageRenderingIndicator.StartAnimating();

            var t = Task <CGImage> .Factory.StartNew(() =>
            {
                CGImage pageImage        = null;
                PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[currentPageNumber]);
                pageImage = renderer.ConvertPageToImage(96);
                return(pageImage);
            })
                    .ContinueWith(value =>
            {
                PageImageView.Image = new UIImage(value.Result);
                PageRenderingIndicator.StopAnimating();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
예제 #13
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            if (cbxPageNumber.SelectedIndex != -1)
            {
                PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[cbxPageNumber.SelectedIndex]);
                PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface<PdfBgraByteRenderingSurface>(96, 96);
                PdfRendererSettings settings = new PdfRendererSettings(96, 96, rs);
                renderer.ConvertPageToImage(settings);

                WriteableBitmap pageBitmap = new WriteableBitmap(rs.Width, rs.Height);
                Stream imageStream = pageBitmap.PixelBuffer.AsStream();
                imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);

                //pageImage.Width = pageBitmap.PixelWidth;
                //pageImage.Height = pageBitmap.PixelHeight;
                pageImage.Source = pageBitmap;
            }
        }
예제 #14
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            if (cbxPageNumber.SelectedIndex != -1)
            {
                PdfPageRenderer             renderer = new PdfPageRenderer(document.Pages[cbxPageNumber.SelectedIndex]);
                PdfBgraByteRenderingSurface rs       = renderer.CreateRenderingSurface <PdfBgraByteRenderingSurface>(96, 96);
                PdfRendererSettings         settings = new PdfRendererSettings(96, 96, rs);
                renderer.ConvertPageToImage(settings);

                WriteableBitmap pageBitmap  = new WriteableBitmap(rs.Width, rs.Height);
                Stream          imageStream = pageBitmap.PixelBuffer.AsStream();
                imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);

                //pageImage.Width = pageBitmap.PixelWidth;
                //pageImage.Height = pageBitmap.PixelHeight;
                pageImage.Source = pageBitmap;
            }
        }
예제 #15
0
        private void btnObjectAnalysis_Click(object sender, EventArgs e)
        {
            //use the PDF library to break out all of the PDF Objects
            Readers.PDFReader Rdr = new Readers.PDFReader();
            Rdr.getObjectsFromPDF(PDFFileName, out PDFPageWidth, out PDFPageHeight);
            //break up text objects with multiple words into a single word per object
            DataBase.DB DocObjects = new DataBase.DB();

            DocObjects.LocateKeywords();

            PdfFixedDocument doc      = new PdfFixedDocument(PDFFileName);
            PdfPageRenderer  renderer = new PdfPageRenderer(doc.Pages[0]);

            FileStream PNGStream = File.OpenWrite(PDFFileName + ".png");

            renderer.ConvertPageToImage(dpi, PNGStream, PdfPageImageFormat.Png);
            PNGStream.Flush();
            PNGStream.Close();
            LoadImageBox();

            PopulateGridView("Text");
        }
예제 #16
0
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Provides data for navigation methods and event
        /// handlers that cannot cancel the navigation request.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            int pageNumber = (int)e.Parameter;
            PdfFixedDocument document = (Application.Current as App).Document;

            var t = Task<PdfBgraByteRenderingSurface>.Factory.StartNew(() =>
            {
                PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[pageNumber]);
                PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface<PdfBgraByteRenderingSurface>(96, 96);
                PdfRendererSettings settings = new PdfRendererSettings(96, 96, rs);
                renderer.ConvertPageToImage(settings);

                return rs;
            })
                .ContinueWith(value =>
                {
                    PdfBgraByteRenderingSurface rs = value.Result;
                    WriteableBitmap pageBitmap = new WriteableBitmap(rs.Width, rs.Height);
                    Stream imageStream = pageBitmap.PixelBuffer.AsStream();
                    imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);
                    pageImage.Width = pageBitmap.PixelWidth;
                    pageImage.Height = pageBitmap.PixelHeight;
                    pageImage.Source = pageBitmap;

                }, TaskScheduler.FromCurrentSynchronizationContext());
        }
예제 #17
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            StreamResourceInfo xfiniumPdf = Application.GetResourceStream(new Uri("xfinium.pdf", UriKind.Relative));
            PdfFixedDocument document = new PdfFixedDocument(xfiniumPdf.Stream);
            xfiniumPdf.Stream.Close();
            (Application.Current as App).Document = document;

            int i = 0;

            pageThumbnailImages = new Image[document.Pages.Count];

            for (i = 0; i < document.Pages.Count; i++)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.Margin = new Thickness(10, 10, 0, 0);

                Image pageImage = new Image();
                pageImage.Tag = i;
                pageImage.Tap += pageImage_Tap;
                border.Child = pageImage;
                pageThumbnailImages[i] = pageImage;

                pageThumbnails.Children.Add(border);
            }

            for (i = 0; i < document.Pages.Count; i++)
            {
                int index = i;

                var t = Task<PdfArgbIntRenderingSurface>.Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[index]);
                    PdfArgbIntRenderingSurface rs = renderer.CreateRenderingSurface<PdfArgbIntRenderingSurface>(thumbnailDpi, thumbnailDpi);
                    PdfRendererSettings settings = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
                    renderer.ConvertPageToImage(settings);

                    return rs;
                })
                    .ContinueWith(value =>
                    {
                        PdfArgbIntRenderingSurface rs = value.Result;
                        WriteableBitmap wb = new WriteableBitmap(rs.Width, rs.Height);
                        Array.Copy(rs.Bitmap, wb.Pixels, rs.Bitmap.Length);
                        pageThumbnailImages[index].Width = wb.PixelWidth;
                        pageThumbnailImages[index].Height = wb.PixelHeight;
                        pageThumbnailImages[index].Source = wb;

                    }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
예제 #18
0
        private void SchedulePageRendering(int pos)
        {
            // schedule rendering or load from cache procedure
            ThreadPool.QueueUserWorkItem ((p) => {
                if (pos >= 0) {

                    PdfPageRenderer renderer = new PdfPageRenderer (doc.Pages [pos]);
                    Bitmap pageImage = renderer.ConvertPageToImage (95);
                    Bitmap mutableBitmap = pageImage.Copy (Bitmap.Config.Argb8888, true);
                    Color C = new Color (mutableBitmap.GetPixel (1, 1));
                    for (int f = 0; f <  0 /*mutableBitmap.Width*/; f++) {//623
                        for (int j = 0; j < 0/*Convert.ToInt32(mutableBitmap.Height*0.05)*/; j++) {
                            //Color C = new Color (BitMaps[count].GetPixel (i+20, j + 30));//pageimage
                            mutableBitmap.SetPixel (f, j, C);
                        }
                        for (int j = mutableBitmap.Height - Convert.ToInt32(mutableBitmap.Height*0.05); j < mutableBitmap.Height; j++) {//900 936
                            mutableBitmap.SetPixel (f, j, C);
                        }
                    }

            //
            //						string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
            //						var cachepath = System.IO.Path.Combine (documentsPath, "Cache" + pos + ".jpg");
            //						Bitmap BM = BitmapFactory.DecodeFile (cachepath);

                    Bitmap BM = mutableBitmap;
                    int width = (int)BM.Width;
                    int height = (int)BM.Height;

                    // Phase I, try to load the file first
                    try {

                        if (BM != null) {
                            lock (syncObject) {
                                //Console.WriteLine("loaded cached instance");

                                ScaleImageView currentView = views [pos];

                                //if view exists update it, otherwise dismiss the bitmap
                                if (currentView != null) {
                                    currentView.Post (() => {
                                        lock (syncObject) {
                                            ReplaceBitmap (pos, BM);
                                            currentView.SetImageBitmap (BM);
                                            currentView.Invalidate ();
                                        }
                                    });
                                } else {
                                    DismissBitmap (BM);
                                }
                            }

                            return;
                        }

                    } catch (Exception e) {
                        Console.WriteLine ("can't load cached bitmap, re-rendering: " +
                        e.Message);
                    }

            //						try
            //						{
            //							Console.WriteLine("creating new instance");
            //
            //							// phase II, re-rendering
            //							// render the page using default settings
            //							int[] bitmapData = new int[width*height];
            //							ManualResetEvent me = null;
            //							if (ProgressiveRendering)
            //							{
            //								me = new ManualResetEvent(false);
            //								ThreadPool.QueueUserWorkItem((a) =>
            //									{
            //										Thread.Sleep(500);
            //
            //										while (!me.WaitOne(0))
            //										{
            //											lock (syncObject)
            //											{
            //												ImageView currentView = views[pos];
            //												if (currentView !=null)
            //												{
            //													Bitmap targetBitmap = bitmaps[pos];
            //
            //													BitmapHelper.CopyPixelDataToBitmap(targetBitmap,bitmapData,width);
            //
            //													currentView.PostInvalidate();
            //												}
            //												else
            //												{
            //													return;
            //												}
            //											}
            //
            //											Thread.Sleep(200);
            //										}
            //									});
            //							}
            //
            //
            //
            //						}
            //						catch (Exception e)
            //						{
            //							Console.WriteLine("page rendering error: " + e.Message);
            //						}
                }
            });
        }
예제 #19
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;

            Stream pdfStream =
                assembly.GetManifestResourceStream("Xfinium.Pdf.Samples.Pro.WP81.PageThumbnails.xfinium.pdf");
            PdfFixedDocument document = new PdfFixedDocument(pdfStream);
            pdfStream.Dispose();

            int i = 0;

            pageThumbnailImages = new Image[document.Pages.Count];

            for (i = 0; i < document.Pages.Count; i++)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.Margin = new Thickness(10, 10, 0, 0);

                Image pageImage = new Image();
                border.Child = pageImage;
                pageThumbnailImages[i] = pageImage;

                pageThumbnails.Children.Add(border);
            }

            for (i = 0; i < document.Pages.Count; i++)
            {
                int index = i;

                var t = Task<PdfBgraByteRenderingSurface>.Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[index]);
                    PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface<PdfBgraByteRenderingSurface>(thumbnailDpi, thumbnailDpi);
                    PdfRendererSettings settings = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
                    renderer.ConvertPageToImage(settings);

                    return rs;
                })
                    .ContinueWith(value =>
                    {
                        PdfBgraByteRenderingSurface rs = value.Result;
                        WriteableBitmap pageBitmap = new WriteableBitmap(rs.Width, rs.Height);
                        Stream imageStream = pageBitmap.PixelBuffer.AsStream();
                        imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);

                        pageThumbnailImages[index].Width = pageBitmap.PixelWidth;
                        pageThumbnailImages[index].Height = pageBitmap.PixelHeight;
                        pageThumbnailImages[index].Source = pageBitmap;

                    }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }