GrapeCity Documents for Word v5.1 - April 22, 2022

Updates included in this release:

  • Enhanced Font Support
  • Font Effects
  • Save documents to SVG

GcWord Templates Enhancements:

  • Paragraph Block Behavior
  • Run Block Behaviour
  • Ignore Missing Data Members
  • Support for Type Converting Formatter

Read the release blog for full details.

GcWord v5 - December 14, 2021

GrapeCity Documents for Word (GcWord)

Support Arrays of Primitive Types and Strings as Data Sources for Report Templates

Lists and arrays of primitive types (types for which Type.IsPrimitive gets true) and strings can now be used as data sources in GcWord Report Templates. The array elements' values are injected into the generated document with the "Value" template tag, as the example below shows.

var doc = new GcWordDocument();
            
            // Add a few simple arrays as data sources:
            doc.DataTemplate.DataSources.Add("dsInts", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            doc.DataTemplate.DataSources.Add("dsConsts", new double[]
            {
                    Math.PI,
                    Math.E,
            });
            doc.DataTemplate.DataSources.Add("dsStrs", new List<string>()
            {
                    "Pacific",
                    "Atlantic",
                    "Indian",
                    "Southern",
                    "Arctic",
            });
            // Add a list template so that the data is formatted as a list:
            var myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate");
            
            // Integers:
            doc.Body.Paragraphs.Add("Integers from 1 to 9:", doc.Styles[BuiltInStyleId.Heading1]);
            var p = doc.Body.Paragraphs.Add("{{#dsInts}}{{dsInts.value}}{{/dsInts}}", doc.Styles[BuiltInStyleId.ListParagraph]);
            p.ListFormat.Template = myListTemplate;
            
            // Math constants:
            doc.Body.Paragraphs.Add("Constants from the Math class:", doc.Styles[BuiltInStyleId.Heading1]);
            p = doc.Body.Paragraphs.Add("{{#dsConsts}}{{dsConsts.value}}{{/dsConsts}}", doc.Styles[BuiltInStyleId.ListParagraph]);
            p.ListFormat.Template = myListTemplate;
            
            // Strings (oceans):
            doc.Body.Paragraphs.Add("Strings (oceans):", doc.Styles[BuiltInStyleId.Heading1]);
            p = doc.Body.Paragraphs.Add("{{#dsStrs}}{{dsStrs.value}:toupper()}{{/dsStrs}}", doc.Styles[BuiltInStyleId.ListParagraph]);
            p.ListFormat.Template = myListTemplate;
            

word

Help | Demo

Define and Embed Fonts

You can now define and embed fonts in MS Word documents to render the document correctly, even if the Fonts are missing on the system. With the new Font API, you can now -

  • Allow users to define and embed any fonts in documents, so Microsoft Word will correctly render documents even if the fonts are missing in the local system.
  • Allow users to read and use fonts data for Word document rendering.
  • Allow users to find and remove embedded fonts from Word documents.
  • Get more info about ThemeFont class properties used in Word documents.

The following new additions have been added to the Font API supported in GcWord.

  • Extended ThemeFont class with new properties:
    • Add new FontInfo class
    • Add new FontInfoCollection class that represents FontInfo collection
    • Add a new FontSignature class to support FontInfo.Signature property
    • Add new EmbeddedFont class to support FontInfo.Embedded property
    • Add new EmbeddedFontCollection that represents EmbeddedFont collection
    • Add Fonts property to DocumentBase class to get access to FontInfoCollection

Users can manage fonts in GcWordDocument and GlossaryDocument classes.

The following code embeds the Times New Roman font into a DOCX under a custom name "My font 1":

GcWordDocument doc = new GcWordDocument(); 
            const string myFontName1 = "My Font 1";
            // Use first of the fonts to be embedded:
            var p = doc.Body.Paragraphs.Add();
            var run = p.GetRange().Runs.Add($"Text rendered using embedded font \"{myFontName1}\".");
            // Apply custom font to the run:
            run.Font.Name = myFontName1;
            
            // (in this case we simply duplicate "Times New Roman"):
             var font1 = doc.Fonts.Add(myFontName1);
            
            // Use "Times New Roman" font settings:
            font1.CharSet = FontCharSet.Ansi;
            font1.Family = FontFamily.Roman;
            font1.Pitch = FontPitch.Variable;
            font1.Panose = new List<byte> { 2, 2, 6, 3, 5, 4, 5, 2, 3, 4 };
            font1.Signature.CodePageRange1 = 0x000001ff;
            font1.Signature.CodePageRange2 = 0x00000000;
            font1.Signature.UnicodeRange1 = 0xE0002EFF;
            font1.Signature.UnicodeRange2 = 0xC000785B;
            font1.Signature.UnicodeRange3 = 0x00000009;
            font1.Signature.UnicodeRange4 = 0x00000000;
            
            // Load the "Times New Roman" font data:
            byte[] data1 = File.ReadAllBytes(Path.Combine("Resources", "Fonts", "times.ttf"));
            // Embed font data into the document:
            
            font1.Embedded.Add(EmbeddedFontType.Regular, FontDataType.ObfuscatedTrueTypeFont, data1);
            

Help | Embed Fonts Demo | List Embed Fonts Demo| Remove Embed Fonts Demo

Check out the release notes for a full list of changes and additions.

Breaking Changes

In this release, we have made a few changes to streamline our packages. The following changes may require you to change references to GrapeCity.Documents packages in your projects (note that these changes affect only package/dll references, and should not require any changes in your code):

  • GrapeCity.Documents.Common package has been removed. All types that lived in that package have been moved over to GrapeCity.Documents.Imaging package
  • GrapeCity.Documents.Common.Windows package has been renamed to GrapeCity.DioDocs.Imaging.Windows
  • GrapeCity.DioDocs.Pdf.Resources package has been removed. Types that were defined in it have been moved to GrapeCity.DioDocs.Pdf

If you have any comments on the new features or want to share how these are helpful, drop a comment below!

Read the release blog for full details.