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.

Thu May 07, 2015 3:10 pm

Hi,

here's a small code which display all ContentControls from header, body and footer.

.NET : 4.5.2
Spire.Doc : 5.4.10.53040

Missing in body : Document.Message
Missing in header : Expediteur.Adresse1 and Expediteur.Adresse2
Missing in footer : none.

(I can get them using MS Open XML SDK 2.5).

Vincent

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Fri May 08, 2015 8:48 am

Hello,

Thanks for your inquiry.
There is code for your reference, and please download the version from the following link and have a try:
http://www.e-iceblue.com/downloads/temp ... 5.4.12.zip

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Sat May 09, 2015 9:20 am

Hi,

nearly perfect, just : Document.Message is still missing in document body.

Vincent

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Mon May 11, 2015 6:02 am

Hello,

Thanks for your response.
Document.Message can be found in body, please see the below picture.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon May 11, 2015 10:08 am

Hi,

I've found the mistake. In my code, I need to browse both structureTags.tabInlines and structureTags.tags.
(I'm not sure to understand what's the difference between these 2 items and why they 're not in the same structure.)

Thanks for quick patch :)

Vincent

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Tue May 12, 2015 2:40 am

Hello,

The structureTags.tabInlines is in paragraph, and the structureTags.tags is in body.
If there are any questions or needs, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Jun 01, 2015 5:00 pm

Hi,

using this code :
Code: Select all
List<StructureDocumentTagInline> tagInlines = structureTags.tagInlines;
                Console.WriteLine("Part1");
                for (int i = 0; i < tagInlines.Count; i++)
                {
                    string alias = tagInlines[i].SDTProperties.Alias;   // Can be null or empty
                    decimal id = tagInlines[i].SDTProperties.Id;
                    string tag = tagInlines[i].SDTProperties.Tag;
                    string STDType = tagInlines[i].SDTProperties.SDTType.ToString();

                    Console.WriteLine("{0,20},{1,15},{2, 10} - {3}", alias, id, STDType, tag);

                    if (tagInlines[i].SDTProperties.SDTType == SdtType.Picture)
                    {
                        // Replace picture by another one
                        Image img = Image.FromFile(Path.GetFullPath (@"..\..\logo_default.gif"));

                        // TODO : replace Picture by this new one
                    }
                }


I need to replace the picture found in the content control. I can detect the Picture type of ContentControl but I don't see anything related to image.
Can somebody help me ?

Thanks,

Vincent

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Tue Jun 02, 2015 7:36 am

Hello,

Thanks for your inquiry.
Sorry that at present the Spire.Doc doesn’t support to replace the picture found in the content control.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Jun 02, 2015 8:41 am

Ok.

another alternative will be to replace image stored in the resources part. (so all ContentControls using this image will use the new one. it's something like ImagePart<> in the OpenXml SDK).

Vincent

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Wed Jun 03, 2015 6:36 am

Hello,

After investigation, there is a way to replace the image. And there is a new interface( IStructureDocument )to define the class StructureTags, the code is far more succinct than before. Please refer to the below code:
Code: Select all
  List<IStructureDocument> tagInlines = structureTags.StructureDocument;   
              …       
                if (tagInlines[i].SDTProperties.SDTType == SdtType.Picture)
                {
                    DocPicture picture = tagInlines[i].ChildObjects.FirstItem as DocPicture;
                    picture.LoadImage(Image.FromFile(@"F:\image\image1.jpg"));
                }
               …
        public class StructureTags
        {
            List<IStructureDocument> m_structureDocumnt;
            public List<IStructureDocument> StructureDocument
            {
                get
                {
                    if (m_structureDocumnt == null)
                        m_structureDocumnt = new List<IStructureDocument>();

                    return m_structureDocumnt;
                }           
            }
          }


Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Jun 03, 2015 8:00 am

Hi,

in my case, it works only for barcode inserted as image.
the image included in ContentControl in header it don't work. (tagInlines[i].ChildObjects.FirstItem == null)

Vincent

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Wed Jun 03, 2015 9:30 am

Hello,

Please refer to the below code:
Code: Select all
if (tagInlines[i].SDTProperties.SDTType == SdtType.Picture)
                {
                    DocPicture picture = tagInlines[i].ChildObjects.FirstItem as DocPicture;
                    if (picture == null)
                    {
                        picture = new DocPicture(doc);
                        picture.LoadImage(Image.FromFile(@"F:\image\image1.jpg"));
                        tagInlines[i].ChildObjects.Add(picture);
                    }
                    else
                    {
                        picture.LoadImage(Image.FromFile(@"F:\image\image1.jpg"));
                    }
                }

If there are any questions, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Jun 03, 2015 10:41 am

your code works but in my case, the content control returning null already embed an image.
So loading this document :
- display twice the image
- image size fit to image source and not previous image size.

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Thu Jun 04, 2015 8:19 am

Hello,

Sorry that I can’t reproduce your issue, so please provide your document and all code for our test.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Jun 04, 2015 11:28 am

Here's the project.

nolme
 
Posts: 79
Joined: Fri Apr 24, 2015 3:56 pm

Return to Spire.Doc