Html to pdf A4 size c#

I need to convert dynamic html to pdf which i am doing using stream but am facing issue regarding page width , i want to keep page width as A4 but i am not able to do it.

Code:

Aspose.Pdf.HtmlLoadOptions htmlLoadOptions = new Aspose.Pdf.HtmlLoadOptions();
htmlLoadOptions.PageInfo.Margin.Bottom = 10;
htmlLoadOptions.PageInfo.Margin.Top = 50;
htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
                htmlLoadOptions.PageInfo.Height = Aspose.Pdf.<span style="color:#2b91af;">PageSize</span>.A4.Height;
                <span style="color:green;">//Load HTML string</span>
                Aspose.Pdf.<span style="color:#2b91af;">Document</span> doc = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">Document</span>(<span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(System.Text.<span style="color:#2b91af;">Encoding</span>.UTF8.GetBytes(htmlString)), htmlLoadOptions);

                <span style="color:#2b91af;">MemoryStream</span> outStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();</pre><br><pre style="font-family:Consolas;font-size:13;color:black;background:white;">doc.Save(outStream, Aspose.Pdf.<span style="color:#2b91af;">SaveFormat</span>.Pdf);
                <span style="color:blue;">byte</span>[] content = outStream.ToArray();
                <span style="color:blue;">return</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">FileContentResult</span>(content, <span style="color:#a31515;">"application/pdf"</span>) { FileDownloadName = <span style="color:#a31515;">"Aspose"</span> };</pre>

Hi Akshay,

Thanks for your inquiry. I am afraid we can not set width/height of resultant PDF document less than minimal width/height of actual html page during HTML to PDF conversion. However as a workaround we can resize the contents of resultant PDF document using ResizeContents() method of PdfFileEditor class, please amend your code as following to accomplish the requirement.

However if the problem persist then please share your sample input HTML along with related resources. We will look into it and will guide you accordingly.

var pdfDocument = new Document(input, htmlLoadOptions);

pdfDocument.ProcessParagraphs();

// Resize contents of resultant PDF
int[] page_cnt1 = new int[pdfDocument.Pages.Count];

for (int i = 0; i < pdfDocument.Pages.Count; i++)
    page_cnt1[i] = i + 1;

PdfFileEditor pfe = new PdfFileEditor();

pfe.ResizeContents(pdfDocument, page_cnt1, 
    PdfFileEditor.ContentsResizeParameters.PageResize(Aspose.Pdf.PageSize.A4.Width, Aspose.Pdf.PageSize.A4.Height));

// Save output as PDF format
pdfDocument.Save(outstream);

Please feel free to contact us for any further assistance.

Best Regards,