找回密码
 立即注册

QQ登录

只需一步,快速开始

longgun119

论坛元老

6

主题

31

帖子

1万

积分

论坛元老

积分
13942

活字格认证

longgun119
论坛元老   /  发表于:2015-5-14 15:36  /   查看:28914  /  回复:35
回复 15楼AvoCaDolol的帖子

删除pdf当中的一页可以实现了,O(∩_∩)O谢谢。
我还有以下几个问题:
(1)txt文件无法加载到WebThumbnailViewer中
(2)其他类型的电子文件怎么实现删除其中一页,比如word、excel等
(3)数据库中的二进制文件流怎么加载到WebThumbnailViewer中,并实现删除其中一页(编辑)再保存到数据库
(4)如何实现在线编辑WebImageViewer中加载的文件,编辑完后将其保存

35 个回复

倒序浏览
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-5-14 16:02:00
沙发
回复 1楼longgun119的帖子

您好,关于您的几个问题回答如下:
1、TXT文件想要添加到WebThumbnailViewer中,需要一个配置文件,您可以在Resource目录下新建一个InputProfile.xml,内容如下
<ImageGenerator>
  <InputProfile>
     <TxtEnabled>true</TxtEnabled>
  </InputProfile>
</ImageGenerator>

然后在Page_Load方法中的get_upload_file();语句之前添加这两句即可实现加载TXT文本到WebThumbnailViewer,
WebThumbnailViewer1.InputProfile = Server.MapPath("Resources\\InputProfile.xml");
WebImageViewer1.InputProfile = Server.MapPath("Resources\\InputProfile.xml");
当然不要忘记在工程中添加相关引用:Leadtools.Codecs.Rtf和Leadtools.Codecs.Txt。

2、其他类型的电子文件怎么实现删除其中一页,比如word、excel等
其他文件可以使用DocumentReader加载之后删除Page,具体例子请参见这里:如何使用DocumentReader

3、数据库中的二进制流请使用对应的类型反序列化为文件就可以如同上面的各种格式一样被加载到WebThumbnailViewer,
例如Image,进行反序列化后在内存中创建一个Image,然后添加到WebThumbnailViewer中即可,想要删除一页的话可以将内存中的原始Image修改后序列化为二进制流重新Update到数据库中。

4、目前Leadtools不提供Web编辑功能,只提供对Web展示的图片进行注释、标注、画线、绘画等功能,如果您想打开一个Word并进行文字编辑的话这个功能是没有的。
回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-5-15 09:51:00
板凳
回复 2楼AvoCaDolol的帖子

第一个问题,按照你的方法修改后出现以下问题:
Server Error in '/' Application.

Invalid file format

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Leadtools.RasterException: Invalid file format

Source Error:


Line 129:        using (RasterCodecs codecs = new RasterCodecs())
Line 130:        {
Line 131:            CodecsImageInfo info = codecs.GetInformation(WebThumbnailViewer1.Page.MapPath(file_path), true);
Line 132:            sel_file = file_path;
Line 133:

Source File: F:\work\LeadToolsDemo\DocumentCleanDemo.aspx.cs    Line: 131

Stack Trace:


[RasterException: Invalid file format]
   Leadtools.RasterException.CheckErrorCode(Int32 code) +66
   Leadtools.Codecs.RasterCodecs.DoGetInformation(String fileName, Stream stream, Boolean totalPages, Int32 pageNumber) +1790
   Leadtools.Codecs.RasterCodecs.GetInformation(String fileName, Boolean totalPages) +126
   DocumentCleanDemo.Load_File(String file_path) in F:\work\LeadToolsDemo\DocumentCleanDemo.aspx.cs:131
   DocumentCleanDemo.Repeater1_ItemCommand(Object source, RepeaterCommandEventArgs e) in F:\work\LeadToolsDemo\DocumentCleanDemo.aspx.cs:160
   System.Web.UI.WebControls.Repeater.OnItemCommand(RepeaterCommandEventArgs e) +111
   System.Web.UI.WebControls.Repeater.OnBubbleEvent(Object sender, EventArgs e) +40
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.RepeaterItem.OnBubbleEvent(Object source, EventArgs e) +88
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +180
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-5-15 10:37:00
地板
回复 3楼longgun119的帖子

您好,原因是RasterCodec也需要开启Txt读取。
请在CodecsImageInfo info = codecs.GetInformation(WebThumbnailViewer1.Page.MapPath(file_path), true);
这一句前添加如下代码:
  1. codecs.Options.Txt.Load.Enabled = true;
  2. codecs.Options.Txt.Load.FontColor = new RasterColor(255, 0, 0);
  3. codecs.Options.Txt.Load.FontSize = 12;
  4. codecs.Options.Txt.Load.Bold = true;
  5. codecs.Options.RasterizeDocument.Load.LeftMargin = 1.00;
  6. codecs.Options.RasterizeDocument.Load.TopMargin = 1.25;
  7. codecs.Options.RasterizeDocument.Load.PageWidth = 8.50;
  8. codecs.Options.RasterizeDocument.Load.PageHeight = 11.00;
  9. codecs.Options.RasterizeDocument.Load.BottomMargin = 1.00;
  10. codecs.Options.RasterizeDocument.Load.RightMargin = 1.25;
复制代码

评分

参与人数 1满意度 +5 收起 理由
longgun119 + 5 可以了,但中文显示乱码。。。

查看全部评分

回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-5-15 12:07:00
5#
回复 4楼AvoCaDolol的帖子

WebThumbnailViewer 中page的重新排序功能可以实现吗?
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-5-15 12:20:00
6#
回复 5楼longgun119的帖子

您好,目前WebThumbnailViewer 不支持内部的排序功能,WebThumbnailViewer 的顺序依赖于Add的先后顺序,所以,如果您想排序的话,请在Add之前对所有读入的Page进行自定义排序,排好后循环Add到WebThumbnailViewer 中即可。

另外关于WebThumbnailViewer 加载Text文档乱码的问题,您可以看看是否是Text文档保存为GB2312了,您可以将Text文档拖入Visual Studio中,文件--高级保存选项改变编码格式为UTF-8之后再加载到WebThumbnailViewer 中,我这边的中文文档没有乱码,无法再现您的问题。

评分

参与人数 1满意度 +5 收起 理由
longgun119 + 5 文档编码问题导致中文乱码,修改编码问题解决了。。。

查看全部评分

回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-5-20 17:00:00
7#
回复 6楼AvoCaDolol的帖子

1.旋转WebThumbnailViewer中的一页后,如何保存至原来文件,没有旋转的页保持不变?
2.往WebThumbnailViewer中追加页面,如何将追加的页面保存至原来文件?

以下是我所写的代码,但实现有问题:
            if (sel_file.Substring(sel_file.LastIndexOf(".") + 1).ToLower() == "pdf")
            {
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    codecs.Options.Pdf.InitialPath = Server.MapPath("~/bin/");
                    Leadtools.Pdf.PDFFile pdf_file = new Leadtools.Pdf.PDFFile(WebThumbnailViewer1.Page.MapPath(sel_file));
                    for (int i = 0; i < WebThumbnailViewer1.Count; i++)
                    {
                        ThumbnailInfo info = WebThumbnailViewer1.GetThumbnailInfo(i);
                        if (info.CacheFileName.Length > 0)
                        {
                            Leadtools.Pdf.PDFFile pdf = new Leadtools.Pdf.PDFFile(WebThumbnailViewer1.Page.MapPath(info.CacheFileName));
                            if (i < pdf_file.GetPageCount())
                                pdf_file.ReplacePagesFrom(1, pdf, i + 1, i + 1);
                            else
                                pdf_file.InsertPagesFrom(1, pdf, i + 1, i + 1);
                        }
                        else
                        {
                            Leadtools.Pdf.PDFFile pdf = new Leadtools.Pdf.PDFFile(WebThumbnailViewer1.Page.MapPath(info.Url));
                            if (i < pdf_file.GetPageCount())
                                pdf_file.ReplacePagesFrom(1, pdf, i + 1, i + 1);
                            else
                                pdf_file.InsertPagesFrom(1, pdf, i + 1, i + 1);
                        }
                    }
                }
            }
            else
            {
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    CodecsImageInfo img_info = codecs.GetInformation(WebThumbnailViewer1.Page.MapPath(sel_file), true);
                    for (int i = 0; i < WebThumbnailViewer1.Count; i++)
                    {
                        ThumbnailInfo info = WebThumbnailViewer1.GetThumbnailInfo(i);
                        if (info.CacheFileName.Length > 0)
                        {
                            using (Leadtools.RasterImage image = codecs.Load(WebThumbnailViewer1.Page.MapPath(info.CacheFileName)))
                            {
                                if (i < img_info.TotalPages)
                                    codecs.Save(image, WebThumbnailViewer1.Page.MapPath(sel_file), image.OriginalFormat, image.BitsPerPixel, 1, 1, info.Page, CodecsSavePageMode.Replace);
                                else
                                    codecs.Save(image, WebThumbnailViewer1.Page.MapPath(sel_file), image.OriginalFormat, image.BitsPerPixel, 1, 1, info.Page, CodecsSavePageMode.Append);
                            }
                        }
                        else
                        {
                            using (Leadtools.RasterImage image = codecs.Load(WebThumbnailViewer1.Page.MapPath(info.Url), 0, CodecsLoadByteOrder.BgrOrGray, info.Page, info.Page))
                            {
                                if (i < img_info.TotalPages)
                                    codecs.Save(image, WebThumbnailViewer1.Page.MapPath(sel_file), image.OriginalFormat, image.BitsPerPixel, 1, 1, 0, CodecsSavePageMode.Replace);
                                else
                                    codecs.Save(image, WebThumbnailViewer1.Page.MapPath(sel_file), image.OriginalFormat, image.BitsPerPixel, 1, 1, 0, CodecsSavePageMode.Append);
                            }
                        }
                    }
                }
            }
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-5-21 09:16:00
8#
回复 7楼longgun119的帖子

您好,问题已经收到,我这边正在帮您处理。请稍后。
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-5-21 14:56:00
9#
回复 0楼AvoCaDolol的帖子

您好,您的问题回答如下:
1、旋转的方法的话,您可以使用RotateCommand命令,该命令的使用方法举例如下:
   // 将图片旋转45度
   RotateCommand command = new RotateCommand();
   command.Angle = 45 * 100;
   command.FillColor = new RasterColor(255, 255, 255);
   command.Flags = RotateCommandFlags.Bicubic;
   command.Run(image);
之后保存进原始文件即可。
2、追加页面的话您可以使用如下方法:
PDFFilePage page = new PDFFilePage();
pdf.Pages.Add(page);
以上方法是追加一个新的空白页。
如果您想将其他PDF文档中的某一页追加到当前文档的某个位置可以使用
PDFFile.InsertPagesFrom方法
该方法举例如下:
   string originalFileName = Path.Combine(LEAD_VARS.ImagesDir, @&quot;Leadtools.pdf&quot;);
   string sourceFileName = Path.Combine(LEAD_VARS.ImagesDir, @&quotDFSegmentation.pdf&quot;);
   string destinationFileName = Path.Combine(LEAD_VARS.ImagesDir, @&quot;LEAD_ReplacePage2.pdf&quot;);

   // 为原始文档做一份拷贝
   File.Copy(originalFileName, destinationFileName, true);
   File.SetAttributes(destinationFileName, FileAttributes.Normal);

   // 这是需要替换的文档
   PDFFile sourceFile = new PDFFile(sourceFileName);

   // 将目标文档中的第二页 2 用源文档替换掉
   PDFFile file = new PDFFile(destinationFileName);
   file.ReplacePagesFrom(2, sourceFile, 1, 1);
3、您给的示例代码出现什么错误能否提供?从代码看不出错误在哪里。
回复 使用道具 举报
longgun119
论坛元老   /  发表于:2015-5-21 15:16:00
10#
回复 9楼AvoCaDolol的帖子

不能先将其他pdf文档追加到WebThumbnailViewer中,然后在将WebThumbnailViewer中所有文档追加保存到当前文档?(因为可能要先旋转追加文档中的一些page后再做保存)
回复 使用道具 举报
1234下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部