Free Support Forum - aspose.com

PDF conversion with margins and tables in doc files

Hi Aspose team,


we found an issue when converting a doc file to pdf with customized margins and containing tables. The document is somehow not rendered correctly in the output pdf.
However, if you first open the original document in MS Word and save it as docx (without that option to keep compatibility with earlier versions) and then run the code to adjust margins and save as pdf, the output is fine.

You can reproduce this with the following code:

var doc = new Document(@“S:\document.doc”);
var pageSetup = new DocumentBuilder(doc).PageSetup;

// 4 cm border
var margin = ConvertUtil.MillimeterToPoint(40);

pageSetup.TopMargin = margin;
pageSetup.RightMargin = margin;
pageSetup.BottomMargin = margin;
pageSetup.LeftMargin = margin;

doc.Save(@“S:\document.pdf”);

I attached some files and outputs they generate:
original.doc -> The original doc file
original.pdf -> Output of original.doc generated with Aspose
originalWord.pdf -> Output of original doc manipulated (the margins) by MS Word and generated by MS Word (this is what we would expect Aspose output to look like)
saved_with_aspose.doc -> Original file manipulated (the margins) by Aspose and saved as doc with Aspose
saved_with_aspose.pdf -> Output of saved_with_aspose.doc generated with Aspose
converted_word_no_compatibility.docx -> Original file saved as docx with MS Word without keeping compatibility to earlier word versions
converted_word_no_compatibility.pdf -> Output of converted_word_no_compatibility.docx generated with Aspose
converted_word_with_compatibility.docx -> Original file saved as docx with MS Word with keeping compatibility to earlier word versions
converted_word_with_compatibility.pdf -> Output of converted_word_with_compatibility.docx generated with Aspose
I hope those files will help you.

Kind regards,
Daniel
Hi Daniel,

Thanks for your inquiry. We have tested the scenario with your shared document using Aspose.Words for .NET 17.4 and we have noticed the reported issue. We have logged a ticket WORDSNET-15272 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

Best Regards,

Hi Daniel,


We have further looked into the issue and we would suggest you to use UpdateTableLayout() method. It will resolve the issue.

var doc = new Document(@“D:\Downloads\original.doc”);<o:p></o:p>

var pageSetup = new DocumentBuilder(doc).PageSetup;

// 4 cm border

var margin = ConvertUtil.MillimeterToPoint(40);

pageSetup.TopMargin = margin;

pageSetup.RightMargin = margin;

pageSetup.BottomMargin = margin;

pageSetup.LeftMargin = margin;

doc.UpdateTableLayout();

doc.Save(@"E:/Data/original_setup.pdf");


Best Regards,

Hi Tilal,


thanks for your reply. I managed to fix the problem by calling that method, too. :slight_smile:

Kind regards,
Daniel