Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

PrintPreview with help of hta


  • Please log in to reply
1 reply to this topic
GS SAHU
  • Members
  • 20 posts
  • Last active: Oct 28 2015 07:14 PM
  • Joined: 09 Jun 2013

i think ahk required a print preview windows. i am try to full fill this requirement with following code.

Gui, Add, Button,default, PrintPreview
Gui, Add, Edit,w395 h560 vEditbox
Gui, show, w400 h600
return

GuiClose:
ExitApp

buttonPrintPreview:
Gui, Submit, nohide

StringReplace, newtext, Editbox,`n, <br>,all
FileDelete, PrintPreview.hta
preview(newtext)
Run, PrintPreview.hta
return


preview(Text)
{
FileAppend,
(
<html> 
<head>
<script language=vbscript> 
Option Explicit
Dim ie 
Sub PrintPreview() 
Set ie=CreateObject("InternetExplorer.Application") 
ie.Visible=False 
ie.Navigate "about:blank"
setTimeout "PreviewStart",1000 
End Sub 

Sub PreviewStart() 
If ie.Busy Or ie.ReadyState<>4 Then
  setTimeout "PreviewStart",100
Else
  ie.Document.open 
  ie.Document.write document.documentElement.outerHTML 
  ie.Document.close 
  ie.ExecWB 7,0
  setTimeout "PreviewEnd",1000 
End If 
End Sub 

Sub PreviewEnd() 
If ie.Busy Then 
 setTimeout "PreviewEnd",1000 
Else 
 ie.Quit 
End If 
End Sub 
</script> 
</head>
<body onload=PrintPreview()> 

%Text%

</body> 
</html> 

),PrintPreview.hta


}


GS SAHU
  • Members
  • 20 posts
  • Last active: Oct 28 2015 07:14 PM
  • Joined: 09 Jun 2013

other simple version of print preview without hta.

;credit to yoshioka.teruo@nifty.com for vbscript
Gui, Add, Button,ym, PrintPreview
Gui, Add, Edit,w395 h560 vEditbox xm
Gui, show, w400 h600
return

buttonPrintPreview:
Gui, Submit, nohide
StringReplace, newtext, Editbox,`n, <br>,all
preview(newtext)
return


preview(Text)
{
FileDelete, %temp%\PrintPreview.htm
FileAppend,
(
%Text%
),%temp%\PrintPreview.htm
ie := ComObjCreate("InternetExplorer.Application") 
ie.Navigate("about:blank")
While ie.Busy Or ie.ReadyState<>4
  Sleep 100
ie.Document.designMode:="On"
ie.Navigate(A_Temp . "\PrintPreview.htm")
While ie.Busy Or ie.ReadyState<>4
  Sleep 100
ie.ExecWB(7,0)
  While ie.Busy
  Sleep 100
ie.Quit 
}


GuiClose:
ExitApp