Beispiel #1
0
        private BitmapSource ShowPDF(string filename)
        {
            IntPtr ctx = IntPtr.Zero;
            IntPtr stm = IntPtr.Zero;
            IntPtr doc = IntPtr.Zero;
            IntPtr p   = IntPtr.Zero;

            try
            {
                //MessageBox.Show(filename);

                ctx = Methods.NewContext();
                stm = Methods.OpenFile(ctx, filename);
                doc = Methods.OpenDocumentStream(ctx, stm);
                p   = Methods.LoadPage(doc, currentpage);

                pages = Methods.CountPages(doc);

                Rectangle b = new Rectangle();
                Methods.BoundPage(doc, p, ref b);

                return(PdfImage.CreateBitmapSourceFromBitmap(PdfImage.Page(ctx, doc, p, b)));
            }
            catch (Exception ex)
            {
                return(null);

                throw new Exception(ex.Message);
            }
            finally
            {
                Methods.FreePage(doc, p);
                Methods.CloseDocument(doc);
                Methods.CloseStream(stm);
                Methods.FreeContext(ctx);
            }
        }