It opens a printer dialog and prints the file, which could also be a nicely formatted 'c:\test.html'
as well.
It prints headers and footers though..
(Right click int the webgadget to see the html source that does the actual work)
Code: Select all
;-program notes
;-PB4.00, 20061127, utopiomania
;-initialize
;-
enumeration
#win1
#web1
endEnumeration
global path.s
declare openMainWindow()
declare.s createPage(path.s)
;-program entry
openMainWindow()
;-program event handler
repeat
event = waitWindowEvent()
select event
case #PB_Event_Gadget
select eventGadget()
;
endSelect
case #PB_Event_CloseWindow
exit = #True
endSelect
until exit = #True
;-program exit
;-
deleteFile(path)
end
procedure openMainWindow()
flags = #PB_Window_ScreenCentered | #PB_Window_Systemmenu | #PB_Window_MaximizeGadget
if openWindow(#win1, 0, 0, 800, 600, "Javascript print file", flags)
;Create a new gadget list for the current window
if createGadgetList(windowID(#win1))
;Controls
path = getPathPart(programFileName()) + "page.html"
createPage(path)
webGadget(#web1, 0, 0, 800, 600, "file://" + path)
endIf
endIf
endProcedure
procedure.s createPage(path.s)
define s.s, dq.s = chr(34), crlf.s = chr(13) + chr(10)
;create the html string for the page:
s = s + "<html>" + crlf
s = s + "<head>" + crlf
s = s + "<meta http-equiv='MSThemeCompatible' content='yes'> " + crlf
s = s + "" + crlf
s = s + "<script type = 'text/javascript'>" + crlf
s = s + "function printDocument()" + crlf
s = s + "{" + crlf
s = s + " frames['preview'].focus();" + crlf
s = s + " frames['preview'].print();" + crlf
s = s + "}" + crlf
s = s + "</script>" + crlf
s = s + "</head>" + crlf
s = s + "" + crlf
s = s + "<body scroll = 'no'>" + crlf
s = s + "<center>" + crlf
s = s + "<h2>Document Preview</h2>" + crlf
s = s + "<iframe src = 'c:\test.txt' name = 'preview' width = '750' height = '480' " + crlf
s = s + " style = 'border:2px solid #efefef;'>Document preview</iframe>" + crlf
s = s + "" + crlf
s = s + "<p><button type = 'button' onclick = 'printDocument();'>Print This Document</button></p>" + crlf
s = s + "</body>" + crlf
s = s + "</html>" + crlf
if len(path)
;write the string to a file
createFile(0, path)
writeString(0, s)
closeFile(0)
else
;return the string
procedureReturn "about:" + s
endIf
endProcedure