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

Free Support Forum - aspose.com

Dynamic HTML Table gives weird look when exporting to PDF

Im using Aspose word to read a word template and bind dynamic data with Replace method, and then I’m exporting it to a PDF file.
this dynamic data included dynamic HTML content from rich text boxes which include an HTML table.
this table is not rendering on output pdf properly and im seeking support for that.
HTML View (correct view)

PDF view

public class ReplaceWithHtmlEvaluator : IReplacingCallback
{
    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);

        builder.MoveTo(e.MatchNode);
        builder.InsertHtml(e.Replacement);
        e.Replacement = "";
        return ReplaceAction.Replace;
    }
}

appreciate if someone helpme with this.

@ishara119 Could you please attach your problematic template document and HTML content here for testing? We will check the issue and provide you more information.

hi, following is a sample of html im receiving, it could be anything since it dynamic and im using Replace method to add it into document.

<div>2. Shipment to be derived from<table border="1" cellspacing="0"><tbody><tr><td>Manufacturer Name</td><td>Address</td></tr><tr><td>M1</td><td>Australia,650168</td></tr><tr><td>M3</td><td>Australia,650168</td></tr><tr><td>M3</td><td>Singapore,117438</td></tr></tbody></table></div>

@ishara119 Could you please also attach a template document? Inserting the provided HTML into an empty document (or replacing some text with it) produces correct output on my side.

yes sure, here i have attached sample doc file with minimal details you can check that.
to elaborate bit more,

following text i have in word template
<<CONDITIONS>>

and using following line to replace it dynamically,

doc.Range.Replace("<<CONDITIONS>>", (licenceData.Conditons != null) ? licenceData.Conditons : String.Empty, new FindReplaceOptions { ReplacingCallback = new ReplaceWithHtmlEvaluator() });

//ReplaceWithHtmlEvaluator method is mentioned in first post.Template.docx (30.5 KB)

@ishara119 I was managed to reproduce your issue on my side. I have logged it as WORDSNET-24670 in our defect tracking system. We will keep you informed and let you know once it is resolved.

As a workaround you could specify the width of inserted table explicitly either in the HTML string or in AW DOM after inserting.

Thank you.
the suggested workaround might not work, because the HTML comes from Rich Textbox so i can not predict the layout of HTML, no of HTML tables can not predit or it’s placing within the html.

@ishara119 We will keep you updated and let you know once the issue is resolved or we have more information for you.

1 Like

@ishara119 Our development team have concluded that this issue is not a bug. You are trying to insert a table with auto layout (AllowAutoFit = true) in to a table with fixed layout (AllowAutoFit = false). MS Word document model doesn’t support that. As a workaround you could try the following:

  1. Change layout of the parent table in the template from fixed to auto (specify AllowAutoFit = true for that table)
  2. Specify the with of the inserted table in the HTML fragment (e.g. style=\"width:100%\" on the <table> element)