Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Dec 31, 2014 10:02 am

How insert checkbox at Fixed Position, for example near by 'aaaa' character?

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Thu Jan 01, 2015 4:31 am

Hello,

Please use the following method to insert checkbox in fixed position.
Code: Select all
CheckBoxFormField cb = new CheckBoxFormField(doc);
cb.Checked = true;
cb.Name = "Chk1";
para.Items.Insert(0, cb);

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Sat Jan 03, 2015 1:48 am

para how declare in Fixed Position?tks

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Sat Jan 03, 2015 3:31 am

Gary.zhang wrote:Hello,

Please use the following method to insert checkbox in fixed position.
Code: Select all
CheckBoxFormField cb = new CheckBoxFormField(doc);
cb.Checked = true;
cb.Name = "Chk1";
para.Items.Insert(0, cb);

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team

para how declare in Fixed Position?tks

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Mon Jan 05, 2015 6:49 am

Hello,
Sorry for late reply. MS Word document is flow document and does not contain any information about its layout into lines and pages. So there is no way to determine on which page and where on the page some particular node is located. In Spire.Doc you only insert the paragraph step by step or by index like this.
Code: Select all
Document doc = new Document();
Section section = doc.AddSection();
Paragraph para1 = section.AddParagraph();
para1.AppendText("paragraph1");
Paragraph para2 = section.AddParagraph();
para2.AppendText("paragraph2");
CheckBoxFormField cb = new CheckBoxFormField(doc);
cb.Checked = true;
cb.Name = "Chk1";
para2.Items.Insert(1, cb);
doc.SaveToFile("test.docx", FileFormat.Docx);

If there are any doubt, you could provide us your document and state your requirement, we will provide the corresponding demo for your reference.
Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Jan 06, 2015 9:39 am

Hello,

Have you tried the code? Does it fulfill your needs? Could you please give us some feedback if convenience?

Please let us know if there are any questions or needs.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Jan 08, 2015 2:46 am

Gary.zhang wrote:Hello,

Have you tried the code? Does it fulfill your needs? Could you please give us some feedback if convenience?

Please let us know if there are any questions or needs.

Thanks,
Gary
E-iceblue support team

tks for your anwser,i'm understander

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Thu Jan 08, 2015 3:23 am

Gary.zhang wrote:Hello,

Have you tried the code? Does it fulfill your needs? Could you please give us some feedback if convenience?

Please let us know if there are any questions or needs.

Thanks,
Gary
E-iceblue support team

for example Aspose.Words;
code lile this
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Aspose.Words;
namespace WordDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document(".//test.doc");
            doc.Range.Replace("{#username}", "zhang", false, false);//{#username} template character
            Regex reg = new Regex("{#userphoto}");//fix  position
       doc.Range.Replace(reg, new ReplaceAndInsertImage(".//1.jpg"), false);
           
            doc.Save("res.doc")
        }
    } 
     
   public class ReplaceAndInsertImage : IReplacingCallback
    {

        public string url { get; set; }
         
   public ReplaceAndInsertImage(string url)
        {
            this.url = url;
        }
         
   public ReplaceAction Replacing(ReplacingArgs e)
        {
            var node = e.MatchNode;
   
            Document doc = node.Document as Document;
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.MoveTo(node);
            builder.InsertImage(url);
            return ReplaceAction.Replace;
        }
    }
}
 

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Thu Jan 08, 2015 6:20 am

Hello,

Thanks for your response. Here are the code in Spire for your reference.
Code: Select all
Document doc = new Document();
doc.LoadFromFile("test.doc");
doc.Replace("{#username}", "zhang", false, false);
DocPicture picture=new DocPicture(doc);
picture.LoadImage(Image.FromFile("1.jpg"));
TextSelection[] texts = doc.FindAllString("{#userphoto}", true, true);
foreach(TextSelection ts in  texts)
            {
                TextRange range= ts.GetAsOneRange();
                Paragraph paragraph=range.OwnerParagraph;
                int index=paragraph.ChildObjects.IndexOf(range);
                paragraph.ChildObjects.Insert(index,picture);
                paragraph.ChildObjects.RemoveAt(index+1);
            }
doc.SaveToFile("result.doc");

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Jan 12, 2015 8:59 am

Hello,

Have you tried the method in Spire? Does it fulfill your needs? Could you please give us some feedback if convenience?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Jan 14, 2015 1:04 am

Gary.zhang wrote:Hello,

Have you tried the method in Spire? Does it fulfill your needs? Could you please give us some feedback if convenience?

Thanks,
Gary
E-iceblue support team

Code: Select all
 string filepath = Server.MapPath("mb/");
         
            Document document = new Document();
            document.LoadFromFile(filepath + "Apply_1.doc",FileFormat.Auto);
            DocPicture picture = new DocPicture(document);
            System.Drawing.Image img = System.Drawing.Image.FromFile(filepath+"11.jpg");
            picture.LoadImage(img);
            TextSelection[] texts = document.FindAllString("{$110936}", false, false);
            foreach (TextSelection ts in texts)
            {
                TextRange range = ts.GetAsOneRange();
                Paragraph paragraph = range.OwnerParagraph;
                int index = paragraph.ChildObjects.IndexOf(range);
                paragraph.ChildObjects.Insert(index, picture);
                paragraph.ChildObjects.RemoveAt(index + 1);
            }
           
            document.SaveToFile(filepath + "Apply_Zs.doc", FileFormat.Doc);

I've already tried that. It's blown.
sorry

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Wed Jan 14, 2015 1:54 am

Hello,

Thanks for your response. Please attach your document here for our testing, if it is inconvenient to attach here, you can send it to Support@e-iceblue.com via email.
Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Jan 14, 2015 3:46 am

Gary.zhang wrote:Hello,

Thanks for your response. Please attach your document here for our testing, if it is inconvenient to attach here, you can send it to Support@e-iceblue.com via email.
Thanks,
Gary
E-iceblue support team

I have emailed you.see Support@e-iceblue.com

wangjun
 
Posts: 8
Joined: Wed Dec 31, 2014 8:42 am

Wed Jan 14, 2015 7:26 am

Hello,

Thanks for the information. I have checked the original document and found that the line spacing of the paragraph is set as exactly and a fixed value(12pt), which caused the reason why the image doesn't display totally, please don't set the fixed value.
Image
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc