Long story short: I've had to alter our current project to allow for PDF printing directly from the VB.Net application. I'm using PDFSharp to achieve this, and for the most part I've got it working fine.
However, for part of this it requires a basic type of richtext, which PDFSharp cannot handle. Instead I've written a small thing that basically converts it to HTML and then I can parse it a lot easier and just populate the PDF in that manner.
To do this, I created a separate project to test in, and the following process works:
- Create a richtextbox and a webbrowser
- Populate the richtextbox with the richtext
- Copy the richtext to the clipboard
- Paste the richtext into the WebBrowser documenttext
- Access the body html and use that
However, when I've tried to integrate this into the main project the WebBrowser object only occasionally takes the paste. The majority of the time it comes up blank. As far as I can tell, absolutely everything is identical between the two, except for the fact that in the one it's working everything is happening within a class, and in the one where it isn't it's all within a module. Is there something I should know that I don't regarding these?
Here are the relevant parts of the code:
Private RTF2 As New RichTextBox 'Rich text box to capture original format
Private Browse2 As New WebBrowser 'WebBrowser object
Private HTML2 As New RichTextBox 'Rich text box to put the HTML into so it can be processed
...
'Called on the New() of the Module
Browse2.DocumentText = ""
Browse2.Document.ExecCommand("EditMode", False, Nothing)
...
RTF2.Clear()
RTF2.Rtf = Col1
RTF2.SelectAll()
RTF2.Copy()
Clipboard.SetText(RTF2.Rtf, TextDataFormat.Rtf)
Browse2.Navigate("about:blank")
Browse2.Document.ExecCommand("Paste", False, Nothing)
After this point the Browse2.DocumentText() should be filled with the HTML, like it is in the smaller test project, but I get absolutely nothing.
Any advice would be greatly appreciated.