Upgrade with new apose liabrary to 24.9.0 leads to right margin issue in PDF

@mayurih

Would you please upgrade to the latest version which is 25.7 at the moment. Also, you can find the information about release notes at the below link:

In case you still face any kind of issues, please share minimal sample code snippet with us so that we can try to replicate the issue in our environment and address it accordingly.

Here is code

// Area where we create html data-----------------------
 string html = string.Format(@"table style='width:100%;padding-left:5px;padding-right:5px;'>  tr>td style='{2}'>{0}/td>/tr>
                                            tr>td> /td>/tr>
                                            tr>td >{1}/td>/tr>
                                        </table"
                                                      , title
                                                      , subTableHtml
                                                      , this.Level1TitleCss
                                                      , this.CellBorderCss);

html = ASRExportHelper.PP_STYLE + html;
// Area where we create html data-----------------------

---------Area where the html is bing to builder-------------

builder.InsertHtml(section.HtmlContent);

pdf saving --------------------------

Document doc = new Document(tempPath);
DocumentBuilder builder = new DocumentBuilder(doc);
doc.Save(path, Aspose.Words.SaveFormat.Pdf);

@mayurih

Looks like you are using Aspose.Words. We have moved this topic to the respective forum category where you will be assisted accordingly.

@mayurih Could you please attach your problematic input HTML, temporary and problematic output documents here for testing? We will check the issue and provide you more information.

@alexey.noskov
Sample html-

htmlcode.docx (15.4 KB)

report with issue

@mayurih Thank you for additional information. Unfortunately, I cannot reproduce the problem on my side. I used the following simple code for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(File.ReadAllText(@"C:\Temp\in.html"));
doc.Save(@"C:\Temp\out.pdf");

out.pdf (63.1 KB)

which aspose version your are using at your end?

@mayurih The latest 25.7 version of Aspose.Words for .NET.

tempdoc.docx (75.3 KB)

we are using this document file as base template and appending dynamic table through html code in it. does this template have any issue?

@mayurih Yes, with your template the problem is reproducible. As a workaround, you can load your HTML into a separate document and then insert this document instead of HTML string. Please see the following code:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
Document htmlDoc = new Document(@"C:\Temp\in.html");
builder.InsertDocument(htmlDoc, ImportFormatMode.KeepSourceFormatting);
doc.Save(@"C:\Temp\out.pdf");

out.pdf (121.6 KB)

I have tried this solution my data gets adjusted properly but left side column data gets wrapped automatically.

@mayurih Could you please elaborate what is the expected output?

it should be like this

@mayurih Please try modifying the code like this:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();

Document htmlDoc = new Document(@"C:\Temp\in.html");
foreach (Table t in htmlDoc.GetChildNodes(NodeType.Table, true))
    t.AutoFit(AutoFitBehavior.FixedColumnWidths);

builder.InsertDocument(htmlDoc, ImportFormatMode.KeepSourceFormatting);
doc.Save(@"C:\Temp\out.pdf");

out.pdf (121.5 KB)

this code is not working at my end.

NodeCollection tables = htmlDoc.GetChildNodes(NodeType.Table, true);
foreach (Aspose.Words.Tables.Table table in tables)
    table.AutoFit(AutoFitBehavior.AutoFitToWindow);

@mayurih In the above code AutoFitBehavior.FixedColumnWidths was suggested not AutoFitBehavior.AutoFitToWindow. Please try using AutoFitBehavior.FixedColumnWidths.

it worked, but is there any way not to write content in html file as this may lead to creation of file on server and for each user we might need to create new.

@mayurih Sure, you can pass HTML string. The code example reads HTML content from the file just for demonstration purposes.

can u give one example of how to pass html string while creating htmldoc in memory

@mayurih You can use code like the following:

string html = File.ReadAllText(@"C:\Temp\in.html");

Document htmlDoc;
using (MemoryStream htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html)))
    htmlDoc = new Document(htmlStream);