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

Free Support Forum - aspose.com

Control over margin in PDF while coverting HTML to PDF

I am trying to convert attached HTML file to PDF using Asponse’s(v9.0) Document.SaveToPdf method.
In the converted pdf, top and left margins are too big and I would like to know how to control these margin so that PDF generated looks same as HTML content.

Thanks,
Uday

Hi

Thanks for your inquiry. This occurs because HTML is one page document and this format is designed for Web and not for displaying on pages.
But you can try setting margins using the following code:

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Document doc = new Document("in.htm");

doc.Sections[0].PageSetup.RightMargin = doc.Sections[0].PageSetup.RightMargin - 50;

doc.Sections[0].PageSetup.LeftMargin = doc.Sections[0].PageSetup.LeftMargin - 50;

doc.SaveToPdf("out.pdf");

Best regards,

Thanks for the quick reply.