martin Posted October 5, 2007 Author Share Posted October 5, 2007 Great work!Nearly what I was looking for but.... If I have a text file, can your DLL and UDF can be used to change the default printer and print the file?ThanksSeanYou can select the printer to use with _PrintSetPrinter, but it doesn't change it to the default printer.If you want to print a text file then you have to format the printing yourself, that is you need to decide what text goes on each line and the position of each line. I can se that a function like 'Print this text in this rectangular area and return the number of characters fitted' would be useful but I don't intend to do that at the moment.I expect it would be easier to a Word udf. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
SAG Posted October 5, 2007 Share Posted October 5, 2007 Interesting - I hadn't thought to look at that. Thanks for your reply. Link to comment Share on other sites More sharing options...
fhanna Posted October 15, 2007 Share Posted October 15, 2007 This is a simple example of printing using my print UDF which uses a dll. It is not intended to do the sorts of thing you can do with the Word UDF by big daddy, but it allows you to print text in any font, size and colour and to draw straight lines in any colour. Useful for labels, reports and so on. example printout. Edit:10th September 2007 changed the code below to be the code used to create the example printout. expandcollapse popup#include 'printMGv2.au3' Global $hp Local $mmssgg,$marginx,$marginy $hp = _PrintDllStart($mmssgg);this must always be called first if $hp = 0 then consolewrite("Error from dllstart = " & $mmssgg & @CRLF) Exit endif _PrintSetPrinter($hp);choose the printer if you don't want the default printer _PrintPageOrientation($hp,0);landscape _PrintStartPrint($hp) $pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp) $pgwd = _PrintGetpageWidth($hp) - _PrintGetXOffset($hp) $axisx = Round($pgwd * 0.8) $axisy = Round($pght * 0.8) _PrintSetFont($hp,'Arial',18,0,'bold,underline') $Title = "Sales for 2006" $tw = _PrintGetTextWidth($hp,$Title) $th = _PrintGetTextHeight($hp,$title) _PrintText($hp,$title,Int($pgwd/2 - $tw/2),_PrintGetYOffset($hp)) _PrintSetLineWid($hp,2) _PrintSetLineCol($hp,0) _printsetfont($hp,'Times New Roman',12,0,'') $basey = 2*_PrintGetTextHeight($hp,"Jan") $basex = $basey + 200 _PrintLine($hp,$basex,$pght - $basey,$axisx + $basex,$pght - $basey) _PrintLine($hp,$basex,$pght - $basey,$basex,$pght-$basey-$axisy) $xdiv = Int(($axisx - $basey)/12) $ydiv = Int($axisy/10) $months = StringSplit("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sept|Oct|Nov|Dec",'|') For $n = 1 To 12 _PrintText($hp,$months[$n],$basex + $n*$xdiv - Int(_printGetTextWidth($hp,$months[$n])/2),$pght-$basey + 5) _PrintLine($hp,$Basex + $n*$xdiv,$pght - $basey - 10,$Basex + $n*$xdiv,$pght - $basey + 10) Next For $n = 1 To 10 _PrintText($hp,$n,$basex - _PrintGetTextWidth($hp,$n) - 20,$pght-$basey-$n*$ydiv-Int(_printGetTextHeight($hp,'10')/2)) _PrintLIne($hp,$basex - 5,$pght - $basey - $n*$ydiv,$basex + 5,$pght - $basey - $n*$ydiv) Next _PrintText($hp,"£ x 1000,000",$basex - 3 * _PrintGetTextHeight($hp,"£"),$pght - $basey - 100,90) Dim $sales[13] = [0,20,25,20,18,10,17,20,10,80,90,100,100] _PrintSetLineCol($hp,0x0000ff) _PrintSetBrushCol($hp,0x55FF55) For $n = 1 To 12 _PrintRectangle($hp,$Basex + $n*$xdiv -50,$pght - $basey - Int($sales[$n]*$ydiv/10), _ $Basex + $n*$xdiv +50,$pght - $basey - 0.2) Next $label = "I started work" _PrintSetLineCol($hp,0) _PrintLine($hp,Int($pgwd/2),2*$th + 125,$Basex + 8*$xdiv ,$pght - $basey - Int($sales[8]*$ydiv/10)) _Printsetlinecol($hp,0x0000ff) _PrintSetLineWid($hp,10) _PrintSetBrushCol($hp,0xbbccee) _PrintEllipse($hp,Int($pgwd/2) - 200,2*$th,Int($pgwd/2) + 200,2*$th + 250) ;add an image in next line. can be bmp, jpg or ico file ;_PrintImage($hp,"screenshot004.bmp",Int($pgwd/2) - 150,2*$th+260,300,350) _PrintText($hp,$label,Int($pgwd/2 - _PrintGetTextWidth($hp,$label)/2),2*$th + 125 - Int(_printGetTextHeight($hp,$label)/2)) _PrintEndPrint($hp) _PrintNewPage($hp); _printDllClose($hp) Functions available are - _PrintDllStart _PrintDllClose _PrintSetPrinter _PrintGetPageWidth _PrintGetPageHeight _PrintGetHorRes _PrintGetVertRes _PrintStartPrint _PrintSetFont _PrintNewPage _PrintEndPrint _PrintText _PrintGetextWidth _PrintGetTextHeight _PrintLine _PrintGetXOffset _PrintGetYOffset _PrintSetLineCol _PrintSetLIneWid (added in V2.1) _PrintImage - prints jpg, bmp and some ico files _PrintPageOrientation - set portrait or landsacpe + _PrintText - updated so text can be printed at any angle. Also made text have a transparent background so it can be printed over images or lines etc without destroying them. (added in V2.2) _PrintEllipse Filled ellipse or circle _PrintPie for filled pie slice _PrintArc Elliptical or circular arcs _PrintRectangle filled rectangle _PrintSetBrushCol sets the colour used for filling V2.3 13th Aug 2007 PrintRectangle in prinMGV2.au3 corrected. Thanks to Michel Claveau. Orientation in PrintMG.dll now ignores request if printing in progress. Thanks again to Michel Claveau. The link below is for a compressed link. If you download it, extract the link then double click on it and it will get the zip containing the UDF and the dll. A definite thanks for this post. I need to carry 1 step futher. I know I could change the default printer prior to the script but want to leave the default but select the printer from the drop down via the script; ie a _printSelectPrinter type of function where the printer parameter would be supplied and the Print dialog box would not appear. Additional function would be the alter the page range. Any additional info in reference to this would be appreciated. Thanks again. Link to comment Share on other sites More sharing options...
martin Posted October 15, 2007 Author Share Posted October 15, 2007 A definite thanks for this post. I need to carry 1 step futher. I know I could change the default printer prior to the script but want to leave the default but select the printer from the drop down via the script; ie a _printSelectPrinter type of function where the printer parameter would be supplied and the Print dialog box would not appear. Additional function would be the alter the page range.Any additional info in reference to this would be appreciated.Thanks again.Do you mean that you want a function where you can choose a printer from a drop down list, but you do not want to use the _PrintSePrinter function? If so then can you explain what the problem is with the _PrintSetPrinter function that you want to avoid?Altering the page range doesn't make sense to me because the pages you print are set in your script, so you control that and not my dll. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
fhanna Posted October 15, 2007 Share Posted October 15, 2007 Do you mean that you want a function where you can choose a printer from a drop down list, but you do not want to use the _PrintSePrinter function? If so then can you explain what the problem is with the _PrintSetPrinter function that you want to avoid?Altering the page range doesn't make sense to me because the pages you print are set in your script, so you control that and not my dll.Thanks for your fast response. Yes, we would like for the printer selection be made via a parameter. When the Print dialog box appears the default is selected; then you press OK or select another printer. I would like another printer be selected without having to manually do. It would also be nice to not have the dialog box show.We have multiple AutoIt scripts running and utilitizing the default but another application would need the software to select the printer. For the page range to print we supply a override via controlID.Bottomline: The software calls up the Print dialog box via keystrokes, provides an override to print range, if needed then prints via an {ENTER} key. Currently the default is constantly changing depending on the routing of the printout. Due to Windows XP we have found the default does not actually change in the drop down until to exit the program being controlled and reenter. The registry does reflect the proper printer. Under Windows 2000 we did not have this problem.Hope this is a little more clear.Again, thanks for your support. Link to comment Share on other sites More sharing options...
martin Posted October 15, 2007 Author Share Posted October 15, 2007 Thanks for your fast response. Yes, we would like for the printer selection be made via a parameter. When the Print dialog box appears the default is selected; then you press OK or select another printer. I would like another printer be selected without having to manually do. It would also be nice to not have the dialog box show.We have multiple AutoIt scripts running and utilitizing the default but another application would need the software to select the printer. For the page range to print we supply a override via controlID.Bottomline: The software calls up the Print dialog box via keystrokes, provides an override to print range, if needed then prints via an {ENTER} key. Currently the default is constantly changing depending on the routing of the printout. Due to Windows XP we have found the default does not actually change in the drop down until to exit the program being controlled and reenter. The registry does reflect the proper printer. Under Windows 2000 we did not have this problem.Hope this is a little more clear.Again, thanks for your support.OK, I see what you're after, I should have understood from your first post.Yes, I agree a _PrintSelectPrinter would be a good idea. I'll work on a simple version. I'll PM you with an update when I think it works so you can test it. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
fhanna Posted October 24, 2007 Share Posted October 24, 2007 OK, I see what you're after, I should have understood from your first post.Yes, I agree a _PrintSelectPrinter would be a good idea. I'll work on a simple version. I'll PM you with an update when I think it works so you can test it.Martin sent me a module for testing and worked as needed. Hopefully, he will be posting an update. Martin, thank you again. Link to comment Share on other sites More sharing options...
martin Posted October 25, 2007 Author Share Posted October 25, 2007 Martin sent me a module for testing and worked as needed. Hopefully, he will be posting an update. Martin, thank you again.Latest versions are now UDF version 2.4, printmg.dll v2.42 with the new function _PrintSelectPrinter. First post updated.Thanks fhanna for pointing out the need for this and for testing it. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Michel Claveau Posted October 26, 2007 Share Posted October 26, 2007 Latest versions are now UDF version 2.4, printmg.dll v2.42. First post updated.Thanks. Link to comment Share on other sites More sharing options...
ryandavid773 Posted December 6, 2007 Share Posted December 6, 2007 Sorry to dig up a old thread. I've searched but cannot find a answer. I am trying to create a new page, but it constantly fails to do so. This is what I have so far: $pagecount = 0 For $p = 1 To UBound($TopMatches) For $q = 1 To 5 _PrintText($printer, $TopMatches[$p-1][$q-1], Int(($pgwd*$q*2)/11)-320, $StartHeight + (40*$pagecount)) Next $pagecount += 1 If $pagecount = 44 Then $pagecount = 0 _PrintNewPage($printer) $StartHeight = -75 EndIf Next _PrintDllClose($printer) Could someone please point me in the right direction? Thanks a lot! Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted December 6, 2007 Share Posted December 6, 2007 I'm glad you made this now I can die happy Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
martin Posted December 6, 2007 Author Share Posted December 6, 2007 (edited) Sorry to dig up a old thread. I've searched but cannot find a answer. I am trying to create a new page, but it constantly fails to do so. This is what I have so far: $pagecount = 0 For $p = 1 To UBound($TopMatches) For $q = 1 To 5 _PrintText($printer, $TopMatches[$p-1][$q-1], Int(($pgwd*$q*2)/11)-320, $StartHeight + (40*$pagecount)) Next $pagecount += 1 If $pagecount = 44 Then $pagecount = 0 _PrintNewPage($printer) $StartHeight = -75 EndIf Next _PrintDllClose($printer) Could someone please point me in the right direction? Thanks a lot! I haven't got time to investigate this now, but if the NewPage function is a problem then try replacing _PrintNewPage with If _PrintEndPrint($printer) then _PrintStartPrint($printer) which should result in a new page being started. I'll look at the problem at the weekend. Edited December 6, 2007 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted December 6, 2007 Author Share Posted December 6, 2007 I'm glad you made this now I can die happyI'm glad that you have found a use for it, and if it helps to kill off dictators then it's very useful! Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ryandavid773 Posted December 6, 2007 Share Posted December 6, 2007 Thanks martin! I don't mean to complain, but your method works great except for it creates a whole new document. The only reason why this is a problem is because I print mainly to PDF, and it asks for a new file name for each page. It would be awesome to be able to have multiple pages within a single PDF. Thanks a lot! Ryan Link to comment Share on other sites More sharing options...
martin Posted December 6, 2007 Author Share Posted December 6, 2007 Thanks martin!I don't mean to complain, but your method works great except for it creates a whole new document. The only reason why this is a problem is because I print mainly to PDF, and it asks for a new file name for each page. It would be awesome to be able to have multiple pages within a single PDF.Thanks a lot!RyanYes, I didn't think of that.I've uploaded a new version (V2.44) which now has the new page working correctly, see the first post. Tested with a pdf creator as well as a printer.For some reason I had commented out the most of the code in the _PrintNewPage function which explains why it didn't do anything, probably done when I was changing the way the page count worked in the previous version change. Who knows, who cares?Anyway, apologies for the error. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ryandavid773 Posted December 6, 2007 Share Posted December 6, 2007 Yes, I didn't think of that.I've uploaded a new version (V2.44) which now has the new page working correctly, see the first post. Tested with a pdf creator as well as a printer.For some reason I had commented out the most of the code in the _PrintNewPage function which explains why it didn't do anything, probably done when I was changing the way the page count worked in the previous version change. Who knows, who cares?Anyway, apologies for the errorAwesome, thank you so much martin! I owe you one! Link to comment Share on other sites More sharing options...
sherkas Posted January 22, 2008 Share Posted January 22, 2008 thank you for this udf! Link to comment Share on other sites More sharing options...
martin Posted January 23, 2008 Author Share Posted January 23, 2008 thank you for this udf!A pleasure, hope it's useful to you. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ChrisL Posted April 2, 2008 Share Posted April 2, 2008 (edited) Martin I've been playing around with this dll and I think I have found a small issue If I use $p = _PrintSetPrinter($hp) and I click cancel there seems to be no way for me to know that cancel was clicked. @error is 0 and $p = 1, I was expecting $p to be -1 Any help you can give greatly appreciated Edit: Forgot to say this is a great peice of work Edited April 2, 2008 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
martin Posted April 2, 2008 Author Share Posted April 2, 2008 (edited) MartinI've been playing around with this dll and I think I have found a small issueIf I use $p = _PrintSetPrinter($hp) and I click cancel there seems to be no way for me to know that cancel was clicked.@error is 0 and $p = 1, I was expecting $p to be -1Yes, not very good is it? I haven't got much time now but I've made a quick change to the dll so that it returns 1 on success and 0 on failure. I think clicking Cancel will give failure but I haven't tried it out! You only need the new dll which you can get here. (Link now removed)Could you try it please and let me know if it does what you want? If it works ok then I will update the links in the first post. If it doesn't do the job it will be a few days before I have another attempt to fix it.Edit: Forgot to say this is a great peice of work Thanks.EDIT: Now tested and it does return 0 if Cancel pressed, otherwise it returns 1.A return of 1 does not guarantee that all is well however. If you select a printer which is no longer available the return is still 1 and the printout will be on the default printer. To deal with this, and to give a method to check what printer is being used, I have added a new function '_PrinterGetPrinter' which returns the printer name. But this doesn't do quite what I wanted. EDIT 2: The new _PrintGetPrinter function does give the current printer name but if you select a non existent printer then it will give that name even though the default printer actually gets used. I don't have a solution to this yet.First post updated with new links to latest version. Edited April 3, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now