Jump to content

Search the Community

Showing results for tags 'Print'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 14 results

  1. First I want to thanks to RoyGlanfield for : Printing RichEdit A long time ago I was wondering how to print RTF files in the background. I just used to use this solution: ShellExecuteWait($sRTF_FileFullPath, '', '', 'print') Unfortunately, it is slow and is not done, in the background. A few days ago I was looking for a solution through google. I found a solution at home and exactly here. I modified it a little, and behold, here it is: #include-once #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #Tidy_Parameters=/sort_funcs /reel #Region RTF PRINTER Include# #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <Array.au3> #EndRegion RTF PRINTER Include# #Region RTF PRINTER HEADER# ; #INDEX# ======================================================================================================================= ; Title .........: UDF for Printing RTF files ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: UDF for Printing RTF files ; Author(s) .....: mLipok, RoyGlanfield ; Modified ......: ; =============================================================================================================================== #cs Title: UDF for Printing RTF files Filename: RTF_Printer.au3 Description: UDF for Printing RTF files Author: RoyGlanfield, mLipok Modified: Last Update: 2014/06/15 Requirements: AutoIt 3.3.10.2 or higher http://www.autoitscript.com/forum/topic/127580-printing-richedit/ http://www.autoitscript.com/forum/topic/161831-rtf-printer-printing-richedit/ Update History: =================================================== 2014/06/04 v0.1 First official version 2014/06/04 v0.2 * Global Variable renaming by adding $__ * extended $__API_RTF_Printer * new function: _RTF_SetMargins($vMarginLeft = 1, $vMarginTop = 1, $vMarginRight = 1, $vMarginBottom = 1) * new function: _RTF_SetNumberOfCopies($iNumberOfCopies = 1) * added #Region RTF PRINTER initialization# * CleanUp * added #forceref * added #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 2014/06/12 v0.3 * Global Variable Renaming add 'RTF' to variable names and added $__ to be sure that no one else used the name * Global Variable renaming $aPageInfo to $__aRTFPageInfo to be sure that no one else used the name * variable renaming $hInput* to $iCtrlInput* * in _RTF_PrintFile() new parameter $fAddIndex * Setting RTF_Printer Window Title * fix problem with printing more than 16 RTF files >> GUIDelete($__API_RTF_Printer[$__hRTF_Gui]) * new internal function __RTF_AddLeadingZeros * added some more comments * brand new RTF_Printer_Examples.au3 2014/06/15 v0.4 * $sRTF_FileFullPath_or_Stream - A string value. Full path to the RTF file to be printed or Stream Data from _GUICtrlRichEdit_StreamToVar * Now you can create documents in RichEdit and print them without the need to save the RTF file. * You can also download the documents from the database and print them without having to save them to disk as RTF files. * new RTF_Printer_Examples.au3 * new #Region MSDN Links , Help, Doc * some minior variable renaming #CE #EndRegion RTF PRINTER HEADER# #Region RTF PRINTER Constants# ; #CONSTANTS# =================================================================================================================== ; $__<UDF>_CONSTANT_<NAME> Global Const $__PDtags = "align 1 ;DWORD lStructSize;" & _ "HWND hwndOwner;" & _ "handle hDevMode;" & _ "handle hDevNames;" & _ "handle hDC;" & _ "DWORD Flags;" & _ "WORD nFromPage;" & _ "WORD nToPage;" & _ "WORD nMinPage;" & _ "WORD nMaxPage;" & _ "WORD nCopies;" & _ "handle hInstance;" & _ "LPARAM lCustData;" & _ "ptr lpfnPrintHook;" & _ "ptr lpfnSetupHook;" & _ "ptr lpPrintTemplateName;" & _ "ptr lpSetupTemplateName;" & _ "handle hPrintTemplate;" & _ "handle hSetupTemplate" Global Enum _ $__hRTF_dcc, _ $__hRTF_Gui, $__hRichEditE, $__hRTF_RichEditPre, _ $__iRTFLabelPagegNow, $__iRTFLabelPagesTotal, _ $__vRTFMarginTop, $__vRTFMarginLeft, $__vRTFMarginRight, $__vRTFMarginBottom, _ $__iRTFNumberOfCopies, _ $__API_RTF_Printer_Count ; , $tDefaultPrinter, _ #EndRegion RTF PRINTER Constants# #Region RTF PRINTER Global Variables# Global $__API_RTF_Printer[$__API_RTF_Printer_Count] Global $__aRTFPageInfo[2]; $__aRTFPageInfo[0]= total num of pages $__aRTFPageInfo[1.....] = 1st char number of each page #EndRegion RTF PRINTER Global Variables# #Region RTF PRINTER initialization# _RTF_SetMargins() _RTF_SetNumberOfCopies() #EndRegion RTF PRINTER initialization# #Region RTF PRINTER CURRENT# ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_PrintFile ; Description ...: Print Selected File in the background or with custom window dialog ; Syntax ........: _RTF_PrintFile($sRTF_FileFullPath_or_Stream[, $sDocTitle = Default[, $fPrintNow = True[, $fAddIndex = False]]]) ; Parameters ....: $sRTF_FileFullPath_or_Stream - A string value. Full path to the RTF file to be printed or Stream Data from _GUICtrlRichEdit_StreamToVar ; $sDocTitle - [optional] A string value. Default is Default. If Default then $sDocTitle = FileName ; $fPrintNow - [optional] A boolean value. Default is True. If true then printing is running in the background. ; $fAddIndex - [optional] A boolean value. Default is False. If true then add Indexing to Document Name in spooler ; Return values .: None ; TODO ; Author ........: mLipok, RoyGlanfield ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/161831-rtf-printer-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func _RTF_PrintFile($sRTF_FileFullPath_or_Stream, $sDocTitle = Default, $fPrintNow = True, $fAddIndex = False) Static $__iRTF_Printer_Counter If $__iRTF_Printer_Counter = '' Then $__iRTF_Printer_Counter = 1 ; chcecking if Streamed Data insteed FileFullPath If StringLeft($sRTF_FileFullPath_or_Stream, 5) = '{\rtf' Then If $sDocTitle = Default Then $sDocTitle = 'RichEdit Data' EndIf Else If Not FileExists($sRTF_FileFullPath_or_Stream) Then Return -1 ; setting DocTitle (document Name in spooler) - if Default then FileName If $sDocTitle = Default Then $sDocTitle = StringRegExp($sRTF_FileFullPath_or_Stream, '(?i).+\\(.+)', 3)[0] EndIf EndIf ; adding index (as prefix) to the DocTitle (document Name in spooler) If $fAddIndex Then $sDocTitle = __RTF_AddLeadingZeros(String($__iRTF_Printer_Counter), 5) & '_' & $sDocTitle EndIf Local $hPrintDc = '' #forceref $hPrintDc Local $__aRTFPageInfo[2]; $__aRTFPageInfo[0]= total num of pages $__aRTFPageInfo[1.....] = 1st char number of each page Local $iPageInPreview = 1 ; the Page Now on show in the preview ; Printer dialog tags Local $tDefaultPrinter = __GetDefaultPrinter() ; Setting RTF_Printer Window Title Local $sRTF_Printer_Title = 'Print RTF ---- ' & $tDefaultPrinter $sRTF_Printer_Title = '[' & String($__iRTF_Printer_Counter) & '] ' & $sRTF_Printer_Title $__API_RTF_Printer[$__hRTF_Gui] = GUICreate($sRTF_Printer_Title, 430, 580, -1, -1) ; Control whose contents is to be printed--------MUST be RichEdit. ; any size will do---- has no effect on the printed copy $__API_RTF_Printer[$__hRichEditE] = _GUICtrlRichEdit_Create($__API_RTF_Printer[$__hRTF_Gui], "", 10, 50, 400, 124, $ES_MULTILINE + $WS_VSCROLL) ;+ $ES_AUTOVSCROLL) ; 21000 push the preview control off the page ; to be resized and positioned after paper size and orientation has been chosen [print dialog or default] $__API_RTF_Printer[$__hRTF_RichEditPre] = _GUICtrlRichEdit_Create($__API_RTF_Printer[$__hRTF_Gui], "", 21000, 10, 10, 10, $ES_MULTILINE) ;+ $ES_AUTOVSCROLL) $__API_RTF_Printer[$__iRTFLabelPagegNow] = GUICtrlCreateLabel("0", 60, 180, 40, 20, $SS_RIGHT) GUICtrlCreateLabel(" of ", 100, 180, 20, 20, $SS_Center) $__API_RTF_Printer[$__iRTFLabelPagesTotal] = GUICtrlCreateLabel("0", 120, 180, 40, 20, $SS_Left) Local $iButtonBack = GUICtrlCreateButton("Back", 160, 180, 50, 20) Local $iButtonNext = GUICtrlCreateButton("Next", 210, 180, 50, 20) Local $iButtonPrintNow = GUICtrlCreateButton("PrintNow", 280, 180, 100, 20) Local $EndPage = '' #forceref $EndPage GUICtrlCreateLabel('Margins-->', 0, 3, 50, 20) GUICtrlCreateLabel(' cm--->', 0, 30, 40, 20) GUICtrlCreateLabel('Left', 50, 3, 30, 15) GUICtrlCreateLabel('Top', 80, 3, 40, 15) GUICtrlCreateLabel('Right', 120, 3, 40, 15) GUICtrlCreateLabel('Bottom', 160, 3, 40, 15) GUICtrlCreateLabel('Copies', 230, 3, 40, 15) Local $iCtrlInputMarginLeft = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginLeft], 40, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginTop = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginTop], 80, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginRight = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginRight], 120, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginBottom = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginBottom], 160, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputNumberOfCopies = GUICtrlCreateInput($__API_RTF_Printer[$__iRTFNumberOfCopies], 230, 25, 40, 20) Local $iButtonPrint = GUICtrlCreateButton("Print", 280, 5, 55, 20) Local $iButtonPrintGeneral = GUICtrlCreateButton("General", 280, 25, 60, 20) Local $iButtonPrintSetup = GUICtrlCreateButton("Print Setup", 335, 5, 75, 20) Local $iButtonNoDialog = GUICtrlCreateButton("No dialog", 340, 25, 70, 20) ; chcecking if Streamed Data insteed FileFullPath If StringLeft($sRTF_FileFullPath_or_Stream, 5) = '{\rtf' Then _GUICtrlRichEdit_StreamFromVar($__API_RTF_Printer[$__hRichEditE], $sRTF_FileFullPath_or_Stream) Else _GUICtrlRichEdit_StreamFromFile($__API_RTF_Printer[$__hRichEditE], $sRTF_FileFullPath_or_Stream) EndIf ; TrayTip('_GUICtrlRichEdit_StreamFromFile',@error,4) ; for test only If $fPrintNow = False Then GUISetState() EndIf ; this does not work ---$r = _GUICtrlRichEdit_SetZoom($__API_RTF_Printer[$__hRichEditE], 1/2)-------------- ; Below works well---but does have to be reset after anything is streamed in------ ; OK--------$r = _SendMessage($h_RichEdit, $EM_SETZOOM, $tDefaultPrinterominator, $denominator) ; $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 1000, 2333) ; must be integer -- "1000, 2333" not "1, 2.333" ; $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 100, 200) ; eg 50% Local $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 100, 300) ; eg 33.3333333333% #forceref $r ; $r = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETZOOM, 100, 500) ; eg 20% Local $z Local $iMsg If $fPrintNow Then ; NO DIALOG ; $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) ; not needed as only prints 1copy ; "No dialog" ---No choices ; prints 1 copy using the default printer's settings $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterNoDialog() If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) EndIf ; PRINT NOW ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then __RTF_Print($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $sDocTitle, $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) $__iRTF_Printer_Counter += 1 Else EndIf $hPrintDc = '' ; GUISetState() ; for test only ; Sleep(3000) ; for test only Else While 1 Sleep(10) $__API_RTF_Printer[$__vRTFMarginLeft] = GUICtrlRead($iCtrlInputMarginLeft) $__API_RTF_Printer[$__vRTFMarginTop] = GUICtrlRead($iCtrlInputMarginTop) $__API_RTF_Printer[$__vRTFMarginRight] = GUICtrlRead($iCtrlInputMarginRight) $__API_RTF_Printer[$__vRTFMarginBottom] = GUICtrlRead($iCtrlInputMarginBottom) $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE GUIDelete() Exit Case $iMsg = $iButtonNoDialog; "No dialog" ; $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) ; not needed as only prints 1copy ; "No dialog" ---No choices ; prints 1 copy ; using the default printer's settings $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterNoDialog() If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintSetup; "PrintSetup" ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterSetup($__API_RTF_Printer[$__iRTFNumberOfCopies]) ; OK-- If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrint; "Print" ; "Print" ---choices-- ; number of copies ; Page range---All, from, to, Selection ; NO-- portrait/landscape choice $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_Printer($__API_RTF_Printer[$__iRTFNumberOfCopies]) ; OK--"Print" dialog If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintGeneral; "General" ; "General" ---choices-- ; number of copies ; Page range---All, Selection ; NO-- portrait/landscape choice----------- $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterGeneral($__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__iRTFNumberOfCopies]) If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintNow; ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then MsgBox(4096, '', __RTF_Print($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $sDocTitle, $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom])) Else EndIf $hPrintDc = '' Case $iMsg = $iButtonNext; If $iPageInPreview < $__aRTFPageInfo[0] Then $iPageInPreview += 1 __NextPage($iPageInPreview) EndIf Case $iMsg = $iButtonBack ; If $iPageInPreview > 1 Then $iPageInPreview -= 1 __NextPage($iPageInPreview) EndIf EndSelect WEnd EndIf ; CleanUp If IsHWnd($__API_RTF_Printer[$__hRTF_Gui]) Then GUIDelete($__API_RTF_Printer[$__hRTF_Gui]) EndFunc ;==>_RTF_PrintFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_SetMargins ; Description ...: Set Margins size in cm [centimeters] ; Syntax ........: _RTF_SetMargins([$vMarginLeft = 1[, $vMarginTop = 1[, $vMarginRight = 1[, $vMarginBottom = 1]]]]) ; Parameters ....: $vMarginLeft - [optional] A variant value. Default is 1. ; $vMarginTop - [optional] A variant value. Default is 1. ; $vMarginRight - [optional] A variant value. Default is 1. ; $vMarginBottom - [optional] A variant value. Default is 1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _RTF_SetMargins($vMarginLeft = 1, $vMarginTop = 1, $vMarginRight = 1, $vMarginBottom = 1) $__API_RTF_Printer[$__vRTFMarginLeft] = $vMarginLeft ; initial minimum Left margin $__API_RTF_Printer[$__vRTFMarginTop] = $vMarginTop ; initial minimum Top margin $__API_RTF_Printer[$__vRTFMarginRight] = $vMarginRight ; initial minimum Right margin $__API_RTF_Printer[$__vRTFMarginBottom] = $vMarginBottom ; initial minimum Bottom margin EndFunc ;==>_RTF_SetMargins ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_SetNumberOfCopies ; Description ...: Set number of copies ; Syntax ........: _RTF_SetNumberOfCopies([$iNumberOfCopies = 1]) ; Parameters ....: $iNumberOfCopies - [optional] An integer value. Default is 1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _RTF_SetNumberOfCopies($iNumberOfCopies = 1) $__API_RTF_Printer[$__iRTFNumberOfCopies] = $iNumberOfCopies ; initial number of Copies to print EndFunc ;==>_RTF_SetNumberOfCopies #EndRegion RTF PRINTER CURRENT# #Region RTF PRINTER INTERNAL# ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterSetup ; Description ...: Get the device context of a "PrinterSetup" Dialog box ; Syntax ........: __GetDC_PrinterSetup([$iCopies = 1]) ; Parameters ....: $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- portrait/landscape, printer, paper size ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterSetup($iCopies = 1) Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Constants--$PD_RETURNDC = 0x100----$PD_PRINTSETUP = 0x40 DllStructSetData($strcPD, "Flags", 0x100 + 0x40) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies ; DllStructSetData($strcPD,"nFromPage", 1) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterSetup ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_Printer ; Description ...: Get the device context of a "Print" Dialog box ; Syntax ........: __GetDC_Printer([$iCopies = 1]) ; Parameters ....: $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- many, but no portrait/landscape ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_Printer($iCopies = 1) Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Constant--$PD_RETURNDC = 0x100 DllStructSetData($strcPD, "Flags", 0x100) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies DllStructSetData($strcPD, "nFromPage", 1) ; start from page # DllStructSetData($strcPD, "nToPage", 0xFFFF) DllStructSetData($strcPD, "nMinPage", 1) DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_Printer ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterNoDialog ; Description ...: Get the device context of the default printer ; Syntax ........: __GetDC_PrinterNoDialog() ; Parameters ....: ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Uses the default printers settings ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterNoDialog() Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Const--RETURNDEFAULT = 0x400---RETURNDC = 0x100----PRINTSETUP = 0x40 DllStructSetData($strcPD, "Flags", 0x100 + 0x40 + 0x400) ; different flags open different dialogue boxes ; DllStructSetData($strcPD, "nCopies", $iCopies) ; only set this if a dialog is shown ; DllStructSetData($strcPD,"nFromPage", 1) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterNoDialog ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterGeneral ; Description ...: Get the device context of a "PrinterSetup General tab" Dialog box ; Syntax ........: __GetDC_PrinterGeneral($hRichEditCtrl[, $iCopies = 1]) ; Parameters ....: $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- many, but no portrait/landscape ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterGeneral($hRichEditCtrl, $iCopies = 1) ; Printer Setup, general options---NO landscape! Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) DllStructSetData($strcPD, "hwndOwner", $hRichEditCtrl) ; ; Constant--$PD_RETURNDC = 0x100 DllStructSetData($strcPD, "Flags", 0x100) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies ; DllStructSetData($strcPD,"nFromPage", 10) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterGeneral ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDefaultPrinter ; Description ...: Get default printer dialog tags ; Syntax ........: __GetDefaultPrinter() ; Parameters ....: ; Return values .: Printer dialog tags ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDefaultPrinter() Local $tags1 = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($tags1)) Local $tags2 = DllStructCreate("char[" & DllStructGetData($tags1, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($tags2), "ptr", DllStructGetPtr($tags1)) Return DllStructGetData($tags2, 1) EndFunc ;==>__GetDefaultPrinter ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __NextPage ; Description ...: Show selected page in preview ; Syntax ........: __NextPage($iPageNumber) ; Parameters ....: $iPageNumber - An integer value. ; Return values .: None ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __NextPage($iPageNumber) ; stream into preview all up to the end of the page to show ; _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRichEditE], 0, $__aRTFPageInfo[$iPageNumber + 1] - 1) ; '-1' because $__aRTFPageInfo[$iPageNumber+1] is the 1st char of next page _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRichEditE], 0, $__aRTFPageInfo[$iPageNumber + 1]) ; '-1' because $__aRTFPageInfo[$iPageNumber+1] is the 1st char of next page Local $stream = _GUICtrlRichEdit_StreamToVar($__API_RTF_Printer[$__hRichEditE]) _GUICtrlRichEdit_StreamFromVar($__API_RTF_Printer[$__hRTF_RichEditPre], $stream) _GUICtrlRichEdit_HideSelection($__API_RTF_Printer[$__hRTF_RichEditPre]) ; now delete all before the page to show this way the font size etc. is continued, rather than reverting to the default. _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRTF_RichEditPre], 0, $__aRTFPageInfo[$iPageNumber]) _GUICtrlRichEdit_ReplaceText($__API_RTF_Printer[$__hRTF_RichEditPre], '') Local $r = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETZOOM, 100, 500) ; eg 20% #forceref $r GUICtrlSetData($__API_RTF_Printer[$__iRTFLabelPagegNow], $iPageNumber) EndFunc ;==>__NextPage Func __RTF_AddLeadingZeros($iDigitToExpand, $iNumberOfDigits) Return StringRight("00000000000000000000000000000000000" & String($iDigitToExpand), $iNumberOfDigits) EndFunc ;==>__RTF_AddLeadingZeros ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __RTF_Preview ; Description ...: Show a "Print Preview" from RichEdit control ; Syntax ........: __RTF_Preview($hPrintDc, $hRichEditCtrl[, $LeftMinMargin = 1[, $TopMinMargin = 1[, $RightMinMargin = 1[, $BottomMinMargin = 1]]]]) ; Parameters ....: $hPrintDc - A handle value. Handle of Printer's device context. ; $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $LeftMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the left. ; $TopMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the top. ; $RightMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Right. ; $BottomMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Bottom. ; Return values .: None ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Orientation, paper size, number of copies, and which printer are set when the Printer's device context is generated. ; Unexpected results may be caused by single line/paragaph orphin tags in the rtf. ; The Preview RichEdit Control is resized and zoomed 20% ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __RTF_Preview($hPrintDc, $hRichEditCtrl, $LeftMinMargin = 1, $TopMinMargin = 1, $RightMinMargin = 1, $BottomMinMargin = 1) ; convert the margins 0.1 inches to twips ; $TopMinMarg = $TopMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $LeftMinMarg = $LeftMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $PageMinMarg = $PageMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $BottomMinMarg = $BottomMinMarg * 144; eg 10*144 = 1440 which 1 inch ; convert the margins 1 cm to twips $TopMinMargin = $TopMinMargin * 567; eg 2.539cm * 567= ~1440 which 1 inch $LeftMinMargin = $LeftMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $RightMinMargin = $RightMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $BottomMinMargin = $BottomMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch ; $hPrintDc ; Divice Context handle----------- ; dots per inch depends on the printer quality setting-------X and Y can be different! Local $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88) ; Const LOGPIXELSX = 88 Local $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90) ; Const LOGPIXELSY = 90 ; printer dots per inch ; get the printable area [Page] and paper area [Paper] Local $vPageWidth = _WinAPI_GetDeviceCaps($hPrintDc, 8) ; Const HORZRES= 8 Local $vPageHeight = _WinAPI_GetDeviceCaps($hPrintDc, 10) ; Const VERTRES = 10 Local $vPaperWidth = _WinAPI_GetDeviceCaps($hPrintDc, 110) ; Const PHYSICALWIDTH = 110 Local $vPaperHeight = _WinAPI_GetDeviceCaps($hPrintDc, 111) ; Const PHYSICALHEIGHT = 111 ; none printable margins Local $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ; Const PHYSICALOFFSETX = 112 Local $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113) ; Const PHYSICALOFFSETY = 113 Local $vRightMargin = $vPaperWidth - $vPageWidth - $OffSetX Local $vBottomMargin = $vPaperHeight - $vPageHeight - $OffSetY ; conversion factors to use later----------- Local $TwipsInchX = $dotInchX / 1440 ; convert dots to twips [per inch] Local $TwipsInchY = $dotInchY / 1440 ; convert dots to twips [per inch] ; convert all measurments to twips $OffSetX = $OffSetX / $TwipsInchX ; convert Left dots to twips $OffSetY = $OffSetY / $TwipsInchY ; convert Left dots to twips $vPageWidth = $vPageWidth / $TwipsInchX ; convert Right dots to twips $vPageHeight = $vPageHeight / $TwipsInchY ; convert Right dots to twips $vPaperWidth = $vPaperWidth / $TwipsInchX ; convert Paper Width dots to twips $vPaperHeight = $vPaperHeight / $TwipsInchY ; convert Paper Width dots to twips ; Set the margins and keep everything in the printable area Local $Left1 = $LeftMinMargin - $OffSetX If $Left1 < 0 Then $Left1 = 0 ; dont print before printable area starts Local $Top1 = $TopMinMargin - $OffSetY If $Top1 < 0 Then $Top1 = 0 ; dont print before printable area starts Local $Right1 = $RightMinMargin - $vRightMargin If $Right1 < 0 Then $Right1 = 0 ; dont print after printable area ends ; $Right1 = $vPaperWidth - $Right1 - $OffSetX $Right1 = $vPageWidth - $Right1 ; $OffSetX+$Left1-$vRightMargin Local $Bottom1 = $BottomMinMargin - $vBottomMargin If $Bottom1 < 0 Then $Bottom1 = 0 ; dont print after printable area ends $Bottom1 = $vPageHeight - $Bottom1 Local $z = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETTARGETDEVICE, $hPrintDc, $Right1 - $Left1) ; If $z = 0 Then Return 'Cant find RichEdit Control' If _GUICtrlRichEdit_GetTextLength($hRichEditCtrl) < 1 Then Return 'Nothing to Print.' ; must have a selection on the richEdit control--------------- _SendMessage($hRichEditCtrl, $EM_SETSEL, 0, -1) ; ok----select all Local $dcHTags = "HANDLE hdc;HANDLE hdcTarget;" Local $pgTags = "int Left1 ;int Top1 ;int Right1 ;int Bottom1 ;int Left2;int Top2;int Right2;int Bottom2;" Local $rgTags = "LONG cpMin;LONG cpMax" ; create a structure for the printed page Local $strcPage = DllStructCreate($dcHTags & $pgTags & $rgTags) DllStructSetData($strcPage, "hdc", $hPrintDc) ; printer DllStructSetData($strcPage, "Left1", $Left1) ; twip--------printer DllStructSetData($strcPage, "Right1", $Right1) ; twip--------printer DllStructSetData($strcPage, "Top1", $Top1) ; twip--------printer DllStructSetData($strcPage, "Bottom1", $Bottom1) ; twip--------printer ; next 7 lines seem to have, no effect or crash printer jobs queue---why??? ; "HANDLE hdc;" is the printer------- before conecting printer to rtf??? ; "HANDLE hdcTarget;" is the target RichEdit control that has the rtf ???? ; DllStructSetData($strcPage,"hdcTarget",$hPrintDc) ; richEdit scource??? ; DllStructSetData($strcPage,"Left2",$Left1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Top2",$Top1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Right2",$Page1/$dotInchX*96/3) ; twip------richEdit scource??? ; DllStructSetData($strcPage,"Bottom2",$Bottom1/$dotInchX*96/3) ; twip-----richEdit scource??? ; get the pointer to all that will be printed??? {I think????????} Local $a = DllStructGetPtr($strcPage) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags)) ; use this pointer----------- _SendMessage($hRichEditCtrl, $EM_EXGETSEL, 0, $a) ReDim $__aRTFPageInfo[2] $__aRTFPageInfo[1] = 1 $__aRTFPageInfo[0] = 0 ; the total number of pages Local $iPageInPreview = 1 ; the page number of the preview now showing #forceref $iPageInPreview ; find the last char of the document to be printed Local $cpMax = DllStructGetData($strcPage, "cpMax") ; set the 1st page start char----------- Local $cpMin = 0 Local $cpMin2 = -1 ; ----------------------------------------------------------- ; make a loop to format each printed page and exit when ; $cpMin reaches the $cpMax ; $cpMin is less than 0---{I have seen -1 but I forget when}--- ; ALSO-- ExitLoop if $cpMin = $cpMin 2---if it stops finding the start of next page While $cpMax > $cpMin And $cpMin > -1 ; get the 1st char of the next page, {but how does it work ???} $cpMin2 = $cpMin $cpMin = _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, True, DllStructGetPtr($strcPage)) If $cpMin2 = $cpMin Then ExitLoop; get out of loop before more pages are added ; set the next page start char----------- DllStructSetData($strcPage, "cpMin", $cpMin) $__aRTFPageInfo[0] += 1 ; increment page the total page count ; update array --- for what to show in the preview _ArrayAdd($__aRTFPageInfo, $cpMin) ; start char-number of each page ; end the page and loop again for the next page until the end of document WEnd _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, False, 0) ; adjust the preview shape/size WinMove($__API_RTF_Printer[$__hRTF_RichEditPre], '', 210 - $vPaperWidth / 1440 * 96 / 5 / 2, 200, $vPaperWidth / 1440 * 96 / 5 + 15, $vPaperHeight / 1440 * 96 / 5 + 15) ; the printer starts printing at offsetX and offsetY but the preview windiw starts at 1 and 1 ; so add offsetX and offsetY to the page margins to the printer would use _GUICtrlRichEdit_SetRECT($__API_RTF_Printer[$__hRTF_RichEditPre], ($Left1 + $OffSetX) / $dotInchX * 96 / 5, ($Top1 + $OffSetY) / $dotInchY * 96 / 5, 460, 500) __NextPage(1) GUICtrlSetData($__API_RTF_Printer[$__iRTFLabelPagesTotal], $__aRTFPageInfo[0]) Return $__aRTFPageInfo[0] EndFunc ;==>__RTF_Preview ; #FUNCTION# ==================================================================================================================== ; Name ..........: __RTF_Print ; Description ...: Print from RichEdit control ; Syntax ........: __RTF_Print($hPrintDc, $hRichEditCtrl, $sDocTitle[, $LeftMinMargin = 1[, $TopMinMargin = 1[, $RightMinMargin = 1[, ; $BottomMinMargin = 1]]]]) ; Parameters ....: $hPrintDc - A handle value. Printer's device context. ; $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $sDocTitle - An unknown value. Printer's job title. ; $LeftMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the left ; $TopMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Top ; $RightMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Right ; $BottomMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Bottom ; Return values .: Success - 'Sent to the printer.' ; Failure - 'Printing aborted.' ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Orientation, paper size, number of copies, and which printer are set when the Printer's device context is generated. ; Unexpected results may be caused by single line/paragaph orphin tags in the rtf. ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __RTF_Print($hPrintDc, $hRichEditCtrl, $sDocTitle, $LeftMinMargin = 1, $TopMinMargin = 1, $RightMinMargin = 1, $BottomMinMargin = 1) ; convert the margins 0.1 inches to twips ; $TopMinMarg = $TopMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $LeftMinMarg = $LeftMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $PageMinMarg = $PageMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $BottomMinMarg = $BottomMinMarg * 144; eg 10*144 = 1440 which 1 inch ; convert the margins 1 cm to twips $TopMinMargin = $TopMinMargin * 567; eg 2.539cm * 567= ~1440 which 1 inch $LeftMinMargin = $LeftMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $RightMinMargin = $RightMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $BottomMinMargin = $BottomMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch ; $hPrintDc ; Divice Context handle----------- ; dots per inch depends on the printer quality setting-------X and Y can be different! Local $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88) ; Const LOGPIXELSX = 88 Local $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90) ; Const LOGPIXELSY = 90 ; printer dots per inch ; get the printable area [Page] and paper area [Paper] Local $vPageWidth = _WinAPI_GetDeviceCaps($hPrintDc, 8) ; Const HORZRES= 8 Local $vPageHeight = _WinAPI_GetDeviceCaps($hPrintDc, 10) ; Const VERTRES = 10 Local $vPaperWidth = _WinAPI_GetDeviceCaps($hPrintDc, 110) ; Const PHYSICALWIDTH = 110 Local $vPaperHeight = _WinAPI_GetDeviceCaps($hPrintDc, 111) ; Const PHYSICALHEIGHT = 111 ; none printable margins Local $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ; Const PHYSICALOFFSETX = 112 Local $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113) ; Const PHYSICALOFFSETY = 113 Local $vRightMargin = $vPaperWidth - $vPageWidth - $OffSetX Local $vBottomMargin = $vPaperHeight - $vPageHeight - $OffSetY ; conversion factors to use later----------- Local $TwipsInchX = $dotInchX / 1440 ; convert dots to twips [per inch] Local $TwipsInchY = $dotInchY / 1440 ; convert dots to twips [per inch] ; convert all measurments to twips $OffSetX = $OffSetX / $TwipsInchX ; convert Left dots to twips $OffSetY = $OffSetY / $TwipsInchY ; convert Left dots to twips $vPageWidth = $vPageWidth / $TwipsInchX ; convert Right dots to twips $vPageHeight = $vPageHeight / $TwipsInchY ; convert Right dots to twips $vPaperWidth = $vPaperWidth / $TwipsInchX ; convert Paper Width dots to twips $vPaperHeight = $vPaperHeight / $TwipsInchY ; convert Paper Width dots to twips ; Set the margins and keep everything in the printable area Local $Left1 = $LeftMinMargin - $OffSetX If $Left1 < 0 Then $Left1 = 0 ; dont print before printable area starts Local $Top1 = $TopMinMargin - $OffSetY If $Top1 < 0 Then $Top1 = 0 ; dont print before printable area starts Local $Right1 = $RightMinMargin - $vRightMargin If $Right1 < 0 Then $Right1 = 0 ; dont print after printable area ends ; $Right1 = $vPaperWidth - $Right1 - $OffSetX $Right1 = $vPageWidth - $Right1 ;+$Left1 ; $OffSetX Local $Bottom1 = $BottomMinMargin - $vBottomMargin If $Bottom1 < 0 Then $Bottom1 = 0 ; dont print after printable area ends $Bottom1 = $vPageHeight - $Bottom1 ;+$Top1 Local $z = _SendMessage($hRichEditCtrl, $EM_SETTARGETDEVICE, 0) ; 0=wrap----anything else is 1 char per page!!!!! If $z = 0 Then Return 'Cant find RichEdit Control' If _GUICtrlRichEdit_GetTextLength($hRichEditCtrl) < 1 Then Return 'Nothing to Print.' ; must have a selection on the richEdit control--------------- _SendMessage($hRichEditCtrl, $EM_SETSEL, 0, -1) ; ok----select all Local $pgTags = "int Left1 ;int Top1 ;int Right1 ;int Bottom1 ;int Left2;int Top2;int Right2;int Bottom2;" Local $rgTags = "LONG cpMin;LONG cpMax" Local $dcHTags = "HANDLE hdc;HANDLE hdcTarget;" ; create a structure for the printed page Local $strcPage = DllStructCreate($dcHTags & $pgTags & $rgTags) DllStructSetData($strcPage, "hdc", $hPrintDc) ; printer DllStructSetData($strcPage, "Left1", $Left1) ; twip--------printer DllStructSetData($strcPage, "Right1", $Right1) ; twip--------printer DllStructSetData($strcPage, "Top1", $Top1) ; twip--------printer DllStructSetData($strcPage, "Bottom1", $Bottom1) ; twip--------printer ; next 7 lines seem to have, no effect or crash printer jobs queue---why??? ; "HANDLE hdc;" is the printer------- before conecting printer to rtf??? ; "HANDLE hdcTarget;" is the target RichEdit control that has the rtf ???? ; DllStructSetData($strcPage,"hdcTarget",$hPrintDc) ; richEdit scource??? ; DllStructSetData($strcPage,"Left2",$Left1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Top2",$Top1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Right2",$Page1/$dotInchX*96/3) ; twip------richEdit scource??? ; DllStructSetData($strcPage,"Bottom2",$Bottom1/$dotInchX*96/3) ; twip-----richEdit scource??? ; get the pointer to all that will be printed??? {I think????????} Local $a = DllStructGetPtr($strcPage) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags)) ; use this pointer----------- _SendMessage($hRichEditCtrl, $EM_EXGETSEL, 0, $a) ; find the last char of the document to be printed Local $cpMax = DllStructGetData($strcPage, "cpMax") ; set the 1st page start char----------- Local $cpMin = 0 Local $cpMin2 = -1 ; ----------------------------------------------------------- ; create a Document structure for the print job title Local $strDocNm = DllStructCreate("char DocName[" & StringLen($sDocTitle & Chr(0)) & "]") DllStructSetData($strDocNm, "DocName", $sDocTitle & Chr(0)) Local $strDoc = DllStructCreate("int Size;ptr DocName;ptr Output;ptr Datatype;dword Type") DllStructSetData($strDoc, "Size", DllStructGetSize($strDoc)) ; insert the document name structure into the document structure DllStructSetData($strDoc, "DocName", DllStructGetPtr($strDocNm)) DllCall("gdi32.dll", "long", "StartDoc", "hwnd", $hPrintDc, "ptr", DllStructGetPtr($strDoc)) ; ----------------------------------------------------------- ; make a loop to format each printed page and exit when ; $cpMin reaches the $cpMax ; $cpMin is less than 0---{I have seen -1 but I forget when}--- ; ALSO-- ExitLoop if $cpMin = $cpMin 2---if it stops finding the start of next page Local $StartPage, $EndPage #forceref $StartPage While $cpMax > $cpMin And $cpMin > -1 ; start a new page----------- $StartPage = DllCall("Gdi32.dll", "int", "StartPage", "HANDLE", $hPrintDc) ; increment page the count----------- ; if not done now it will exit the loop before counting the last page ; get the 1st char of the next page, {but how does it work ???} $cpMin2 = $cpMin $cpMin = _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, True, DllStructGetPtr($strcPage)) ; ExitLoop when $cpMin = $cpMin 2---just in case it stops finding the start of next page If $cpMin2 = $cpMin Then ExitLoop; get out of loop before more pages are added ; set the next page start char----------- DllStructSetData($strcPage, "cpMin", $cpMin) ; this sends it to the printer $EndPage = DllCall("Gdi32.dll", "int", "EndPage", "HANDLE", $hPrintDc) ; end the page and loop again for the next page until the end of document WEnd _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, False, 0) If $EndPage[0] > 0 Then DllCall("Gdi32.dll", "int", "EndDoc", "HANDLE", $hPrintDc) Return 'Sent to the printer.' Else DllCall("Gdi32.dll", "int", "AbortDoc", "HANDLE", $hPrintDc) Return 'Printing aborted.' EndIf EndFunc ;==>__RTF_Print #EndRegion RTF PRINTER INTERNAL# #Region MSDN Links , Help, Doc ;~ How to Print the Contents of Rich Edit Controls ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/bb787875(v=vs.85).aspx ;~ http://blogs.msdn.com/b/oldnewthing/archive/2007/01/12/1455972.aspx ;~ How To Use GetDeviceCaps to Determine Margins on a Page ;~ http://support.microsoft.com/kb/193943 ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd162833(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd162931(v=vs.85).aspx ;~ http://support.microsoft.com/kb/139652 ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646962(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646964(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646966(v=vs.85).aspx #EndRegion MSDN Links , Help, Doc HOW TO USE THIS: #include-once #include <RTF_Printer.au3> _RTF_PrintFile($sRTF_FileFullPath, Default, True, True) ; or take a look in attached RTF_Printer_Examples.au3 ; Regards mLipok EDIT: attachment changed (before 6 downloads) RTF_Printer.au3.Download.html
  2. Version 0.0.1

    526 downloads

    by eltorro Posted April 26, 2010 Most print preview solutions use the MFC Doc/View architecture which limits it usefulness outside of c++. I found an article where a Delphi programmer used Enhanced Meta Files wrapped in a custom header and packaged together to create a print preview control. After a little more searching, It looks like using EMFs is a solution that would work. Some people suggest to create the document in Word or HTML and use Word or a browser to view it. Indeed, I have rendered documents to HTML and used the IE UDF to display the contents and/or print them. Not quite as ideal as one would like. Using GRS's printwin.au3 as a start, I came up with a print preview solution which others may be able to expand upon
  3. Hi everyone. I want to format the output of _INetGetSource to look nice and pretty. Example google.com source output: <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script>(function(){window.google={kEI:'DJtTWvCOI6WGjwSE9JrICg',kEXPI:'18167,1354277,1354916,1355218,1355675,1355793,1356171,1356806,1357219,1357326,3700304,3700519,3700521,4003510,4029815,4031109,4043492,4045841,4048347,4081038,4081164,4095909,4096834,4097153,4097195,4097922,4097929,4098733,4098740,4098752,4102237,4102827,4103475,4103845,4106084,4107914,4109316,4109490,4112770,4113217,4115697,4116349,4116724,4116731,4116926,4116927,4116935,4117980,4118798,4119032,4119034,4119036,4120285,4120286,4120660,4121175,4121518,4122511,4123830,4123850,4124091,4124850,4125837,4126202,4126754,4126869,4127262,4127418,4127473,4127744,4127863,4128586,4128622,4129001,4129520,4129556,4129633,4130362,4130783,4131247,4131834,4132956,4133114,4133509,4135025,4135088,4135249,4135934,4136073,4136092,4136137,4137597,4137646,4140792,4140849,4141281,4141707,4141915,4142071,4142328,4142420,4142443,4142503,4142678,4142729,4142829,4142834,4142847,4143278,4143527,4143902,4144442,4144550,4144704,4145074,4145075,4145082,4145088,4145461,4145485,4145622,4145688,4145713,4145836,4146146,4146183,4146874,4147032,4147043,4147096,4147443,4147800,4147951,4148257,4148304,4148436,4148498,4148573,6512220,10200083,10202524,10202562,15807763,19000288,19000423,19000427,19001999,19002287,19002288,19002366,19002548,19002880,19003321,19003323,19003325,19003326,19003328,19003329,19003330,19003407,19003408,19003409,19004309,19004516,19004517,19004518,19004519,19004520,19004521,19004531,19004656,19004668,19004670,19004692,41317155',authuser:0,kscs:'c9c918f0_DJtTWvCOI6WGjwSE9JrICg',u:'c9c918f0',kGL:'US'};google.kHL='en';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var b;a&&(!a.getAttribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||google.kEI};google.getLEI=function(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b};google.https=function(){return"https:"==window.location.protocol};google.ml=function(){return null};google.wl=function(a,b){try{google.ml(Error(a),!1,b)}catch(d){}};google.time=function(){return(new Date).getTime()};google.log=function(a,b,d,c,g){if(a=google.logUrl(a,b,d,c,g)){b=new Image;var e=google.lc,f=google.li;e[f]=b;b.onerror=b.onload=b.onabort=function(){delete e[f]};google.vel&&google.vel.lu&&google.vel.lu(a);b.src=a;google.li=f+1}};google.logUrl=function(a,b,d,c,g){var e="",f=google.ls||"";d||-1!=b.search("&ei=")||(e="&ei="+google.getEI(c),-1==b.search("&lei=")&&(c=google.getLEI(c))&&(e+="&lei="+c));c="";!d&&google.cshid&&-1==b.search("&cshid=")&&(c="&cshid="+google.cshid);a=d||"/"+(g||"gen_204")+"?atyp=i&ct="+a+"&cad="+b+e+f+"&zx="+google.time()+c;/^http:/i.test(a)&&google.https()&&(google.ml(Error("a"),!1,{src:a,glmm:1}),a="");return a};}).call(this);(function(){google.y={};google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};}).call(this);google.f={};var a=window.location,b=a.href.indexOf("#");if(0<=b){var c=a.href.substring(b+1);/(^|&)q=/.test(c)&&-1==c.indexOf("#")&&a.replace("/search?"+c.replace(/(^|&)fp=[^&]*/g,"")+"&cad=h")};</script><style>#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important} But I want it outputted like this: <!doctype html> <html itemscope="" itemtype="http://schema.org/WebPage" lang="en"> <head> <meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"> <meta content="noodp" name="robots"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"> <title>Google</title> <script> (function() { window.google = { kEI: 'DJtsdfgWGjwSE9JrICg', kEXPI: '18167,1354277,1354916,1355218,1355675,1355793,1356171,1356806,1357219,1357326,37sdfg0304,3700519,3700521,4003510,4029815,4031109,4043492,4045841,4048347,4081038,4081164,4095909,4096834,4097153,4097195,4097922,4097929,4098733,4098740,4098752,4102237,4102827,4103475,4103845,4106084,4107914,4109316,4109490,4112770,4113217,4115697,4116349,4116724,4116731,4116926,4116927,4116935,4117980,4118798,4119032,4119034,4119036,4120285,4120286,4120660,4121175,4121518,4122511,4123830,4123850,4124091,4124850,4125837,4126202,4126754,4126869,4127262,4127418,4127473,4127744,4127863,4128586,4128622,4129001,4129520,4129556,4129633,4130362,4130783,4131247,4131834,413sdfg56,4133114,4133509,4135025,4135088,4135249,4135934,4136073,4136092,4136137,4137597,4137646,4140792,4140849,4141281,4141707,4141915,4142071,4142328,4142420,4142443,4142503,4142678,4142729,4142829,4142834,4142847,4143278,4143527,4143902,4144442,4144550,4144704,4145074,4145075,4145082,4145088,4145461,4145485,4145622,4145688,4145713,4145836,4146146,4146183,4146874,4147032,4147043,4147096,4147443,4147800,4147951,4148257,4148304,4148436,4148498,4148573,6512220,10200083,10202524,10202562,15807763,19000288,190sdfg23,19000427,19001999,19002287,19002288,19002366,19002548,19002880,19003321,19003323,19003325,19003326,19003328,19003329,19003330,19003407,19003408,19003409,19004309,19004516,19004517,19004518,19004519,19004520,19004521,19004531,19004656,19004668,19004670,19004692,41317155', authuser: 0, kscs: 'c9c918f0_DJtTWvCOI6WGjwSE9JrICg', u: 'c9c918f0', kGL: 'US' }; google.kHL = 'en'; })(); ....... I checked the forums and did not see any UDFs that allow for this. I see the Chilkat UDF but that only supports JSON. Any help would be greatly appreciated.
  4. Hello I am trying to get chrome to save it's current webpage to a pdf using autoit. I wold like to save the file into a folder on the desktop called "ChromeFiles" . However when I use the send command chrome only occasionally responds. Thank you Simon
  5. When I click on print button (Javascript Button) in webpage using _IEAction($btnprint,"click") then display print dialog, like this one: i want to Automate this print dialog box and print file using default printer. (not using controlclick). its possible to print without showing print dialog box?
  6. hallo autoit community i ask how to create bill temple and insert data to it then print it thanks
  7. Hi guys Looking to automate...I have PDF files...Need to convert them all to 2 pages each but more specifically, retain only the first and last. Searched a lot and hitting the wall....Any ideas? Just directions would do... Not sure how to "print to file" and I believe |ShellExecuteWait($sFilePath, " /h /p", "", "print", @SW_HIDE)| doesn't give options of what pages...
  8. I have a project to print a prn printfile to a barcode printer. File is both binary (fonts and pictures) and text mixed in a format understandable for the printer. I need some advice about the methode to deal and use windows printer spooler. The printers could be connected in network or localy by USB, so easiest is to make that connection by windows. I have not found any easy way to print in the site, just how to setup a new printer or change parameters. I thought printing was the easy part. My program should be used by windows vista, 7, 8 and 10 and sometime in POS environment. Right now I print by FTP to CAB printers, but its not always accepted in some networks or by firewalls. I need to change it, and also be open to use other printers. The option I have seen is windows LPR command, but I dont know if its usable in all windows versions or if it behave different. I tested it from cmd.exe, but have not succeded for the printers I normaly use. Copy to LPT or COM is also an alternative. DIsadvantage is I need to change in driver to connect LPT/COM to the printer and not userfriendly to install. I want a solid solution, not complicated for the user and easy to understand and maintain. Just a procedure in Auto-IT like 'Print ("Printer name", "File")' to put it in the que, and leave the printer maintain to windows. Any ideas or considirations? Where to begin? (soory for the speling, not my naitive language)
  9. Hello everyone, here is my little contribution to AutoIt community. I was looking for a way to print tables from my scripts. None of the solutions was exactly working for me as there were always some limitations. If you need to be able to print table, while making sure that header is printed on each page (if large table), rows won't split up(across several pages) and you want to be able to adjust table size on page or each column size, you in the right place. Also you can choose between landscape and portrait mode It uses a browser to print table out. Simply, it generates a html file which is then open within browser and it initialize print. This version is tested with Chrome browser... Please be aware that there is a bug. When you try to disable row numbers, it will also remove table borders(lines). If anybody can figure out why, it would be appreciated by me and I am sure by others as well. Enjoy Jan UPDATE: found today that geniuses from Google stopped following standards and it no longer prints correctly with Chrome. It also ignores the portrait/landscape settings. However, I tested it with latest IE on Win 7 and it works fine!!! so I suggest you use IE to print... In case you don't have IE as main browser and you do have issues with your current browser then replace shellexecute and winwaitactive at the end of function with: local $hIE=run('"C:\Program Files\Internet Explorer\iexplore.exe" "' & $sFile & '"') ProcessWait($hIE) ; AutoIt Version: 3.3.10 ; Language: English ; Platform: Win ; Author: Jan Zoudlik ; NOTE: big thanks to DoctorDestructo from http://stackoverflow.com/ for main script with css styling etc ; and guinness, tproli, Lupo73 from https://www.autoitscript.com/forum/ for inspiration with their listview to html function ; Script Function: ; table print - example + _table_print function #include <File.au3> Local $aTestArray[4][4] = [[20, 50, 20, 7], ["head", "heading<br/>accross two lines", "heading", "X"],["data row 1",5,"data",6],["data row 2",5&"<br/>"&6,"data",6]] _table_print("test title",100,$aTestArray,True) Func _table_print($Title,$Table_Size,ByRef $2D_array, $Landscape=True, $Row_Numbers=True) ;table that will print as table should (tested with chrome and ie browsers)> header on each page, table cell won't be printed across two pages > so even multi line row will always stay on one page or will be as whole pushed to next page ;to break the line within the cell or heading use "<br/>" not @LF or @CRLF as it is html... if word within cell is wider then column width it will adjust columnm width so word will fit, it will auto(line)break sentance if wider than column ;the allingment withing table is : vertical middle - horizontal left(header is vertical down - horizontal middle) and row numbers are vertical middle - horizontal right... sufficient for me... ;file name automatically generated and saved in temp folder ;Title - self explaining - displayed on the top of the table on first page only ;Table_Size - in percent - how big table(width) should be compare to the paper size so 100 - table will spread accross whole paper printable area, 50 - table size will be approx half of the paper size ;2D_array - row 0, number in percent per each column (width of column) - all together it should add up 100%(97% if row_numbers are used as 3% is used as size for row count column) ;2D_array - row 1, column header - will repeat on each page ;2D_array - row 2-n, data ;$Row_Numbers - first column will contain row number(so there will be one extra column in table) ;$Landscape - to print in landscape or portrait mode... ;paper size is as per printer settings ;font size is set to 10; if adjustment needed for blind people, then search for font-size: 10px; and don't forget to also adjust line-height: 13px accordingly(so it is bigger than font) ;_table_print function CREATED BY Jan Zoudlik ;big thanks to DoctorDestructo from http://stackoverflow.com/ for main script with css styling etc and guinness, tproli, Lupo73 from https://www.autoitscript.com/forum/ for inspiration with their listview to html function $sHTMLTable='<!DOCTYPE html>' & @CRLF & _ '<html>' & @CRLF & _ ' <body>' & @CRLF & _ ' <table ' if $Row_Numbers then $sHTMLTable=$sHTMLTable & 'class="print t1" ' $sHTMLTable=$sHTMLTable & 'width="' & $Table_Size & '%"> <!-- Delete "t1" class to remove row numbers. -->' & @CRLF & _ ' <caption>' & $Title & '</caption>' & @CRLF if $Row_Numbers then $sHTMLTable=$sHTMLTable & ' <col width="3%">' & @CRLF for $column=0 to ubound($2D_array,2)-1 $sHTMLTable=$sHTMLTable & ' <col width="' & $2D_array[0][$column] & '%">' & @CRLF Next $sHTMLTable=$sHTMLTable & ' <thead>' & @CRLF & _ ' <tr>' & @CRLF if $Row_Numbers then $sHTMLTable=$sHTMLTable & ' <th>#</th>' & @CRLF for $column=0 to ubound($2D_array,2)-1 $sHTMLTable=$sHTMLTable & ' <th>' & $2D_array[1][$column] & '</th>' & @CRLF Next $sHTMLTable=$sHTMLTable & ' </tr>' & @CRLF & _ ' </thead>' & @CRLF & _ ' <tbody>' & @CRLF for $row=2 to ubound($2D_array)-1 $sHTMLTable=$sHTMLTable & ' <tr>' & @CRLF if $Row_Numbers then $sHTMLTable=$sHTMLTable & ' <td></td>' & @CRLF for $column=0 to ubound($2D_array,2)-1 $sHTMLTable=$sHTMLTable & ' <td>' & $2D_array[$row][$column] & '</td>' & @CRLF Next $sHTMLTable=$sHTMLTable & ' </tr>' & @CRLF Next $sHTMLTable=$sHTMLTable & ' </tbody>' & @CRLF & _ ' </table>' & @CRLF & _ ' </body>' & @CRLF & _ '</html>' & @CRLF $sCSSstyle='<style>' & @CRLF & _ ' /* THE FOLLOWING CSS IS REQUIRED AND SHOULD NOT BE MODIFIED. */' & @CRLF & _ ' div.fauxRow {' & @CRLF & _ ' display: inline-block;' & @CRLF & _ ' vertical-align: top;' & @CRLF & _ ' width: 100%;' & @CRLF & _ ' page-break-inside: avoid;' & @CRLF & _ ' }' & @CRLF & _ ' table.fauxRow {border-spacing: 0;}' & @CRLF & _ ' table.fauxRow > tbody > tr > td {' & @CRLF & _ ' padding: 0;' & @CRLF & _ ' overflow: hidden;' & @CRLF & _ ' }' & @CRLF & _ ' table.fauxRow > tbody > tr > td > table.print {' & @CRLF & _ ' display: inline-table;' & @CRLF & _ ' vertical-align: top;' & @CRLF & _ ' }' & @CRLF & _ ' table.fauxRow > tbody > tr > td > table.print > caption {caption-side: top;}' & @CRLF & _ ' .noBreak {' & @CRLF & _ ' float: right;' & @CRLF & _ ' width: 100%;' & @CRLF & _ ' visibility: hidden;' & @CRLF & _ ' }' & @CRLF & _ ' .noBreak:before, .noBreak:after {' & @CRLF & _ ' display: block;' & @CRLF & _ ' content: "";' & @CRLF & _ ' }' & @CRLF & _ ' .noBreak:after {margin-top: -594mm;}' & @CRLF & _ ' .noBreak > div {' & @CRLF & _ ' display: inline-block;' & @CRLF & _ ' vertical-align: top;' & @CRLF & _ ' width:100%;' & @CRLF & _ ' page-break-inside: avoid;' & @CRLF & _ ' }' & @CRLF & _ ' /*table.print > thead {white-space: nowrap;}*/ /* Uncomment if line-wrapping causes problems. */' & @CRLF & _ ' table.print > tbody > tr {page-break-inside: avoid;}' & @CRLF & _ ' table.print > tbody > .metricsRow > td {border-top: none !important;}' & @CRLF & _ '' & @CRLF & _ ' /* THE FOLLOWING CSS IS REQUIRED, but the values may be adjusted. */' & @CRLF & _ ' /* NOTE: All size values that can affect an elements height should use the px unit! */' & @CRLF & _ ' table.fauxRow, table.print {' & @CRLF & _ ' font-size: 10px;' & @CRLF & _ ' line-height: 13px;' & @CRLF & _ ' }' & @CRLF & _ '' & @CRLF & _ ' /* THE FOLLvOWING CSS IS OPTIONAL. */' & @CRLF if $Landscape then $sCSSstyle=$sCSSstyle & ' @page {size: landscape;} /* Delete to print in portrait mode*/' & @CRLF if $Row_Numbers then $sCSSstyle=$sCSSstyle & ' body {counter-reset: t1;} /* Delete to remove row numbers. */' & @CRLF & _ ' .noBreak .t1 > tbody > tr > :first-child:before {counter-increment: none;} /* Delete to remove row numbers. */' & @CRLF & _ ' .t1 > tbody > tr > :first-child:before { /* Delete to remove row numbers. */' & @CRLF & _ ' display: block;' & @CRLF & _ ' text-align: right;' & @CRLF & _ ' counter-increment: t1 1;' & @CRLF & _ ' content: counter(t1);' & @CRLF & _ ' }' & @CRLF $sCSSstyle=$sCSSstyle & ' table.fauxRow, table.print {' & @CRLF & _ ' font-family: Tahoma, Verdana, Georgia; /* Try to use fonts that dont get bigger when printed. */' & @CRLF & _ ' margin: 0 auto 0 auto; /* Delete if you dont want table to be centered. */' & @CRLF & _ ' }' & @CRLF & _ ' table.print {border-spacing: 0;}' & @CRLF & _ ' table.print > * > tr > * {' & @CRLF & _ ' border-right: 1px solid black;' & @CRLF & _ ' border-bottom: 1px solid black;' & @CRLF & _ ' padding: 0 3px 0 3px;' & @CRLF & _ ' }' & @CRLF & _ ' table.print > * > :first-child > * {border-top: 1px solid black;}' & @CRLF & _ ' table.print > thead ~ * > :first-child > *, table.print > tbody ~ * > :first-child > * {border-top: none;} ' & @CRLF & _ ' table.print > * > tr > :first-child {border-left: 1px solid black;}' & @CRLF & _ ' table.print > thead {vertical-align: bottom;}' & @CRLF & _ ' table.print > thead > .borderRow > th {border-bottom: none;}' & @CRLF & _ ' table.print > tbody {vertical-align:middle;}' & @CRLF & _ ' table.print > caption {font-weight: bold;}' & @CRLF & _ '</style>' & @CRLF & _ '' & @CRLF & _ '<script>' & @CRLF & _ '' & @CRLF & _ ' (function() { // THIS FUNCTION IS REQUIRED.' & @CRLF & _ ' if(/Firefox|MSIE |Trident/i.test(navigator.userAgent))' & @CRLF & _ ' var formatForPrint = function(table) {' & @CRLF & _ ' var noBreak = document.createElement("div")' & @CRLF & _ ' , noBreakTable = noBreak.appendChild(document.createElement("div")).appendChild(table.cloneNode())' & @CRLF & _ ' , tableParent = table.parentNode' & @CRLF & _ ' , tableParts = table.children' & @CRLF & _ ' , partCount = tableParts.length' & @CRLF & _ ' , partNum = 0' & @CRLF & _ ' , cell = table.querySelector("tbody > tr > td");' & @CRLF & _ ' noBreak.className = "noBreak";' & @CRLF & _ ' for(; partNum < partCount; partNum++) {' & @CRLF & _ ' if(!/tbody/i.test(tableParts[partNum].tagName))' & @CRLF & _ ' noBreakTable.appendChild(tableParts[partNum].cloneNode(true));' & @CRLF & _ ' }' & @CRLF & _ ' if(cell) {' & @CRLF & _ ' noBreakTable.appendChild(cell.parentNode.parentNode.cloneNode()).appendChild(cell.parentNode.cloneNode(true));' & @CRLF & _ ' if(!table.tHead) {' & @CRLF & _ ' var borderRow = document.createElement("tr");' & @CRLF & _ ' borderRow.appendChild(document.createElement("th")).colSpan="1000";' & @CRLF & _ ' borderRow.className = "borderRow";' & @CRLF & _ ' table.insertBefore(document.createElement("thead"), table.tBodies[0]).appendChild(borderRow);' & @CRLF & _ ' }' & @CRLF & _ ' }' & @CRLF & _ ' tableParent.insertBefore(document.createElement("div"), table).style.paddingTop = ".009px";' & @CRLF & _ ' tableParent.insertBefore(noBreak, table);' & @CRLF & _ ' };' & @CRLF & _ ' else' & @CRLF & _ ' var formatForPrint = function(table) {' & @CRLF & _ ' var tableParent = table.parentNode' & @CRLF & _ ' , cell = table.querySelector("tbody > tr > td");' & @CRLF & _ ' if(cell) {' & @CRLF & _ ' var topFauxRow = document.createElement("table")' & @CRLF & _ ' , fauxRowTable = topFauxRow.insertRow(0).insertCell(0).appendChild(table.cloneNode())' & @CRLF & _ ' , colgroup = fauxRowTable.appendChild(document.createElement("colgroup"))' & @CRLF & _ ' , headerHider = document.createElement("div")' & @CRLF & _ ' , metricsRow = document.createElement("tr")' & @CRLF & _ ' , cells = cell.parentNode.cells' & @CRLF & _ ' , cellNum = cells.length' & @CRLF & _ ' , colCount = 0' & @CRLF & _ ' , tbods = table.tBodies' & @CRLF & _ ' , tbodCount = tbods.length' & @CRLF & _ ' , tbodNum = 0' & @CRLF & _ ' , tbod = tbods[0];' & @CRLF & _ ' for(; cellNum--; colCount += cells[cellNum].colSpan);' & @CRLF & _ ' for(cellNum = colCount; cellNum--; metricsRow.appendChild(document.createElement("td")).style.padding = 0);' & @CRLF & _ ' cells = metricsRow.cells;' & @CRLF & _ ' tbod.insertBefore(metricsRow, tbod.firstChild);' & @CRLF & _ ' for(; ++cellNum < colCount; colgroup.appendChild(document.createElement("col")).style.width = cells[cellNum].offsetWidth + "px");' & @CRLF & _ ' var borderWidth = metricsRow.offsetHeight;' & @CRLF & _ ' metricsRow.className = "metricsRow";' & @CRLF & _ ' borderWidth -= metricsRow.offsetHeight;' & @CRLF & _ ' tbod.removeChild(metricsRow);' & @CRLF & _ ' tableParent.insertBefore(topFauxRow, table).className = "fauxRow";' & @CRLF & _ ' if(table.tHead)' & @CRLF & _ ' fauxRowTable.appendChild(table.tHead);' & @CRLF & _ ' var fauxRow = topFauxRow.cloneNode(true)' & @CRLF & _ ' , fauxRowCell = fauxRow.rows[0].cells[0];' & @CRLF & _ ' fauxRowCell.insertBefore(headerHider, fauxRowCell.firstChild).style.marginBottom = -fauxRowTable.offsetHeight - borderWidth + "px";' & @CRLF & _ ' if(table.caption)' & @CRLF & _ ' fauxRowTable.insertBefore(table.caption, fauxRowTable.firstChild);' & @CRLF & _ ' if(tbod.rows[0])' & @CRLF & _ ' fauxRowTable.appendChild(tbod.cloneNode()).appendChild(tbod.rows[0]);' & @CRLF & _ ' for(; tbodNum < tbodCount; tbodNum++) {' & @CRLF & _ ' tbod = tbods[tbodNum];' & @CRLF & _ ' rows = tbod.rows;' & @CRLF & _ ' for(; rows[0]; tableParent.insertBefore(fauxRow.cloneNode(true), table).rows[0].cells[0].children[1].appendChild(tbod.cloneNode()).appendChild(rows[0]));' & @CRLF & _ ' }' & @CRLF & _ ' tableParent.removeChild(table);' & @CRLF & _ ' }' & @CRLF & _ ' else' & @CRLF & _ ' tableParent.insertBefore(document.createElement("div"), table).appendChild(table).parentNode.className="fauxRow";' & @CRLF & _ ' };' & @CRLF & _ ' var tables = document.body.querySelectorAll("table.print")' & @CRLF & _ ' , tableNum = tables.length;' & @CRLF & _ ' for(; tableNum--; formatForPrint(tables[tableNum]));' & @CRLF & _ ' })();' & @CRLF & _ '</script>' $sFile=_TempFile ( @TempDir , "~", ".html" ) ;~ $sFile= @ScriptDir & "\Export.html" $hFile= FileOpen($sFile, 2 + 8) FileWrite($hFile,$sHTMLTable & $sCSSstyle) FileClose($hFile) If @error Then msgbox(0,"Print Error","Failed to close the file!") EndIf ShellExecute($sFile) WinWaitActive(StringTrimLeft($sFile,StringInStr($sFile,"\","",-1))) send("^p") EndFunc ;==>_table_print
  10. How a lot of string formatted output to a printer? E.g: 1) The first line of Arial font and size 20 and Bold 2) The second line to the fourth line of Tahoma font and size 14 3) Insert two blank lines every 5 row 4) Every 64 rows to add a page break (chr(12) ) and add headers and footers 5) Finally, the formatted string output to a printer(Dot matrix printer) How to do that?The printer supports ESC / P, ESC / P2, ESC / PK, ESC / PK2, Epson Standard Code for Printer. Thank you very much!!!
  11. I have seen many different threads about generating barcodes, displaying them, and printing them. However at this point I am completely torn with which method to use. I am making a software that lets the user scan items, enter in information and save it in a SQLite database. For my purposes, I want to be able to display the barcode with number underneath in a similar way to most other controls eg GuiCtrlCreateBarcode( barcodenumber, x, y, width, height ). I also want to be able to print the barcode and have it be readable by the same scanner - The most successful encoding I've found is code128. Here is what I have found so far: This thread has nice code that saves the output as imagesPrinting is easy and scans properlyDisplaying the image on a pic control makes it easy to set it's x/y/width/height But..The code does not let you directly specify the width / height, so displayed image on GUI is ALWAYS skewed.Getting output images the right size with that code is very difficultI cannot find any examples of drawing barcodes to an image that let you specify width / heightThis example Several threads use Static controlsLook very nice on GUI, easy to get explicit position and size But...I know of no way to turn a bunch of static controls into something printableI didn't find any examples that had numbers at the bottom of the barcodeThe third solution I found was using a barcode fontCan look nice, depending on fontShouldn't be hard to print But..Depends on additional font being installedSome fonts don't scan correctlyHow do you specify a width / height of an area you want the barcode to fill when using a font?I'm really at a loss as to how to move forward. Maybe there's an example I missed that is better suited to what I could find? PErhaps someone has experience writing barcode scanning / generating / printing software and can share the experiences. Can someone bounce a few ideas back and forth with me on the best way to proceed?
  12. I am just starting to use this UDF and I'm not sure if it's my sheer ignorance with this UDF or something that's missing, but I'm getting an error with _PrintSetPrinter(), which will not even bring up the dialog box to select the printer. Here's my code (tested): #include <printMGv2.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Local $hwnd, $hButton, $msg, $hp, $mmssgg $hwnd = GUICreate("Example") $hButton = GUICtrlCreateButton("click me to print", 20, 20) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Print") GUISetState() $hp = _PrintDLLStart($mmssgg) ; open the print dll While 1 WEnd Func Print() Local $selected If $hp = 0 Then ; if we couldn't open the dll MsgBox(0, "", "Error from dllstart = " & $mmssgg & @CRLF) ; tell us Return ; get out EndIf $selected = _PrintSetPrinter($hp) ; set the printer MsgBox(0, "", $selected) _PrintDLLClose($hp) ; close the dll EndFunc ;==>Print Func Quit() Exit EndFunc ;==>Quit
  13. Friends, A script I am working on calls a commandline utility called lpr.exe. It allows sending files to a printer with an IP address. My script needs to work on both 32 and 64 bit systems. on my 64 bit system, the only LPR.exe is a 64 bit app, and if I use a command such as RunWait(@ComSpec & " /K lpr.exe -S " & $IPAddress & " -P strict " & $FileName, @ScriptDir) I get an error in the command window telling me there is no lpr.exe command. If I compile my script in 64 bits, it works fine. But then of course that script wouldn't work on a 32 bit system. I could use kludges, such as installing a "lpr32.exe" copied from a 32 bit system on a 64 bit system, and compile the script in 32 bits, or I could even have a 64 and a 32 bit version of the same script. But then, many of my users have no idea if their system is a 32 or 64 bit one, and I'm trying to keep things simple. Is there a way to use RunWait or something similar in such a way that a 64 bit cmd.exe would be called from a 32-bit compiled script? I kind of doubt that, but someone out there might dream up a way... Thanks
  14. Hi all, I'm in the middle of writing a print queue monitor. I would like to be able to run this on our print server to be able to track who's printing large amounts and reduce the effect on the environment. I've done a fair chunck of it, but I'm finding that it's causing a bit of a load on the CPU. On average the 'spoolsv.exe' process sits at about 15-20% constantly when nothing is happening. I'm wondering if there is a way I can reduce this. I'm using the following code to access the print queue. ; Connect to Print Queue $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") While 1 $AllPrintJobs = $objWMIService.ExecQuery ("SELECT * FROM Win32_PrintJob") ; Run through Print Jobs For $PrintJob In $AllPrintJobs ; Process any new jobs here Next Sleep (50) WEnd I've found that I have to catch the job several times in the queue. If I don't I can miss the total number of pages as the jobs spools. Is there another way of me getting the same information? Does the information go to another location after the print queue?
×
×
  • Create New...