We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Can extract thumbnails from *.dotx file?

word has a “Built-In Building Blocks.dotx” file which has a lot of useful buildingblock, i don’t know aspose.word can be extracting thumbnails from this file than for consumer use?

Hi Pyntia,

Thanks for your inquiry. Using Document.AttachedTemplate property you can get or set the full path of the template which is attached to the document. However, could you please attach your sample word document you want to extract content from here for testing? We will investigate the scenario and provide you more information.

Best regards,

hi, Awais

thank you for your reply

i want to using the word default buildingblock template which located in path "%appdata%\Roaming\Microsoft\Document Building Blocks\2052\1x"

another question, is aspose can Modify template programmatic? for example delete a existed buildingblock or append a new buildingblock to existed template file.

thanks

another additional information:
i use office2013 x64 and win8 64, if use windows xp, the path will be change to “my document**”.

thanks

perheps, i want to persist buildingblock to database, is any code snippet for this?

Hi Pyntia,

Thanks for the additional information. Sure, you can use the following code to attach this template document to an empty document and save it to disk:

Document doc = new Document();
doc.AttachedTemplate = @"C:\Users\Awais\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Built-In Building Blocks.dotx";
doc.Save(@"C:\Temp\out.docx");

Yes, with Aspose.Words you can easily modify template (or any Word documents) programmatically; for example, please try running the following code snippet:

Document doc = new Document(@"C:\Users\Awais\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Built-In Building Blocks.dotx");
Style style = doc.Styles.Add(StyleType.Paragraph, "MyStyle1");
style.Font.Size = 24;
style.Font.Name = "Verdana";
style.ParagraphFormat.SpaceAfter = 12;
doc.Save(@"C:\Temp\modified.dotx");

Once you have modified your template document, you can easily save it inside database. Please refer to the following article for more details:
https://docs.aspose.com/words/net/serialize-and-work-with-a-document-in-a-database/

I hope, this helps.

Best regards,

hi, Awais

thank you for your reply

there is something information unclearly, let me talk more about it.

in word, when inserting a cover to current editing document, you can see a cover list like below picture:
https://pjkzua.dm2303.livefilestore.com/y2pq44xZnXR4zVGvaNN9-RIhXfBXdDJJ3o-uzieATxWIS2OdxzaMlgZf_QrtZ8NTQ34St0eXM56LXvfwbIvsLYAxzzawIudHkAW8XdohdoIH1M/build-in-cover.jpg?psid=1

i want to extracting these cover thumbnails from the template file(Built-in Building Blocks.dotx). i think these thumbnails is useful to end user to make document professional and beautiful.

can i do this in aspose?

Hi Pyntia,

Thanks for the additional information. I think, you can achieve this using the GlossaryDocument property. Please see the following points about GlossaryDocument class:

  1. It is the root element for a glossary document within a Word document. A glossary document is a storage for AutoText, AutoCorrect entries and Building Blocks.
  2. Some documents, usually templates, can contain AutoText, AutoCorrect entries and/or Building Blocks (also known as glossary document entries, document parts or building blocks).
  3. To access building blocks, you need to load a document into a Document object. Building blocks will be available via the GlossaryDocument property.
  4. GlossaryDocument can contain any number of BuildingBlock objects. Each BuildingBlock represents one document part.
  5. Corresponds to the glossaryDocument and docParts elements in OOXML.

Best regards,

hi, Aawis
sorry for delay reply
i know the glossaryDocument object in aspose, but i exactly want to know how to take the thumbnail from these buildingblocks.

you didn’t answer this question, i could not found any api from GlossaryDocument class for this purpose.

thanks

Hi Pyntia,

Thanks for your inquiry. I am in communication with our development team and will get back to you as soon as I have any further information.

Best regards,

hi, Awais

thank you very much, waiting good news.

hi, Awais

is any message for this question?

Hi Pyntia,

Thanks for your inquiry. Unfortunately, we have not heard back from our development team yet. We will update you as soon as there is any further information available on this topic.

Best regards,

Hi Pyntia,

Thanks for being patient. Unfortunately, Microsoft Word does not store cover pages as thumbnails in Word documents instead all these are stored as BuildingBlocks inside GlossaryDocument. To access building blocks, you need to load a document into a Document object. Building blocks will then be available via the GlossaryDocument property. If we can help you with anything else, please feel free to ask.

Best regards,

hi, Awais

thank you very much.

do you mean is: aspose can’t generate thumbnail from existed BuildingBlock?

Hi Pyntia,

Thanks for your inquiry. You can use the following code to retrieve and insert cover pages (thumbnails) from “Building Blocks.dotx” into your input document:

Document docBuildingBlocks = new Document(@"C:\Temp\Building Blocks.dotx");
Document doc = new Document(@"C:\Temp\input.docx");
GlossaryDocument glossaryDocument = docBuildingBlocks.GlossaryDocument;
foreach (BuildingBlock buildingBlock in glossaryDocument.BuildingBlocks)
{
    if (buildingBlock.Gallery.ToString().StartsWith("CoverPage"))
    {
        Section sec = (Section)buildingBlock.FirstChild;
        doc.AppendChild(doc.ImportNode(sec, true));
    }
}
doc.Save(@"c:\Temp\output.docx");

I hope, this helps.

Best regards,

hi, Awais

thank you very much.

your code can insert cover page successfully, but there is some little inconsistent,

i have inserted a cover page with the name “Sideline”, after insert to document, the page layout has changed a bit. please look below picture.

diff layout

can you please check it?

Hi Pyntia,

Thanks for your inquiry. Please try executing the following code to avoid this problem:

Document docBuildingBlocks = new Document(MyDir + "Building Blocks.dotx");
Document doc = new Document(MyDir + "input.docx");
GlossaryDocument glossaryDocument = docBuildingBlocks.GlossaryDocument;
foreach (BuildingBlock buildingBlock in glossaryDocument.BuildingBlocks)
{
    if (buildingBlock.Gallery.ToString().StartsWith("CoverPage") && buildingBlock.Name.Equals("Sideline"))
    {
        // clone section which you want to keep layout of
        Section sec = doc.FirstSection.Clone();
        // remove existing content of this section
        sec.RemoveAllChildren();
        // append content of buildingBlock to this section
        foreach (Node node in ((Section)buildingBlock.FirstChild).ChildNodes)
            sec.AppendChild(doc.ImportNode(node, true));
        doc.AppendChild(sec);
    }
}
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,

hi, Awais

your code can work perfectly, thank you very much.