The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
Printing solution that is reliable, easy to mantain, no extra libary's needed. Just download the free microsoft word viewer. Make some XML templates and let the code do the job for you.
I search a long time to get a good printing solution that can fill templates an has no need for drivers or references.
First of all we need a word 2003 (or 2007) xml file that whe use as template source. Because this file is not zipped like docx or open source alternatif odt, whe can read it as a text file and replace without any problem. In the XML template we put the 'TEXTFIELDS' for replacement. In this example i use the markers #...# as replacement field.
First whe read the source, do the replacements and the write the temp printfile. So we always keep the original template.
Dim BRONDOCUMENT As String = "test.xml" TEMPDOCUMENT = "TEMP.xml" Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText(BRONDOCUMENT)
fileContents = fileContents.Replace("#NAAM#", "DE CAT BEN")
fileContents = fileContents.Replace("#ADRESSE#", "A STREET IN BELGIUM")
fileContents = fileContents.Replace("#URL#", "<a href="%22http://www.hetnetop.be/%22">WWW.HETNETOP.BE</a>")
fileContents = fileContents.Replace("#CITY#", "KORTRIJK")
My.Computer.FileSystem.WriteAllText(TEMPDOCUMENT, fileContents, False)
Then all whe have to do is to make some buttons, PRINT, VIEW/EDIT and CANCEL.
Process.Start(TEMPDOCUMENT) My.Computer.Keyboard.SendKeys("^p", True)
For Each proc As Process In Process.GetProcesses()
If InStr(proc.MainWindowTitle, "TEMP") > 0 Then proc.CloseMainWindow()
The VIEW/EDIT button is just the cal 'PROCESS.START(TEMPDOCUMENT)' so whe get the wordviewer in all his glory.
And guess, CANCEL just ends the program... Really simple ! but very fast and reliable in practice !
With this concept you can make a universal windows printer engine, with input the source template XML file and one with fill DATA, so you can call this from other programs, without all the problems that printing can give you...
PS: the test file TEST.XML is in the bind\debug dir.