Example #1
0
        /*
         * 加载word 文件
         *
         * @param DocumentViewer 显示容器
         *
         * @param DControl ctl 控件信息
         */
        public static void loadWord(CWord cWord, string wordFullFile)
        {
            cWord.clearContent();
            string                xpsFile = wordFullFile;
            XpsDocument           xpsDoc  = new XpsDocument(xpsFile, FileAccess.Read);
            FixedDocumentSequence fds     = xpsDoc.GetFixedDocumentSequence();

            System.Windows.Size size = fds.DocumentPaginator.PageSize;

            foreach (DocumentReference DocRef in fds.References)
            {
                bool          bForceReload = false;
                FixedDocument DocFd        = DocRef.GetDocument(bForceReload);

                foreach (PageContent DocFpPc in DocFd.Pages)
                {
                    FixedPage fp = new FixedPage();
                    fp.SetValue(DockPanel.DockProperty, Dock.Top);
                    fp.Width      = size.Width;
                    fp.Height     = size.Height;
                    fp.Background = System.Windows.Media.Brushes.Red;

                    //FixedPage DocFp = DocFpPc.GetPageRoot(bForceReload);
                    //for (int i = 0; i < DocFp.Children.Count; i++)
                    //{
                    //    UIElement DocFpUiElem = DocFp.Children[i];
                    //    DocFp.Children.Remove(DocFpUiElem);
                    //    fp.Children.Add(DocFpUiElem);
                    //}
                    cWord.insertContent(fp);
                }
            }
            xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
        }
Example #2
0
        private async void LoadPageTask(int pageId, TaskInfo taskInfo)
        {
            DispatcherContainer target = (DispatcherContainer)contentStackPanel.Children[pageId];

            // if (target.Child != null && target.Child is FixedPage) return;
            //  if (target.GetIsUpdatingChild()) return;
            // Console.WriteLine("获取页面:" + pageId);
            Console.WriteLine("获取页面:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);

            //await 回调,执行下一个
            await target.SetChildAsync <FixedPage>(() =>
            {
                FixedPage fp = new FixedPage();
                try
                {
                    XpsDocument xpsDoc = new XpsDocument(wordFullPath, FileAccess.Read);
                    FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
                    foreach (DocumentReference DocRef in fixedDocumentSequence.References)
                    {
                        Console.WriteLine("获取页面await:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
                        Console.WriteLine();
                        bool bForceReload       = false;
                        FixedDocument DocFd     = DocRef.GetDocument(bForceReload);
                        PageContent pageContent = DocFd.Pages[pageId];
                        fp = pageContent.GetPageRoot(false);

                        // pageContent.SetValue(ContentPresenter.ContentProperty, null);

                        //for (int i = 0; i < fixedPage.Children.Count; i++)
                        //{
                        //    UIElement uiElement = fp.Children[i];
                        //    fixedPage.Children.Remove(uiElement);
                        //    fp.Children.Add(uiElement);
                        //}
                    }
                    // xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
                    return(fp);
                }
                catch (Exception)
                {
                    return(fp);
                }
            }
                                                   , () =>
            {
                FixedPage fp = new FixedPage();
                pageQueueList[pageId].list.Remove(taskInfo);
                if (pageQueueList[pageId].list.Count > 0)
                {
                    LoadPageTask(pageId, pageQueueList[pageId].list[0]);
                }
                return(fp);
            });


            //  Console.WriteLine("任务是否完成:"+task.IsCompleted);
        }