Ejemplo n.º 1
0
        private void CleanUp()
        {
            /* Collapse this stuff since it is going to be released */
            xaml_ThumbGrid.Visibility = System.Windows.Visibility.Collapsed;

            /* Clear out everything */
            if (m_docPages != null && m_docPages.Count > 0)
            {
                m_docPages.Clear();
            }
            if (m_pageType != null && m_pageType.Count > 0)
            {
                m_pageType.Clear();
            }
            if (m_thumbnails != null && m_thumbnails.Count > 0)
            {
                m_thumbnails.Clear();
            }
            if (m_toppage_pos != null && m_toppage_pos.Count > 0)
            {
                m_toppage_pos.Clear();
            }
            if (m_list_thumb != null && m_list_thumb.Count > 0)
            {
                m_list_thumb.Clear();
            }
            if (m_images_rendered != null && m_images_rendered.Count > 0)
            {
                m_images_rendered.Clear();
            }
            if (m_page_sizes != null && m_page_sizes.Count > 0)
            {
                m_page_sizes.Clear();
            }

            m_currfile = null;
            m_origfile = null;
            m_numpages = -1;
            m_doc_type_has_page_access = true;
            m_document_type            = doc_t.UNKNOWN;
            m_origfile = null;
            CleanUpTempFiles();
            xaml_TotalPages.Text = "/ 0";
            xaml_currPage.Text   = "0";
            CloseExtraWindows(false);

            m_ghostscript.PageRenderedCallBack -= new GSNET.PageRendered(gsPageRendered);
            m_ghostscript.DisplayDeviceClose();
            m_ghostscript.DisplayDeviceOpen();
            m_viewer_state = ViewerState_t.NO_FILE;

            /* Set vertical scroll to top position */
            Decorator    border       = VisualTreeHelper.GetChild(xaml_PageList, 0) as Decorator;
            ScrollViewer scrollViewer = border.Child as ScrollViewer;

            scrollViewer.ScrollToVerticalOffset(0);
            return;
        }
Ejemplo n.º 2
0
        public void ProcessFile(String FileName)
        {
            /* Before we even get started check for issues */
            /* First check if file exists and is available */
            if (!System.IO.File.Exists(FileName))
            {
                ShowMessage(NotifyType_t.MESS_STATUS, "File not found!");
                return;
            }
            if (m_viewer_state == ViewerState_t.DOC_OPEN)
            {
                /* In this case, we want to go ahead and launch a new process
                 * handing it the filename */
                /* We need to get the location */
                string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                try
                {
                    string Arguments = FileName + " open";
                    Process.Start(path, Arguments);
                }
                catch (InvalidOperationException)
                {
                    Console.WriteLine("InvalidOperationException");
                }
                catch (Win32Exception)
                {
                    Console.WriteLine("Win32 Exception: There was an error in opening the associated file. ");
                }
                return;
            }
            else if (m_viewer_state != ViewerState_t.NO_FILE)
            {
                return;
            }

            m_viewer_state = ViewerState_t.OPENING;

            /* If we have a ps or eps file then launch the distiller first
             * and then we will get a temp pdf file which we will open.  This is done
             * to demo both methods of doing callbacks from gs worker thread.  Either
             * progress as we distill the stream for PS or page by page for PDF */
            string extension = System.IO.Path.GetExtension(FileName);

            /* We are doing this based on the extension but should do
             * it based upon the content */
            switch (extension.ToUpper())
            {
            case ".PS":
                m_document_type = doc_t.PS;
                break;

            case ".EPS":
                m_document_type = doc_t.EPS;
                break;

            case ".PDF":
                m_document_type = doc_t.PDF;
                break;

            case ".XPS":
                m_document_type = doc_t.XPS;
                break;

            case ".OXPS":
                m_document_type = doc_t.XPS;
                break;

            case ".BIN":
                m_document_type = doc_t.PCL;
                break;

            case ".PNG":
                m_document_type = doc_t.PNG;
                break;

            case ".JPG":
                m_document_type = doc_t.JPG;
                break;

            case ".TIF":
                m_document_type = doc_t.TIF;
                break;

            default:
            {
                m_document_type = doc_t.UNKNOWN;
                ShowMessage(NotifyType_t.MESS_STATUS, "Unknown File Type");
                m_viewer_state = ViewerState_t.NO_FILE;
                return;
            }
            }
            if (m_document_type == doc_t.PCL ||
                m_document_type == doc_t.XPS ||
                m_document_type == doc_t.PS)
            {
                MessageBoxResult result = MessageBox.Show("Would you like to distill this file?", "ghostnet", MessageBoxButton.YesNoCancel);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    xaml_DistillProgress.Value = 0;
                    m_viewer_state             = ViewerState_t.DISTILLING;
                    if (m_ghostscript.DistillPS(FileName, Constants.DEFAULT_GS_RES) == gsStatus.GS_BUSY)
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy");
                        return;
                    }
                    xaml_DistillName.Text         = "Distilling";
                    xaml_CancelDistill.Visibility = System.Windows.Visibility.Visible;
                    xaml_DistillName.FontWeight   = FontWeights.Bold;
                    xaml_DistillGrid.Visibility   = System.Windows.Visibility.Visible;
                    return;

                case MessageBoxResult.No:
                    //m_doc_type_has_page_access = false;
                    break;

                case MessageBoxResult.Cancel:
                    m_viewer_state = ViewerState_t.NO_FILE;
                    return;
                }
            }
            m_currfile = FileName;
            RenderThumbs();
            return;
        }
Ejemplo n.º 3
0
        public void GSResult(gsParamState_t gs_result)
        {
            TempFile tempfile = null;

            if (gs_result.outputfile != null)
            {
                tempfile = new TempFile(gs_result.outputfile);
            }

            if (gs_result.result == GS_Result_t.gsCANCELLED)
            {
                xaml_DistillGrid.Visibility = System.Windows.Visibility.Collapsed;
                if (tempfile != null)
                {
                    try
                    {
                        tempfile.DeleteFile();
                    }
                    catch
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "Problem Deleting Temp File");
                    }
                }
                return;
            }
            if (gs_result.result == GS_Result_t.gsFAILED)
            {
                xaml_DistillGrid.Visibility = System.Windows.Visibility.Collapsed;
                ShowMessage(NotifyType_t.MESS_STATUS, "GS Failed Conversion");
                if (tempfile != null)
                {
                    try
                    {
                        tempfile.DeleteFile();
                    }
                    catch
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "Problem Deleting Temp File");
                    }
                }
                return;
            }
            switch (gs_result.task)
            {
            case GS_Task_t.CREATE_XPS:
                /* Always do print all from xps conversion as it will do
                 * the page range handling for us */
                /* Add file to temp file list */
                m_tempfiles.Add(tempfile);
                PrintXPS(gs_result.outputfile, true, -1, -1, true);
                break;

            case GS_Task_t.PS_DISTILL:
                xaml_DistillGrid.Visibility = System.Windows.Visibility.Collapsed;
                m_origfile = gs_result.inputfile;

                /* Save distilled result */
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter   = "PDF file (*.pdf)|*.pdf";
                dlg.FileName = System.IO.Path.GetFileNameWithoutExtension(m_origfile) + ".pdf";
                if (dlg.ShowDialog() == true)
                {
                    try
                    {
                        if (File.Exists(dlg.FileName))
                        {
                            File.Delete(dlg.FileName);
                        }
                        File.Copy(tempfile.Filename, dlg.FileName);
                    }
                    catch (Exception except)
                    {
                        ShowMessage(NotifyType_t.MESS_ERROR, "Exception Saving Distilled Result:" + except.Message);
                    }
                }
                tempfile.DeleteFile();
                m_viewer_state = ViewerState_t.NO_FILE;
                break;

            case GS_Task_t.SAVE_RESULT:
                /* Don't delete file in this case as this was our output! */
                ShowMessage(NotifyType_t.MESS_STATUS, "GS Completed Conversion");
                break;
            }
        }
Ejemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing);

            /* Set up ghostscript calls for progress update */
            m_ghostscript = new GSNET();
            m_ghostscript.ProgressCallBack   += new GSNET.Progress(gsProgress);
            m_ghostscript.StdIOCallBack      += new GSNET.StdIO(gsIO);
            m_ghostscript.DLLProblemCallBack += new GSNET.DLLProblem(gsDLL);
            m_ghostscript.DisplayDeviceOpen();

            m_currpage = 0;
            m_gsoutput = new gsOutput();
            m_gsoutput.Activate();
            m_tempfiles                = new List <TempFile>();
            m_thumbnails               = new List <DocPage>();
            m_docPages                 = new Pages();
            m_pageType                 = new List <Page_Content_t>();
            m_page_sizes               = new List <pagesizes_t>();
            m_document_type            = doc_t.UNKNOWN;
            m_doczoom                  = 1.0;
            m_viewer_state             = ViewerState_t.NO_FILE;
            m_validZoom                = true;
            m_doc_type_has_page_access = true;
            m_list_thumb               = new List <idata_t>();
            m_images_rendered          = new List <idata_t>();
            m_aa = true;

            xaml_PageList.AddHandler(Grid.DragOverEvent, new System.Windows.DragEventHandler(Grid_DragOver), true);
            xaml_PageList.AddHandler(Grid.DropEvent, new System.Windows.DragEventHandler(Grid_Drop), true);


            /* For case of opening another file, or launching a print process */
            string[] arguments = Environment.GetCommandLineArgs();
            if (arguments.Length == 3)
            {
                string filePath = arguments[1];
                string job      = arguments[2];

                if (String.Equals(job, "open"))
                {
                    ProcessFile(filePath);
                }
            }
            else if (arguments.Length == 5)
            {
                string filePath = arguments[1];
                string job      = arguments[2];

                try
                {
                    m_currpage = Int32.Parse(arguments[3]);
                    m_numpages = Int32.Parse(arguments[4]);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Failure to parse print page info");
                    Close();
                }

                /* Keep main window hidden if we are doing a print process */
                this.IsVisibleChanged += new System.Windows.DependencyPropertyChangedEventHandler(WindowVisible);
                m_viewer_state         = ViewerState_t.PRINTING;
                Print(filePath);
            }
        }