450289068 发表于 2013-12-2 15:57:00

目前无法做到这样的效果 ,那就必须等待x10 中图片占位符的方式吗?还有就是必须像你那样操作模版就可以是吧??

450289068 发表于 2013-12-2 16:06:00

我的图片不像你demo中那样 大小刚刚好 我的都是大图 只能缩放后放入模版中目前server不支持这样的定位方式 那如何来设置模版呢?

ZenosZeng 发表于 2013-12-2 16:37:00

回复 31楼450289068的帖子

想我那样通过添加 image: 列可以实现图片自动合并,但是缩放操作会受限制。

450289068 发表于 2013-12-3 09:08:00

等待比较好的解决方法目前被卡在瓶颈上了 无解郁闷 我原来通过textframe那是否可以通过table当前的列宽也算是种方式   给考虑个出路吧版主

ZenosZeng 发表于 2013-12-3 12:04:00

还是在之前的Demo基础上实现的,在 ImageFieldMerged 事件中合并图片并实现图片大小自适应操作:


    // 合并图片,并自动调整大小
    void mailMerge_ImageFieldMerged(object sender, MailMerge.ImageFieldMergedEventArgs e)
    {
      // 完成TX中使用的度量单位缇(Twip)与.NET使用的度量单位像素(Pixel)的转换
      int iTwipsPerPixel = 15;

      byte[] ib = dt.Rows["图片"] as byte[];
      System.IO.MemoryStream ms = new System.IO.MemoryStream(ib);
      // 加载图片
      System.Drawing.Image tmp = System.Drawing.Image.FromStream(ms);

      // 创建TX中的图片对象
      TXTextControl.Image image = new TXTextControl.Image(tmp);

      // 获取图片父容器TextFrame
      TXTextControl.TextFrame frame = tx.TextParts.GetMainText().TextFrames.GetItem("Frame01");

      // 设置图片ID
      image.ID = 1001;

      //设置横向和纵向缩放比例属性,注意TextFrame中可用的空间范围应该减去Margin区域
      image.HorizontalScaling = ((frame.Size.Width - frame.InternalMargins - frame.InternalMargins) * 100) / (tmp.Width * iTwipsPerPixel);
      image.VerticalScaling = ((frame.Size.Height - frame.InternalMargins - frame.InternalMargins) * 100) / (tmp.Height * iTwipsPerPixel);

      e.Image = image;
    }

除此,在初始化 ServerTextControl 对象时添加了这两行代码:
    // 初始化 ServerTextControl
    tx.Create();

    // 为 ServerTextControl 加载模板
    tx.Load(AppDomain.CurrentDomain.BaseDirectory + "\\image_template.docx", TXTextControl.StreamType.WordprocessingML);


450289068 发表于 2013-12-3 14:24:00

很感谢版主 给出的答案
但是我有个问题

你创建模版是用什么工具的 ,怎么会直接可以赋值IDne

      // 获取图片父容器TextFrame
      TXTextControl.TextFrame frame = tx.TextParts.GetMainText().TextFrames.GetItem("Frame01");

Frame01我目前制作的模版 无法赋值ID 如果有ID 就可以运用你的方法 ,我的demo
中 模版都不存在ID 所以只能通过Strat 方式走的

ZenosZeng 发表于 2013-12-3 17:29:00

在 TX X10 中提供的模板设计器程序 TX Text Control Words Ribbon 中可以指定对象名称,如下图:
TX X10 下载:http://www.gcpowertools.com.cn/products/textcontrol_wpf.htm

450289068 发表于 2013-12-4 09:33:00

x10 终于出现了 谢谢版主的大力支持 。再次感谢 。请求关闭 。呵呵
合作愉快。。

ZenosZeng 发表于 2013-12-4 13:35:00

:jy74a: :mj72: :mj72: :mj72:
页: 1 2 3 [4]
查看完整版本: 关于打印纸张大小