Certi.zip (9.2 KB)
Stream inputstream = new MemoryStream(htmlContent);
// File name for resultant PDF file
// Create PdfRendering Options object
Aspose.Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();// The PageSetup also provides different properties i.e. FirstPage, LastPage, LeftPage, RightPage and they are used to setup (PageSize, Margin) for every page. // In most cases, usage of setup any page is enough, but in some complicated cases, you may need to fine tune page settings. It can be done either by CSS styles or by using rendering options. // the size for drawing is in pixels var width = Aspose.Html.Drawing.Unit.FromMillimeters(297); var height = Aspose.Html.Drawing.Unit.FromMillimeters(420); var pageSizeA3 = new Aspose.Html.Drawing.Size(width, height); pdf_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(pageSizeA3); pdf_options.PageSetup.AdjustToWidestPage = true; Stream outputStream = new MemoryStream(); // Instantiate PdfDevice object while passing PdfRenderingOptions and resultant file path as arguments using (Aspose.Html.Rendering.Pdf.PdfDevice pdf_device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, outputStream)) // Create HtmlRenderer object using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer()) // Create HtmlDocument instance while passing path of already created HTML file using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(inputstream, string.Empty)) { // Render the output using HtmlRenderer renderer.Render(pdf_device, html_document); } Stream alteredoutputStream = ApplyDocumentProperties(outputStream, IsCertificate); byte[] buff = null; BinaryReader br = new BinaryReader(alteredoutputStream); alteredoutputStream.Position = 0; long numBytes = alteredoutputStream.Length; buff = br.ReadBytes((int)numBytes); return buff;<a class="attachment" href="/uploads/default/27676">Certi.zip</a> (9.2 KB)
We are using the Aspose.HTML (18.9.0) and Aspose.PDF (19.1.0) and facing the performance issue with html to pdf conversation.
Please find attached html file in zip and sample code. renderer.Render(pdf_device, html_document); this line taking the 10-14 secs for html to pdf convert.
Thank You in Advance for help!