示例#1
0
        public void Prepare(string path, ContextObject context)
        {
            _context = context;
            _path    = path;

            var width  = 800d;
            var height = 600d;

            var pages = GhostScriptWrapper.GetPageSizes(path);

            pages?.ForEach(p =>
            {
                width  = Math.Max(width, p.Width);
                height = Math.Max(height, p.Height);
            });

            context.SetPreferredSizeFit(new Size(width, height), 0.8);
        }
示例#2
0
        public void View(string path, ContextObject context)
        {
            _pdfControl           = new PdfViewerControl();
            context.ViewerContent = _pdfControl;

            _buffer = GhostScriptWrapper.ConvertToPdf(path);
            if (_buffer == null || _buffer.Length == 0)
            {
                context.ViewerContent = new Label {
                    Content = "Conversion to PDF failed."
                };
                context.IsBusy = false;
                return;
            }

            Exception exception = null;

            _pdfControl.Dispatcher.BeginInvoke(new Action(() =>
            {
                try
                {
                    _pdfControl.LoadPdf(_buffer);

                    context.Title = $"1 / {_pdfControl.TotalPages}: {Path.GetFileName(path)}";

                    _pdfControl.CurrentPageChanged += UpdateWindowCaption;
                    context.IsBusy = false;
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }), DispatcherPriority.Loaded).Wait();

            if (exception != null)
            {
                ExceptionDispatchInfo.Capture(exception).Throw();
            }
        }