I am evaluating using your HTML-to-PDF conversion component for my company's HL7 server reports. I am currently evaluating the free version.
My problem is how to convert from a string containing the HTML to a string containing the PDF (string-to-string). I have loaded the HTML into a memory stream, and using the SaveToStream() method to capture the PDF as a stream. Getting strings to/from streams is the easy part, the problem I'm having is that the component is always throwing an exception. I typically get "Unknown/Invalid/Unsupported format", this is for a simplistic HTML string:
"<!DOCTYPE html><html><body><h1>Header 1</h1><p>First paragraph</p></body></html>";
below is a snippet of the code (just test code) calling the component:
try
{
PdfDocument pdfdoc = new PdfDocument();
byte[] htmlBytes = Encoding.ASCII.GetBytes(html);
pdfdoc.PageSettings.Orientation = PdfPageOrientation.Portrait;
pdfdoc.LoadFromBytes(htmlBytes, string.Empty);
MemoryStream pdfstream = new MemoryStream();
pdfdoc.SaveToStream(pdfstream);
byte[] pdfbytes = pdfstream.ToArray();
pdf = System.Convert.ToBase64String(pdfbytes);
error = "success";
return;
}
catch (Exception e)
{
error = e.Message;
return;
}