Hello,
We are using aspose for conveting HTML to PDF. In attached scenario, PDF file formatting is not remain same as HTML. The output PDF format is the worst.
Below is source code and attached input HTML file:
byte[] pdfData = null;
string TempFilePath = string.Empty;
string TempFolderPath = System.Web.HttpContext.Current.Server.MapPath("~/TempDir/");if (!Directory.Exists(TempFolderPath)) { Directory.CreateDirectory(TempFolderPath); } TempFilePath = Path.Combine(TempFolderPath, Guid.NewGuid().ToString() + DateTime.Now.ToString("dd-MM-yyyy__hh_mm_ss") + ".pdf"); Aspose.Pdf.HtmlLoadOptions objLoadOptions = new Aspose.Pdf.HtmlLoadOptions(); objLoadOptions.PageInfo.Margin.Bottom = 10; objLoadOptions.PageInfo.Margin.Top = 20; //Load HTML string into MemoryStream using Aspose document class Aspose.Pdf.Document doc = new Aspose.Pdf.Document(new MemoryStream(Encoding.UTF8.GetBytes(html)), objLoadOptions); //Save PDF file on local hard drive or database or as you wish doc.Save(TempFilePath); pdfData = File.ReadAllBytes(TempFilePath);
Input HTML.zip (1.4 KB)