How to fit all pages content into one page when converting html to png by using aspose.words in .net

I am converting html document to png. but I need all the content in the word into one png. could you please give me a solution?

var byteArray = new List<byte[]>();

using (var inputStream = new MemoryStream())
{
    HtmlDocument htmlDocument = new HtmlDocument();

    using (var htmlStream = new MemoryStream(content.Data))
    {
        htmlDocument.Load(htmlStream);
        AddCssLinks(options, htmlDocument);
    }

    htmlDocument.Save(inputStream);

    //docOptions.Encoding = new UTF8Encoding(false);
    Document WordDoc = new Document(inputStream);

    using (var outputStream = new MemoryStream())
    {
        WordDoc.Save(outputStream, SaveFormat.Png);
        byteArray.Add(outputStream.ToArray());
    }

}
return byteArray;

@nethmi You can try increasing page height to fit whole document:

Document doc = new Document("C:\\Temp\\in.docx");

PageSetup pageSetup = doc.FirstSection.PageSetup;
double pageContentHeight = pageSetup.PageHeight - pageSetup.TopMargin - pageSetup.BottomMargin;

// Check whether document fits one page. If not increase page height.
while (doc.PageCount > 1)
{
    double addition = doc.PageCount > 2 ? (doc.PageCount - 1) * pageContentHeight : 10;
    pageSetup.PageHeight = pageSetup.PageHeight + addition;
    doc.UpdatePageLayout();
}

doc.Save("C:\\Temp\\out.png");

Please note, the maximum height of page in MS Word is 1584 pt, so you cannot set page height beyond this value using Aspose.Words.

1 Like

Noted.thank you very much

1 Like