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

Free Support Forum - aspose.com

Decrease document margins (left and right) of the generated PDF Document

I am using ASPOSE WORDS for generating PDF file from html string content.
I want to decrease the left and right margins of the generated PDF document so that I can show more content on my generated PDF document.

public void Main()
    // Load the entire document into memory.
    Document doc = new Document(stream);
    // … do something with the document
    // Convert the document to a different format and save to stream.
    MemoryStream dstStream = new MemoryStream();
    doc.Save(dstStream, SaveFormat.Pdf);
    dstStream.Position = 0;
    File.WriteAllBytes(dataDir + "DocumentOut.pdf", dstStream.ToArray());

Please let me know how to do it on the above code snippet.


Hi Vishal,

Thanks for your inquiry. Please use PageSetup.LeftMargin to set the distance (in points) between the left edge of the page and the left
boundary of the body text and PageSetup.RightMargin to set the distance (in points) between the right edge of the page and the right boundary of the body text.

Please check the following code example for your kind reference. Hope this helps you.

Document doc = new Document(MyDir + "in.html");
foreach (Section section in doc.Sections)
    section.PageSetup.LeftMargin = 0;
    section.PageSetup.RightMargin = 0;
doc.Save(MyDir + "Out.pdf");