Created
May 3, 2026 19:56
-
-
Save blog-aspose-cloud/8aa8fce2983a12b9c605796ba368fa2c to your computer and use it in GitHub Desktop.
Convert HTML to PNG in .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using Aspose.Html.Cloud.Sdk.Api; | |
| using Aspose.Html.Cloud.Sdk.Model; | |
| using Aspose.Html.Cloud.Sdk.Client; | |
| class HtmlToPngDemo | |
| { | |
| static void Main() | |
| { | |
| // 1. Configure API client | |
| var config = new Configuration | |
| { | |
| ClientId = "YOUR_CLIENT_ID", | |
| ClientSecret = "YOUR_CLIENT_SECRET", | |
| BaseUrl = "https://api.aspose.cloud" | |
| }; | |
| var htmlApi = new HtmlApi(config); | |
| // 2. Upload source HTML file | |
| string storagePath = "html/source.html"; | |
| using (FileStream htmlStream = File.OpenRead("source.html")) | |
| { | |
| htmlApi.UploadFile(storagePath, htmlStream); | |
| } | |
| // 3. Set PNG export options | |
| var pngOptions = new PngExportOptions | |
| { | |
| Width = 1024, | |
| Height = 768, | |
| Quality = 90 | |
| }; | |
| // 4. Convert HTML to PNG | |
| using (MemoryStream pngStream = htmlApi.ConvertHtmlToPng(storagePath, pngOptions)) | |
| { | |
| // 5. Save PNG locally | |
| using (FileStream file = File.Create("output.png")) | |
| { | |
| pngStream.CopyTo(file); | |
| } | |
| } | |
| Console.WriteLine("Conversion completed. PNG saved as output.png"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment