Thu Oct 03, 2019 12:43 am
Just to clarify i temporarily changed the HTML file extension to txt, but i have been working with html file and i also tried conversion from HTML string. same result.
PdfDocument pdfDocument = new PdfDocument();
PdfPageSettings pdfSet = new PdfPageSettings();
pdfSet.Size = PdfPageSize.Letter;
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = false;
Thread thread = new Thread(()=> {
pdfDocument.LoadFromHTML(filePath, true, true,true,pdfSet, htmlLayoutFormat);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
MemoryStream stream = new MemoryStream();
pdfDocument.SaveToStream(stream, FileFormat.PDF);
byte[] fileBytes = stream.ToArray();
stream.Write(fileBytes, 0, fileBytes.Length);
stream.Position = 0;