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

Free Support Forum - aspose.com

DocumentBuilder InsertHtml Save as pdf will exceed page

I use Words’s DocumentBuilder InsertHtml with htmlTable string.
Then Save to PDF file, the table will exceed page
My code is below,

    var doc = new Document();
                doc.Styles.DefaultParagraphFormat.Style.Font.NameFarEast = "標楷體";
                doc.Styles.DefaultParagraphFormat.Style.Font.NameAscii = "Times New Roman";
                doc.Styles.DefaultParagraphFormat.Style.Font.Size = 16D;
                var builder = new DocumentBuilder(doc);
                var htmlTable = @"<style>
        .table {
            width: auto; 

        .table, .table tr {
            height: 40px;

        .table, .table td {
            border-collapse: collapse;
            border: 1px solid #000000;
            padding:2px 5px 2px 5px;
    <table class='table' style='width: 100%;'>
            <col style='width: 15%;'>
            <col style='width: 35%;'>
            <col style='width: 15%;'>
            <col style='width: 35%;'>
                <td>106/10/14 22:26</td>
                <td colspan='3'>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</td>

                builder.InsertHtml(htmlTable, true);
                doc.Save("TEST.pdf", SaveFormat.Pdf);

Thanks for your help


Thanks for your inquiry. Please call Document.UpdateTableLayout method and set CompatibilityOptions.GrowAutofit property to false to get the desired output. CompatibilityOptions.GrowAutofit property allow Tables to AutoFit Into Page Margins.

builder.InsertHtml(htmlTable, true);

doc.CompatibilityOptions.GrowAutofit = false;
doc.Save(MyDir + "output.pdf");
1 Like

It’s worked. Awesome.
Thanks for your help.