New topic: saving printer setup string to file- works on mac not on win
<http://forums.realsoftware.com/viewtopic.php?t=1332> Page 1 of 2 [ 19 posts ] Go to page 1, 2 Next Previous topic | Next topic Author Message bernnhugh Post subject: saving printer setup string to file- works on mac not on winPosted: Wed Dec 07, 2005 7:09 pm Joined: Thu Nov 17, 2005 1:50 pm Posts: 33 I'm trying to store a printer setup string to a file so I don't have to set it up every time I reopen my application. This works great on Mac: dim settings as string Dim f As FolderItem Dim t as TextOutputStream If ps.PageSetupDialog Then settings=ps.SetupString f = Volume(0).Child("SS3000").Child("LabelSetup.txt") t = f.CreateTextFile t.Write settings t.close End If I then read it on startup: f= Volume(0).Child("SS3000").Child("LabelSetup.txt") If f.exists then t=f.OpenAsTextFile s=t.ReadAll t.Close ps.SetupString = s end if It works only partially on Windows. It does write the setup string to the file. When I look at the file it contains some binary-looking pieces, but for the most part is text. If I go to reset the printersetup with ps.pagesetupdialog the information is there but when I try to print nothing happens. No error but no print either. The contents of the file are as follows: DoNotAlterThis=SetupString.1 ActualHorizontalResolution=72 ActualVerticalResolution=72 MaxHorizontalResolution=72 MaxVerticalResolution=72 MarginLeft=523 MarginRight=345 MarginTop=254 MarginBottom=254 MinMarginLeft=523 MinMarginRight=345 MinMarginTop=91 MinMarginBottom=254 PageSetupFlags=6 DevModeStructureSizePS=156 DevModeStructurePS=label Top bernnhugh Post subject: Posted: Wed Dec 07, 2005 7:11 pm Joined: Thu Nov 17, 2005 1:50 pm Posts: 33 Looks like that didn't post so well. The contents of the file after what you see had some binary-looking characters. The forum didn't include them in the post and cut the rest that followed after that: 30323 Shipping Top bernnhugh Post subject: Posted: Wed Dec 07, 2005 7:12 pm Joined: Thu Nov 17, 2005 1:50 pm Posts: 33 It cut me off again. Here is the rest : DriverName=winspool DeviceName=label OutputName=USB001 Thanks, bernn Top ibad Post subject: Posted: Thu Mar 16, 2006 8:45 am Joined: Tue Mar 07, 2006 7:03 am Posts: 24 Ever get this resolved. I have exactly the same problem. Top Dave Post subject: I need that info tooPosted: Thu Mar 16, 2006 9:36 am Joined: Fri Sep 30, 2005 8:36 am Posts: 276 Location: lost... I just posted a similar question. I know you have to use EncodeBase64 and DecodeBase64 to save and load the string but I still never got it working. If you got that figured out please post it. _________________ Dave Arrrrrrghh! Top Aaron Ballman Post subject: Posted: Thu Mar 16, 2006 10:22 am Joined: Wed Sep 28, 2005 8:39 am Posts: 9341 Location: St Augusta, MN You can't use a text format to save binary data. Try a BinaryStream instead. And note that you'll run into a bunch of problems if you try to pass that file around to other computers that don't have the *exact* same setup. Top Dave Post subject: Posted: Thu Mar 16, 2006 10:38 am Joined: Fri Sep 30, 2005 8:36 am Posts: 276 Location: lost... Aaron, I wasn't planning to pass the file around. What I was trying to do was have the file create itself on the end users computer after a first print happens and they set their margins. Then to avoid having them set the margins everytime to avoid default settings (if they aren't correct). I will try a BinaryStream to see the difference. [/code] _________________ Dave Arrrrrrghh! Top ibad Post subject: Posted: Thu Mar 16, 2006 10:39 am Joined: Tue Mar 07, 2006 7:03 am Posts: 24 I'm using a binarystream to save the pagesettings. Also this file isn't going onto any other computer, its just a way of my application remembering what the page settings were so a user doesn't have to keep changing them when printing. Lee Top Dave Post subject: Posted: Thu Mar 16, 2006 10:41 am Joined: Fri Sep 30, 2005 8:36 am Posts: 276 Location: lost... Lee, Exactly what I am trying to do Care to post an example so I get it right? _________________ Dave Arrrrrrghh! Last edited by Dave on Thu Mar 16, 2006 10:43 am, edited 1 time in total. Top Aaron Ballman Post subject: Posted: Thu Mar 16, 2006 10:43 am Joined: Wed Sep 28, 2005 8:39 am Posts: 9341 Location: St Augusta, MN If the user's machine is still in the same state (no printers added or removed), then the setup string should work fine (only when saved as binary data and not mucked with in any way). If you find that it's not behaving that way for you, then double-check your code. If it's still causing issues, it may be a bug that you should report. Top Dave Post subject: Posted: Thu Mar 16, 2006 10:45 am Joined: Fri Sep 30, 2005 8:36 am Posts: 276 Location: lost... Aaron, Thats the plan. If the user changes printers etc then all they would have to do is delete the .Dat file and it would create the new one on the next setup. _________________ Dave Arrrrrrghh! Top bernnhugh Post subject: Help with the binary streamPosted: Thu Mar 16, 2006 7:47 pm Joined: Thu Nov 17, 2005 1:50 pm Posts: 33 Aaron, I tried the base64 encoding, but the result is pretty much the same as without the encoding. I need a little help with the binary stream stuff. I'm reading the help files, but I dont' have any experience with binary and I'm just not getting it. What's up with bytes being in pairs? A little hint, please? Thanks, Bernn Top Aaron Ballman Post subject: Posted: Thu Mar 16, 2006 7:55 pm Joined: Wed Sep 28, 2005 8:39 am Posts: 9341 Location: St Augusta, MN Save the printer setup string to its own file, like this: dim bs as BinaryStream = f.CreateBinaryFile( "" ) bs.Write( thePrinterSetupString ) bs.Close And read it back in like this: dim bs as BinaryStream = f.OpenAsBinaryStream( false ) thePrinterSetupString = bs.Read( bs.Length ) bs.Close HTH! Top bernnhugh Post subject: Close, but no CigarPosted: Fri Mar 17, 2006 5:18 pm Joined: Thu Nov 17, 2005 1:50 pm Posts: 33 Aaron, I tried your binary code and got pretty much the same result. The settings appear to get stored, but when you try to print, no output. I had to modify your read code a little: f = Volume(0).Child("SS3000").Child("LabelSetup.dat") If f.exists then bs = f.OpenAsBinaryFile ( false ) ps.SetupString = bs.Read( bs.Length ) bs.Close end if I received a "method doesn't exit" error on f.OpenAsBinaryStream . I'm on 2005R4, maybe a new method? Anything look wrong to you? Thanks, Bernn Top Aaron Ballman Post subject: Posted: Fri Mar 17, 2006 5:27 pm Joined: Wed Sep 28, 2005 8:39 am Posts: 9341 Location: St Augusta, MN Naw, it's just code typed from (poor) memory. It's OpenAsBinaryFile, not OpenAsBinaryStream, which you then corrected. I'm not certain why you're not getting output though...sorry! Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 2 [ 19 posts ] Go to page 1, 2 Next -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
