Aspose.Words.Examples.CSharp.Programming_Documents.Working_with_Tables.SpecifyHeightAndWidth.AutoFitToPageWidth C# (CSharp) Method

AutoFitToPageWidth() private static method

Shows how to set a table to auto fit to 50% of the page width.
private static AutoFitToPageWidth ( string dataDir ) : void
dataDir string
return void
        private static void AutoFitToPageWidth(string dataDir)
        {
            // ExStart:AutoFitToPageWidth
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a table with a width that takes up half the page width.
            Table table = builder.StartTable();

            // Insert a few cells
            builder.InsertCell();
            table.PreferredWidth = PreferredWidth.FromPercent(50);
            builder.Writeln("Cell #1");

            builder.InsertCell();
            builder.Writeln("Cell #2");

            builder.InsertCell();
            builder.Writeln("Cell #3");

            dataDir = dataDir + "Table.PreferredWidth_out.doc";
           
            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:AutoFitToPageWidth
            Console.WriteLine("\nTable autofit successfully to 50% of the page width.\nFile saved at " + dataDir);
        }
        /// <summary>