Free Support Forum -

Modify site edges of pdf page C#

Hey guys!
I want to modify my page so that the side edges are the same as a pdf, that was converting from a word file.
I tried it with PageInfo.Margin & with PageInfo,PageSize but neither of them seem to work.
I uploaded a test file, that was generated with aspose & one file, that was generated with PrintToPdf Option from Microsoft.Word. Maybe you can see the difference and know what I mean.
The right and left margin between the text is too large in the asposepdf.
Thanks in advance.


AsposePDF.pdf (171.7 KB)
WordPrintToPdf.pdf (146.5 KB)


Thanks for contacting support.

Would you please share a bit more details like how you are creating PDF file from a word file by sharing a sample code snippet. We will test the PDF generation scenario in our environment and share our feedback accordingly.

I’m saving my word file as a filtered html file and convert this html file to a pdf.

StreamReader reader = new StreamReader(@“C\temp\TestFile.html”)
string text = reader.ReadToEnd();
//Save html into stream
var stream = new MemoryStream(Encoding.UTF8.GetBytes(text));
//Create new pdf document
Document doc = new Document(stream, new HtmlLoadOptions());
//create new memorystream and save the pdf into it
MemoryStream output = new MemoryStream();

And I just want the page Settings are looking the same as when I convert a word file to pdf using the WordToPDF print method from word.

Thanks in advance!


Thanks for writing back.

In case you are generating PDF file from HTML, following code can be used to specify margins and page size:

Aspose.Pdf.HtmlLoadOptions objLoadOptions = new Aspose.Pdf.HtmlLoadOptions();
objLoadOptions.PageInfo.Margin.Bottom = 0;
objLoadOptions.PageInfo.Margin.Top = 0;
objLoadOptions.PageInfo.Margin.Right = 0;
objLoadOptions.PageInfo.Margin.Left = 0;
objLoadOptions.PageInfo.Width = 595.27584;
objLoadOptions.PageInfo.Height = 841.88952; 
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "sample.html", objLoadOptions);

In case above code does not help, as you said before in your first post, please share your sample HTML string or file so that we can try to reproduce the issue in our environment and address it accordingly.

It’s working with the current Aspose.Pdf Version (18.10).
Any Chance you could tell me a way to do it on Version 9.1?
thanks in advance


Thanks for getting back to us.

Please note that the above version is quite old and it is always recommended to use latest version as it contains more fixes and improvements. Furthermore, issues reported in old/earlier versions are resolved in latest version of the API. We are afraid we may not be able suggest any workaround in older version because, many of the old Generator approaches have been deprecated in latest version. Please use latest version of the API and in case you face any issue, please feel free to let us know.


I understand that.
Thanks for your help! :slight_smile: