How to set page margins when converting PDf to Pptx by using aspose.pdf for .NET

I am trying to convert my html document to pptx. Frist I am converting my html to pdf and then pdf to pptx by using aspose,pdf. I want to adjust page margins in the pptx. So I am doing it to pdf and convert it to pptx. But my margins are not changing according to my need, Could you please help me to change margins ???

//this is my convert method

 public List<byte[]> Convert(ContentsDto content, IDictionary<string, string> options, Func<DependentContent, Task<ContentsDto>> GetDependency = null)
    {
        License htmlLicense = new License();
        htmlLicense.SetLicense("Aspose.Total.NET.lic");
        var pdfBytearray = new List<byte[]>();
        
        HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions() { CustomLoaderOfExternalResources = ResourceLoading, HtmlMediaType = HtmlMediaType.Print };

        //Manipulate html document 
        HtmlDocument htmlDocument = new HtmlDocument();
        using (var htmlStream = new MemoryStream(content.Data))
        {
            htmlDocument.Load(htmlStream);              
            AddFroalaCSSSupport(htmlDocument);
        }
        using (var htmlOutputStream = new MemoryStream())
        {
            //convert html to pdf
            htmlDocument.Save(htmlOutputStream);
            htmlOutputStream.Seek(0, System.IO.SeekOrigin.Begin);                               
            Document pdfDocument = new Document(htmlOutputStream, htmlLoadOptions);
            AddFooter(pdfDocument);

            Page page = pdfDocument.Pages.Add();
            MarginInfo marginInfo = new MarginInfo();
            page.PageInfo.Margin.Left=1000;
 
            //convert pdf to pptx
            PptxSaveOptions pptx_save = new PptxSaveOptions();
            using (var pptxStream = new MemoryStream())
            {
                pdfDocument.Save(pptxStream, pptx_save);
                pptxStream.Seek(0, System.IO.SeekOrigin.Begin);
                pdfBytearray.Add(pptxStream.ToArray());
            }
        }
        return pdfBytearray;
    }

//this is my margin changing part in the above method. this is not working. Could you please help me to write the correct solution?

            Page page = pdfDocument.Pages.Add();
            MarginInfo marginInfo = new MarginInfo();
            page.PageInfo.Margin.Left=1000;

@nethmi

Please try to set the page margins while converting HTML to PDF like below in HtmlLoadOptions:

var htmlLoadOptions = new HtmlLoadOptions();
htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
htmlLoadOptions.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
htmlLoadOptions.PageInfo.Margin.Bottom = 40;
htmlLoadOptions.PageInfo.Margin.Top = 80;
htmlLoadOptions.PageInfo.Margin.Left = 0;
htmlLoadOptions.PageInfo.Margin.Right = 0;

In case you still face any issues, please share your sample HTML in .zip format with us along with the expected output PDF/PPTX files. We will test the scenario in our environment and address it accordingly.

1 Like

Hii

This is working. Thank you very much

Hiii
I want to set my PPTX page width as 7.5 inches and height as 13.333 inches. Could you please help me to write a solution???

Hii

I solved this.

thank you

@nethmi

It is good to know that you were able to achieve your requirements. Please keep using our API and feel free to create a new topic in case you need further assistance.

1 Like