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

Free Support Forum - aspose.com

The margins of section N are set outside the printable area of the page. Do you want to contunue?

Hullo, I'm using ASPOSE Total for .NET and we've a simple requirement to convet the PDF to Word. But We're having to face rough sledding, figuring out the margins.

I am using following code snippet for preparing the demo:

string filePath = @"C:\Data\AdobeXMLFormsSamples.pdf";

if (File.Exists(filePath))
Aspose.Pdf.License license = new Aspose.Pdf.License();
Aspose.Words.License wordLicense = new Aspose.Words.License();
Aspose.Pdf.Document pdf_doc = new Aspose.Pdf.Document(filePath);
filePath = Path.ChangeExtension(Path.GetFullPath(filePath), ".doc");
if (File.Exists(filePath))
pdf_doc.Save(filePath, Aspose.Pdf.SaveFormat.Doc);
Aspose.Words.Document word_doc = new Aspose.Words.Document(filePath);
foreach (Section sec in word_doc)
sec.PageSetup.LeftMargin = 144.00f;
sec.PageSetup.RightMargin = 144.00f;

Please suggest a way out from this issue, we're having to deal with hundrads of such pop-ups.

Alternatively I could not levarage Microsft.Office.Interop.Word which aspose seem to be using coherently (just a rough guess, I could be wrong here)

object nothing = System.Reflection.Missing.Value;
string filePath = @"C:\data\b0e.doc";
if (File.Exists(filePath))
Microsoft.Office.Interop.Word.Application app = new Application();
app.Visible = false;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(filePath, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing);

float left, top, bottom, right;
left = top = bottom = 50.00f;
right = 72.00f;

doc.PageSetup.TopMargin = doc.PageSetup.BottomMargin = doc.PageSetup.LeftMargin = left;
doc.PageSetup.RightMargin = right;
string s = "";
for (int i = 0; i < doc.Sections.Count; i++)
//doc.Sections[i].PageSetup.LeftMargin = left;
//doc.Sections[i].PageSetup.RightMargin = right;
//doc.Sections[i].PageSetup.PaperSize = WdPaperSize.wdPaperLetter;
doc.Sections[i].PageSetup.GutterStyle = WdGutterStyleOld.wdGutterStyleBidi;
catch (Exception)
filePath = Path.GetFileNameWithoutExtension(filePath) + 2 + ".doc";


C:\Program Files (x86)\Aspose\Aspose.Pdf for .NET\Bin\net4.0\Aspose.Pdf.dll ( Runtime Version = v4.0.30319 & Version

C:\Program Files (x86)\Aspose\Aspose.Words for .NET\bin\net2.0\Aspose.Words.dll (Runtime Version v2.0.50727 & Version

Hi Aarsh,

Thanks for your inquiry. In your case, I suggest you please use RecognitionMode.Flow to save Word document into flow layout as shown in following code snippet. Please read following documentation links for your kind reference.

Aspose.Pdf.Document pdf_doc = new Aspose.Pdf.Document(MyDir + “AdobeXMLFormsSamples.pdf”);
Aspose.Pdf.DocSaveOptions saveOptions = new Aspose.Pdf.DocSaveOptions();
saveOptions.Mode = Aspose.Pdf.DocSaveOptions.RecognitionMode.Flow;
pdf_doc.Save(MyDir + "AdobeXMLFormsSamples.doc", saveOptions);
Aspose.Words.Document word_doc = new Aspose.Words.Document(MyDir + "AdobeXMLFormsSamples.doc");
foreach (Section sec in word_doc)
 sec.PageSetup.LeftMargin = 90.00f;
 sec.PageSetup.RightMargin = 90.00f;
word_doc.Save(MyDir + "Out.doc");

Hope this helps you. Please let us know if you have any more queries.

I tried that but found following section. Typically when I turned the grid lines on, I cam to know that I actually need to wrap that element or region. Also looks like it is not being considered as a section otherwise it would have shrunken it.

Hi Aarsh,

Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behaviour as MS Word do. The code shared in my last post sets the Left and Right margin of exported Doc file. The Aspose.Pdf exports the Pdf correctly but some of the contents are not inside grid lines. Do you want the exported Doc file’s contents inside Grid Lines? Please share some more detail about your query.

Moreover, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as how you want your final Word output be generated like. We will then provide you more information on this along with code.