Please see my comment: the code makes no sense. How can you ask about some problem if you are not even trying to do what you wanted to do: converting HTML to PDF. By some reason, you first read the file to a string. You could pass the
StreamReader
instance to
HTMLWorker
directly, but once you use the file content only, you don't touch this file anymore. If you screw up it, you do it somewhere else. No wonder: setting the file name and using for reading in response to the clicks to different buttons is extremely awkward and unsafe. What if you did not select a file before clicking a button for conversion? So, who knows what else could you screw up?
But then, you parse the string with
HTMLWorker
and… do nothing. You don't do anything to PDF document. Who knows what did you mean by that?
Please see this code sample:
http://blog.rubypdf.com/2007/10/10/using-htmlworker-to-parse-html-snippets-and-convert-to-pdf/[
^].
—SA