找回密码
 立即注册

QQ登录

只需一步,快速开始

longgun119

论坛元老

6

主题

31

帖子

1万

积分

论坛元老

积分
13942

活字格认证

longgun119
论坛元老   /  发表于:2015-5-29 15:17  /   查看:13192  /  回复:12
C:\LEADTOOLS 19\Examples\DotNet\CS\DocumentViewerDemo
如何往DocumentViewer追加文件(即同时在DocumentViewer中加载多个文件)?

以下是我所写代码:
            using (var dlg = new UI.OpenDocumentFileDialog())
            {
                dlg.DocumentFileName = _preferences.LastDocumentFileName;
                dlg.AnnotationsFileName = _preferences.LastAnnotationsFileName;
                dlg.LoadEmbeddedAnnotations = _preferences.LastFileLoadEmbeddedAnnotations;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    var options = new LoadDocumentOptions();
                    options.UseCache = DocumentFactory.Cache != null;

                    if (dlg.AnnotationsFileName != null)
                        options.AnnotationsUri = new Uri(dlg.AnnotationsFileName);
                    else
                        options.AnnotationsUri = null;

                    options.LoadEmbeddedAnnotations = dlg.LoadEmbeddedAnnotations;
                    Document document = DocumentFactory.LoadFromFile(dlg.DocumentFileName, options);
                    foreach (Leadtools.Documents.DocumentPage page in document.Pages)
                    {
                        _documentViewer.Document.Pages.Add(page);
                    }
                    _documentViewer.Commands.DocumentViewer.SetDocument(_documentViewer.Document);
                }
            }
每次执行到“_documentViewer.Document.Pages.Add(page);”这句时,会报“Page is already a member of a different document”的错误!

12 个回复

倒序浏览
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-6-1 09:04:00
沙发
您好,问题已经收到,我这边调查后给您回复。
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-6-1 10:43:00
板凳
回复 1楼longgun119的帖子

您好,关于错误信息,回答如下:
_documentViewer.Document.Pages.Add(page);
这一句,您在往Viewer中添加Page的时候,不用使用这个方法,这个方法会导致出现异常,因为Document对象添加的时候不能添加其他Document中的页面。
请将这一句修改为:_documentViewer.SetDocument(document);,这样您加载的文档中的所有页面都会直接追加到Viewer中。
另外,DocumentViewer只支持同时存在一个文档,所以如果您需要添加多个文档到当前Viewer中的话,给您提供两种做法:
1、将多个文档中的Page添加到Viewer中,这对于编辑、合并是有好处的,但如果您仍想将编辑后的文档再保存回原始文档的话比较麻烦。这个例子就形如LEADTOOLS 19\Examples\DotNet\CS\DocumentWritersDemo
2、您可以做ChildWindow,就是LEADTOOLS 19\Examples\DotNet\CS\DocumentCleanupDemo这样的Demo,每一个文档都是一个子窗口,展现在主窗口之内。
希望这个答案能够帮助到您。
以上, 谢谢。
回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-6-4 16:34:00
地板
回复 3楼AvoCaDolol的帖子

旋转问题:
        private void _clockwiseToolStripButton_Click(object sender, EventArgs e)
        {
            int page_index = _documentViewer.CurrentPageNumber + 1;
            _documentViewer.Commands.Run(DocumentViewerCommands.ViewRotateClockwise, page_index);
        }
以上代码,我只想旋转DocumentViewer中的选中页,但执行结果是DocumentViewer中的所有页都被旋转了
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-6-4 18:11:00
5#
回复 4楼longgun119的帖子

您好,您的问题已经收到,调查之后给您回复
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-6-5 12:22:00
6#
回复 4楼longgun119的帖子

您好,
_documentViewer.Commands.Run(DocumentViewerCommands.ViewRotateClockwise, page_index);
这段代码中,DocumentViewerCommands.ViewRotateClockwise这个参数指的是将整个View都顺时针旋转90度。后面的page_index参数是无效的。

请问您是需要在WinForm中做页面旋转呢,还是Web上做页面旋转?
回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-6-5 13:35:00
7#
回复 6楼AvoCaDolol的帖子

在WinForm中做页面旋转(C:\LEADTOOLS 19\Examples\DotNet\CS\DocumentViewerDemo在这个demo中做旋转)
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-6-8 10:51:00
8#
回复 7楼longgun119的帖子

您好,如果需要旋转的话,只能针对图片,Page是不能旋转的。
在这个Demo中,使用的是DocumentViewer控件,这个控件中只能显示文档,无法显示Image。
如果需要旋转的话,请示用ImageViewer,然后使用下面的代码:
           var page = this._documentViewer.Document.Pages[this._documentViewer.CurrentPageNumber];
            RotateCommand command = new RotateCommand();
            command.Angle = 90 * 100;
            command.FillColor = new RasterColor(255, 255, 255);
            command.Flags = RotateCommandFlags.Bicubic;
            command.Run(page.GetImage());
回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-6-10 11:26:00
9#
回复 8楼AvoCaDolol的帖子

有办法可以直接在DocumentViewer控件中实现?
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-6-10 13:32:00
10#
回复 9楼longgun119的帖子

您好,Document Viewer主要针对Page页面进行操作,对于Page来说是没有旋转这个操作的。
这就像Word文档一样,在Word中是没有将页面旋转的操作的。
如果需要旋转可以使用Image Viewer。
希望能帮助到您。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部