Convert HTML bytes to PDF | Aspose.PDF for .NET | set PDF Page Margins

Hey

Im trying to set the margines of a Aspose.Pdf.Document.
I have a byte [] in HTML format i want to convert to a new byte [] in PDF format.


The conversion itself is no problem.
But the new document have default margines. I can’t change these.
I tried this (changing all the margines to 0 dosen’t change the resulting pdf:

public static byte[] ConvertHTMLToPDF(byte[] data)
{
LicenseHelper.Instance.SetLicenses();

HtmlLoadOptions htmloptions = new HtmlLoadOptions();
htmloptions.UseNewConversionEngine = true;

using (MemoryStream inStream = new MemoryStream(data))
{
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(inStream, htmloptions);
doc.PageInfo.Margin = new MarginInfo(top: 10, bottom: 10, left: 10, right: 10);
using (MemoryStream outStream = new MemoryStream())
{
doc.Save(outStream);

// Convert the document to byte form.
byte[] docBytes = outStream.ToArray();
return docBytes;
}
}
}

Anyone know how to control the margines?

Hi Mikkel,


Thanks for your inquiry. Please note in HTML to PDF conversion use PageInfo object of HtmlLoadOption, it will help you to control margin of resultant PDF document.

Please feel free to contact us for any further assistance.

Best Regards,

I saw that your examples all use the HtmlLoadOption.PageInfo.
But… for some reason HtmlLoadOption.PageInfo dosen’t exists in the assembly I use.
From comments in code it looks like we use Aspose 8.5.


Hi Mikkel,


Thanks for sharing the details.

Please try using the latest release of Aspose.Pdf for .NET 10.9.0 as the object might have been introduced in versions after 8.5.0. We always encourage our customers to try using latest release as it contains New Features, Enhancements and fixes for issues reported in earlier releases.

Should you have any further query, please feel free to contact.

Is there no waty of optaining the same thing in 8.5.
Updating is a little tricky in our application.

Hi Mikkel,


Thanks for sharing the details.

I am afraid we might not be able to fix the issue in earlier release versions as we maintain a single code base. So we suggest you to please try migrating to latest release. Before upgrading in your production environment, you may consider upgrading in test/staging instance and in case your license do not support the latest release, you may consider requesting a 30 days temporary license to test the latest release version. Please visit Get a temporary license