|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Center Text using printer objectI am stomped on this one... I am trying to center text using printer object.
I am printing to a receipt printer. I have tried many things; sometimes it centers the text sometimes it "gets confused" and print just about at any point. Is there a built in text centering command using printer object? Anyone have an ideas? Thanks in advance "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... Nothing built-in. Why didn't you post your code so we could determine what you're doing wrong?>I am stomped on this one... I am trying to center text using printer object. I am printing to a receipt printer. I have tried many >things; sometimes it centers the text sometimes it "gets confused" and print just about at any point. Is there a built in text >centering command using printer object? Anyone have an ideas? > -- Mike First of all, thanks for responding. I used the code below to tab to print
start point... My reasoning was based on fact that receipt printers take 40 characters per line (I think that's essentially true if using fixed width fonts). So what I am thinking to do, or so I thought is feasible to do, is use the text len of the text to be printed to determine where to start printing. Say for example... I have a text of 20 characters (len) to be printed in an area that can take 40 characters maximum (total print area)... the puzzle becomes how to calculate so the printing becomes centered... However I reckon this is somewhat cumbersome and very unreliable... So I am wondering if anyone has better ideas... Function CalcTab(dLen) 'Receipt print takes 40 digits 'Establish print start point so text becomes centered CalcTab = 40 - dLen / 2 End Function Usage Sub Print Dim ToPrint Dim iStart ToPrint = "My house is brown" iStart = CalcTab(len(ToPrint)) Printer.Print Tab(istart); ToPrint Printer.EndDoc End Sub Show quoteHide quote "MikeD" <nob***@nowhere.edu> wrote in message news:uRNZmmpkJHA.4696@TK2MSFTNGP02.phx.gbl... > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message > news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >>I am stomped on this one... I am trying to center text using printer >>object. I am printing to a receipt printer. I have tried many things; >>sometimes it centers the text sometimes it "gets confused" and print just >>about at any point. Is there a built in text centering command using >>printer object? Anyone have an ideas? >> > > Nothing built-in. Why didn't you post your code so we could determine > what you're doing wrong? > > -- > Mike > > Don't use Tab(), instead place the printer pointer at the position where
the text would be centered. 1. Assume a paper width of 8.5 inches 2. 1 inch = 1440 twips 3. Center of paper is 4.25 inches = 6120 twips 4. Width of text to center is Printer.TextWidth(strTitle) 5. Half way point of text is Printer.TextWidth(strTitle) / 2 6. Position to start printing is 6120 - Printer.TextWidth(strTitle) / 2 7. Set Printer.CurrentY accordingly, set Printer.CurrentX to result of (6) 8. Print text. Look at the help of TextWidth for more relevant notes. For simplicity, I used a fixed paper width of 8.5 inches, a better way is to programmatically get the width. You can use CurrentX and CurrentY properties of the Printer object to print anywhere on the paper within allowed boundaries. Have a look at the help for the Printer object and at all its properties/methods so you can see what is available.HTH, Saga -- Show quoteHide quote"jpBless" <jp3blessNoSpam@hotmail.com> wrote in message news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > First of all, thanks for responding. I used the code below to tab to print start point... My > reasoning was based on fact that receipt printers take 40 characters per line (I think that's > essentially true if using fixed width fonts). So what I am thinking to do, or so I thought is > feasible to do, is use the text len of the text to be printed to determine where to start > printing. Say for example... I have a text of 20 characters (len) to be printed in an area that > can take 40 characters maximum (total print area)... the puzzle becomes how to calculate so the > printing becomes centered... > > However I reckon this is somewhat cumbersome and very unreliable... So I am wondering if anyone > has better ideas... > > Function CalcTab(dLen) > 'Receipt print takes 40 digits > 'Establish print start point so text becomes centered > CalcTab = 40 - dLen / 2 > End Function > > Usage > Sub Print > Dim ToPrint > Dim iStart > > ToPrint = "My house is brown" > iStart = CalcTab(len(ToPrint)) > Printer.Print Tab(istart); ToPrint > Printer.EndDoc > End Sub > > > > > "MikeD" <nob***@nowhere.edu> wrote in message news:uRNZmmpkJHA.4696@TK2MSFTNGP02.phx.gbl... >> >> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message >> news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >>>I am stomped on this one... I am trying to center text using printer object. I am printing to a >>>receipt printer. I have tried many things; sometimes it centers the text sometimes it "gets >>>confused" and print just about at any point. Is there a built in text centering command using >>>printer object? Anyone have an ideas? >>> >> >> Nothing built-in. Why didn't you post your code so we could determine what you're doing wrong? >> >> -- >> Mike >> >> > > I can't thank you enough... I am studying the code
much thanks Show quoteHide quote "Saga" <antiSpam@somewhere.com> wrote in message news:ev5Ye3qkJHA.3760@TK2MSFTNGP03.phx.gbl... > Don't use Tab(), instead place the printer pointer at the position where > the text would be centered. > > 1. Assume a paper width of 8.5 inches > 2. 1 inch = 1440 twips > 3. Center of paper is 4.25 inches = 6120 twips > 4. Width of text to center is Printer.TextWidth(strTitle) > 5. Half way point of text is Printer.TextWidth(strTitle) / 2 > 6. Position to start printing is 6120 - Printer.TextWidth(strTitle) / 2 > 7. Set Printer.CurrentY accordingly, set Printer.CurrentX to result of (6) > 8. Print text. > > Look at the help of TextWidth for more relevant notes. > > For simplicity, I used a fixed paper width of 8.5 inches, a better way is > to programmatically get the width. > > You can use CurrentX and CurrentY properties of the Printer object to > print anywhere on the paper within allowed boundaries. Have a look at > the help for the Printer object and at all its properties/methods so you > can see what is available.HTH, Saga > -- > > > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message > news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... >> First of all, thanks for responding. I used the code below to tab to >> print start point... My reasoning was based on fact that receipt printers >> take 40 characters per line (I think that's essentially true if using >> fixed width fonts). So what I am thinking to do, or so I thought is >> feasible to do, is use the text len of the text to be printed to >> determine where to start printing. Say for example... I have a text of 20 >> characters (len) to be printed in an area that can take 40 characters >> maximum (total print area)... the puzzle becomes how to calculate so the >> printing becomes centered... >> >> However I reckon this is somewhat cumbersome and very unreliable... So I >> am wondering if anyone has better ideas... >> >> Function CalcTab(dLen) >> 'Receipt print takes 40 digits >> 'Establish print start point so text becomes centered >> CalcTab = 40 - dLen / 2 >> End Function >> >> Usage >> Sub Print >> Dim ToPrint >> Dim iStart >> >> ToPrint = "My house is brown" >> iStart = CalcTab(len(ToPrint)) >> Printer.Print Tab(istart); ToPrint >> Printer.EndDoc >> End Sub >> >> >> >> >> "MikeD" <nob***@nowhere.edu> wrote in message >> news:uRNZmmpkJHA.4696@TK2MSFTNGP02.phx.gbl... >>> >>> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message >>> news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >>>>I am stomped on this one... I am trying to center text using printer >>>>object. I am printing to a receipt printer. I have tried many things; >>>>sometimes it centers the text sometimes it "gets confused" and print >>>>just about at any point. Is there a built in text centering command >>>>using printer object? Anyone have an ideas? >>>> >>> >>> Nothing built-in. Why didn't you post your code so we could determine >>> what you're doing wrong? >>> >>> -- >>> Mike >>> >>> >> >> > >
Show quote
Hide quote
On Feb 19, 11:19 am, "Saga" <antiS***@somewhere.com> wrote: You cannot assume the width of the paper, different users of the> Don't use Tab(), instead place the printer pointer at the position where > the text would be centered. > > 1. Assume a paper width of 8.5 inches > 2. 1 inch = 1440 twips > 3. Center of paper is 4.25 inches = 6120 twips > 4. Width of text to center is Printer.TextWidth(strTitle) > 5. Half way point of text is Printer.TextWidth(strTitle) / 2 > 6. Position to start printing is 6120 - Printer.TextWidth(strTitle) / 2 > 7. Set Printer.CurrentY accordingly, set Printer.CurrentX to result of (6) > 8. Print text. > > Look at the help of TextWidth for more relevant notes. > > For simplicity, I used a fixed paper width of 8.5 inches, a better way is > to programmatically get the width. > > You can use CurrentX and CurrentY properties of the Printer object to > print anywhere on the paper within allowed boundaries. Have a look at > the help for the Printer object and at all its properties/methods so you > can see what is available.HTH, Saga > -- > > "jpBless" <jp3blessNoS***@hotmail.com> wrote in message > > news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > > > > > First of all, thanks for responding. I used the code below to tab to print start point... My > > reasoning was based on fact that receipt printers take 40 characters per line (I think that's > > essentially true if using fixed width fonts). So what I am thinking to do, or so I thought is > > feasible to do, is use the text len of the text to be printed to determine where to start > > printing. Say for example... I have a text of 20 characters (len) to be printed in an area that > > can take 40 characters maximum (total print area)... the puzzle becomes how to calculate so the > > printing becomes centered... > > > However I reckon this is somewhat cumbersome and very unreliable... So I am wondering if anyone > > has better ideas... > > > Function CalcTab(dLen) > > 'Receipt print takes 40 digits > > 'Establish print start point so text becomes centered > > CalcTab = 40 - dLen / 2 > > End Function > > > Usage > > Sub Print > > Dim ToPrint > > Dim iStart > > > ToPrint = "My house is brown" > > iStart = CalcTab(len(ToPrint)) > > Printer.Print Tab(istart); ToPrint > > Printer.EndDoc > > End Sub > > > "MikeD" <nob***@nowhere.edu> wrote in messagenews:uRNZmmpkJHA.4***@TK2MSFTNGP02.phx.gbl... > > >> "jpBless" <jp3blessNoS***@hotmail.com> wrote in message > >>news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... > >>>I am stomped on this one... I am trying to center text using printer object. I am printing to a > >>>receipt printer. I have tried many things; sometimes it centers the text sometimes it "gets > >>>confused" and print just about at any point. Is there a built in text centering command using > >>>printer object? Anyone have an ideas? > > >> Nothing built-in. Why didn't you post your code so we could determine what you're doing wrong? > > >> -- > >> Mike- Hide quoted text - > > - Show quoted text - program can have different printer with different paper width. Pay attention to the original post the guy is talking about a RECEIPT PRINTER, there are many different standards with different printing widths. You MUST obtain the width from the printer object ! Support, www.AlexandriaComputers.com The assumption was for effect of the quick and dirty work through
that I posted. This is why I mentioned to the OP to get the size programmatically. I should have been more stern than just using the phrase "better way", because as you said getting the paper width from the Printer object is a requirement. By the OP's response, it looks like this was understood. Regards, Saga. -- Show quoteHide quote"viglen" <AlexandriaSupportNON@SPAMMEgmail.com> wrote in message You cannot assume the width of the paper, different users of thenews:6225734a-7844-42ef-9380-cf8033daadc2@f18g2000vbf.googlegroups.com... On Feb 19, 11:19 am, "Saga" <antiS***@somewhere.com> wrote: > Don't use Tab(), instead place the printer pointer at the position where > the text would be centered. > > 1. Assume a paper width of 8.5 inches > 2. 1 inch = 1440 twips > 3. Center of paper is 4.25 inches = 6120 twips > 4. Width of text to center is Printer.TextWidth(strTitle) > 5. Half way point of text is Printer.TextWidth(strTitle) / 2 > 6. Position to start printing is 6120 - Printer.TextWidth(strTitle) / 2 > 7. Set Printer.CurrentY accordingly, set Printer.CurrentX to result of (6) > 8. Print text. > > Look at the help of TextWidth for more relevant notes. > > For simplicity, I used a fixed paper width of 8.5 inches, a better way is > to programmatically get the width. > > You can use CurrentX and CurrentY properties of the Printer object to > print anywhere on the paper within allowed boundaries. Have a look at > the help for the Printer object and at all its properties/methods so you > can see what is available.HTH, Saga > -- > > "jpBless" <jp3blessNoS***@hotmail.com> wrote in message > > news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > > > > > First of all, thanks for responding. I used the code below to tab to print start point... My > > reasoning was based on fact that receipt printers take 40 characters per line (I think that's > > essentially true if using fixed width fonts). So what I am thinking to do, or so I thought is > > feasible to do, is use the text len of the text to be printed to determine where to start > > printing. Say for example... I have a text of 20 characters (len) to be printed in an area that > > can take 40 characters maximum (total print area)... the puzzle becomes how to calculate so the > > printing becomes centered... > > > However I reckon this is somewhat cumbersome and very unreliable... So I am wondering if anyone > > has better ideas... > > > Function CalcTab(dLen) > > 'Receipt print takes 40 digits > > 'Establish print start point so text becomes centered > > CalcTab = 40 - dLen / 2 > > End Function > > > Usage > > Sub Print > > Dim ToPrint > > Dim iStart > > > ToPrint = "My house is brown" > > iStart = CalcTab(len(ToPrint)) > > Printer.Print Tab(istart); ToPrint > > Printer.EndDoc > > End Sub > > > "MikeD" <nob***@nowhere.edu> wrote in messagenews:uRNZmmpkJHA.4***@TK2MSFTNGP02.phx.gbl... > > >> "jpBless" <jp3blessNoS***@hotmail.com> wrote in message > >>news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... > >>>I am stomped on this one... I am trying to center text using printer object. I am printing to a > >>>receipt printer. I have tried many things; sometimes it centers the text sometimes it "gets > >>>confused" and print just about at any point. Is there a built in text centering command using > >>>printer object? Anyone have an ideas? > > >> Nothing built-in. Why didn't you post your code so we could determine what you're doing wrong? > > >> -- > >> Mike- Hide quoted text - > > - Show quoted text - program can have different printer with different paper width. Pay attention to the original post the guy is talking about a RECEIPT PRINTER, there are many different standards with different printing widths. You MUST obtain the width from the printer object ! Support, www.AlexandriaComputers.com FYI:
Just because a printer prints 40 chars on a line does not mean it hard codes a line ending char at char position 41. If you send it 60 chars does it wrap 20 on the next printable line? That will screw up your tabbing. If so, you need find the line length before the hard return or control the line length you construct WITH your hard return. John Show quoteHide quote "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > First of all, thanks for responding. I used the code below to tab to print > start point... My reasoning was based on fact that receipt printers take 40 > characters per line (I think that's essentially true if using fixed width > fonts). So what I am thinking to do, or so I thought is feasible to do, is > use the text len of the text to be printed to determine where to start > printing. Say for example... I have a text of 20 characters (len) to be > printed in an area that can take 40 characters maximum (total print area)... > the puzzle becomes how to calculate so the printing becomes centered... > > However I reckon this is somewhat cumbersome and very unreliable... So I am > wondering if anyone has better ideas... > > Function CalcTab(dLen) > 'Receipt print takes 40 digits > 'Establish print start point so text becomes centered > CalcTab = 40 - dLen / 2 > End Function > > Usage > Sub Print > Dim ToPrint > Dim iStart > > ToPrint = "My house is brown" > iStart = CalcTab(len(ToPrint)) > Printer.Print Tab(istart); ToPrint > Printer.EndDoc > End Sub > > > > > "MikeD" <nob***@nowhere.edu> wrote in message > news:uRNZmmpkJHA.4696@TK2MSFTNGP02.phx.gbl... >> >> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message >> news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >>>I am stomped on this one... I am trying to center text using printer >>>object. I am printing to a receipt printer. I have tried many things; >>>sometimes it centers the text sometimes it "gets confused" and print just >>>about at any point. Is there a built in text centering command using >>>printer object? Anyone have an ideas? >>> >> >> Nothing built-in. Why didn't you post your code so we could determine >> what you're doing wrong? >> >> -- >> Mike >> >> > > IF you decide to print as you do now, there is missing parens in:
CalcTab = (40 - dLen) / 2 /Henning Show quoteHide quote "jpBless" <jp3blessNoSpam@hotmail.com> skrev i meddelandet news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > First of all, thanks for responding. I used the code below to tab to print > start point... My reasoning was based on fact that receipt printers take > 40 characters per line (I think that's essentially true if using fixed > width fonts). So what I am thinking to do, or so I thought is feasible to > do, is use the text len of the text to be printed to determine where to > start printing. Say for example... I have a text of 20 characters (len) to > be printed in an area that can take 40 characters maximum (total print > area)... the puzzle becomes how to calculate so the printing becomes > centered... > > However I reckon this is somewhat cumbersome and very unreliable... So I > am wondering if anyone has better ideas... > > Function CalcTab(dLen) > 'Receipt print takes 40 digits > 'Establish print start point so text becomes centered > CalcTab = 40 - dLen / 2 > End Function > > Usage > Sub Print > Dim ToPrint > Dim iStart > > ToPrint = "My house is brown" > iStart = CalcTab(len(ToPrint)) > Printer.Print Tab(istart); ToPrint > Printer.EndDoc > End Sub > > > > > "MikeD" <nob***@nowhere.edu> wrote in message > news:uRNZmmpkJHA.4696@TK2MSFTNGP02.phx.gbl... >> >> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message >> news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >>>I am stomped on this one... I am trying to center text using printer >>>object. I am printing to a receipt printer. I have tried many things; >>>sometimes it centers the text sometimes it "gets confused" and print just >>>about at any point. Is there a built in text centering command using >>>printer object? Anyone have an ideas? >>> >> >> Nothing built-in. Why didn't you post your code so we could determine >> what you're doing wrong? >> >> -- >> Mike >> >> > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message s1 = "Some Text"news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > the puzzle becomes how to calculate so the > printing becomes centered... Printer.CurrentX = (Printer.ScaleWidth _ - Printer.TextWidth(s1)) / 2 Printer.Print s1 Note that you should set your font and font size *before* the above code is executed. Mike First of all, big thanks everyone who helped... Saga, Mike Williams, MikeD,
Viglen, Jaff, Hanning... Mikes Code worked great... as well Saga's. Ok I am seeming to be Oliver Twist... but I am wondering if this could be adapted to print centered logo (image). Below is the code I am using to print Logo Dim Photo As StdPicture, MaxWidth, MaxHeight, picHeight, picWidth, sFactor Set Photo = LoadPicture(modGeneral.sLogo) picHeight = Photo.Height picWidth = Photo.Width ' MaxHeight = 30500 '2 inch ' MaxWidth = 2540 '1.50 inch MaxHeight = 40500 '2 inch MaxWidth = 3540 '1.50 inch If picHeight > picWidth Then 'if height is more than width 'get Scale factor based on height sFactor = MaxHeight / picHeight Else 'if height is less than width 'get Scale factor based on height sFactor = MaxWidth / picWidth End If Printer.PaintPicture Photo, 700, 0, picWidth * sFactor, _ picHeight * sFactor Printer.endoc Is there a way to make the printer printer centered logo of specified height and width... Again one problem i notice is after printing logo the printer does seem to print the next line over the log. Please help and thanks in adavance Show quoteHide quote "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message news:%23c9DTmtkJHA.1252@TK2MSFTNGP03.phx.gbl... > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message > news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... > >> the puzzle becomes how to calculate so the >> printing becomes centered... > > s1 = "Some Text" > Printer.CurrentX = (Printer.ScaleWidth _ > - Printer.TextWidth(s1)) / 2 > Printer.Print s1 > > Note that you should set your font and font size *before* the above code > is executed. > > Mike > > If you look at the PaintPicture's help you'll notice that Width1 and Height1
can be used to size the image. You can make it as small as you need to. Take care to keep the proportion when making the image smaller so it does not look squeezed or squashed. > Printer.PaintPicture Photo, 700, 0, picWidth * sFactor, _ I see that you are already doing this. Is this approach not working? If it> picHeight * sFactor is not perhaps the calculation of sFactor is the problem. Have you checked to confirm that picHeight and picWidth are getting the right values? And that these values are in the right scale (twips)? > MaxHeight = 40500 '2 inch What scale are you using? Asked another way, if 1.5" is 3,540, isn't 40,500> MaxWidth = 3540 '1.50 inch a bit high for 2"? Keep in mind that unless you specify otherwise, twips will be used for the Width1 an Height1 parameters of the PaintPicture method. Usually, the approach I take is getting a percentage of the image, so if I want to reduce the image proportionally by 40% I do this: > Printer.PaintPicture Photo, 700, 0, picWidth * .4, _ Saga> picHeight * .4 -- Show quoteHide quote"jpBless" <jp3blessNoSpam@hotmail.com> wrote in message news:u5Am7z2kJHA.5836@TK2MSFTNGP02.phx.gbl... > First of all, big thanks everyone who helped... Saga, Mike Williams, MikeD, Viglen, Jaff, > Hanning... > > Mikes Code worked great... as well Saga's. > Ok I am seeming to be Oliver Twist... but I am wondering if this could be adapted to print > centered logo (image). Below is the code I am using to print Logo > > Dim Photo As StdPicture, MaxWidth, MaxHeight, picHeight, picWidth, sFactor > Set Photo = LoadPicture(modGeneral.sLogo) > picHeight = Photo.Height > picWidth = Photo.Width > ' MaxHeight = 30500 '2 inch > ' MaxWidth = 2540 '1.50 inch > MaxHeight = 40500 '2 inch > MaxWidth = 3540 '1.50 inch > If picHeight > picWidth Then > 'if height is more than width > 'get Scale factor based on height > sFactor = MaxHeight / picHeight > Else > 'if height is less than width > 'get Scale factor based on height > sFactor = MaxWidth / picWidth > End If > > Printer.PaintPicture Photo, 700, 0, picWidth * sFactor, _ > picHeight * sFactor > Printer.endoc > > Is there a way to make the printer printer centered logo of specified height and width... > > Again one problem i notice is after printing logo the printer does seem to print the next line > over the log. Please help and thanks in adavance > > > > "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message > news:%23c9DTmtkJHA.1252@TK2MSFTNGP03.phx.gbl... >> >> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message >> news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... >> >>> the puzzle becomes how to calculate so the >>> printing becomes centered... >> >> s1 = "Some Text" >> Printer.CurrentX = (Printer.ScaleWidth _ >> - Printer.TextWidth(s1)) / 2 >> Printer.Print s1 >> >> Note that you should set your font and font size *before* the above code is executed. >> >> Mike >> >> > > Useful as usual... thank you
Show quoteHide quote "Saga" <antiSpam@somewhere.com> wrote in message news:esBkMU3kJHA.4696@TK2MSFTNGP02.phx.gbl... > If you look at the PaintPicture's help you'll notice that Width1 and > Height1 > can be used to size the image. You can make it as small as you need to. > > Take care to keep the proportion when making the image smaller so it > does not look squeezed or squashed. > >> Printer.PaintPicture Photo, 700, 0, picWidth * sFactor, _ >> picHeight * sFactor > > I see that you are already doing this. Is this approach not working? If it > is not perhaps the calculation of sFactor is the problem. Have you checked > to confirm that picHeight and picWidth are getting the right values? And > that these values are in the right scale (twips)? > >> MaxHeight = 40500 '2 inch >> MaxWidth = 3540 '1.50 inch > > What scale are you using? Asked another way, if 1.5" is 3,540, isn't > 40,500 > a bit high for 2"? Keep in mind that unless you specify otherwise, twips > will > be used for the Width1 an Height1 parameters of the PaintPicture method. > > Usually, the approach I take is getting a percentage of the image, so if I > want > to reduce the image proportionally by 40% I do this: > >> Printer.PaintPicture Photo, 700, 0, picWidth * .4, _ >> picHeight * .4 > > Saga > -- > > > > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message > news:u5Am7z2kJHA.5836@TK2MSFTNGP02.phx.gbl... >> First of all, big thanks everyone who helped... Saga, Mike Williams, >> MikeD, Viglen, Jaff, Hanning... >> >> Mikes Code worked great... as well Saga's. >> Ok I am seeming to be Oliver Twist... but I am wondering if this could be >> adapted to print centered logo (image). Below is the code I am using to >> print Logo >> >> Dim Photo As StdPicture, MaxWidth, MaxHeight, picHeight, picWidth, >> sFactor >> Set Photo = LoadPicture(modGeneral.sLogo) >> picHeight = Photo.Height >> picWidth = Photo.Width >> ' MaxHeight = 30500 '2 inch >> ' MaxWidth = 2540 '1.50 inch >> MaxHeight = 40500 '2 inch >> MaxWidth = 3540 '1.50 inch >> If picHeight > picWidth Then >> 'if height is more than width >> 'get Scale factor based on height >> sFactor = MaxHeight / picHeight >> Else >> 'if height is less than width >> 'get Scale factor based on height >> sFactor = MaxWidth / picWidth >> End If >> >> Printer.PaintPicture Photo, 700, 0, picWidth * sFactor, _ >> picHeight * sFactor >> Printer.endoc >> >> Is there a way to make the printer printer centered logo of specified >> height and width... >> >> Again one problem i notice is after printing logo the printer does seem >> to print the next line over the log. Please help and thanks in adavance >> >> >> >> "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message >> news:%23c9DTmtkJHA.1252@TK2MSFTNGP03.phx.gbl... >>> >>> "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message >>> news:OUWxAVqkJHA.4696@TK2MSFTNGP02.phx.gbl... >>> >>>> the puzzle becomes how to calculate so the >>>> printing becomes centered... >>> >>> s1 = "Some Text" >>> Printer.CurrentX = (Printer.ScaleWidth _ >>> - Printer.TextWidth(s1)) / 2 >>> Printer.Print s1 >>> >>> Note that you should set your font and font size *before* the above code >>> is executed. >>> >>> Mike >>> >>> >> >> > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message When declaring variables you really should get into the habit of news:u5Am7z2kJHA.5836@TK2MSFTNGP02.phx.gbl... > ... but I am wondering if this could be adapted to print > centered logo (image). Below is the code I am using to print Logo [most of > code snipped] > Dim Photo As StdPicture, MaxWidth, MaxHeight, picHeight, etc specifically setting them to the most suitable data type. If you fail to specify a particular type (as you have done above) then they will by default be declared as Variants, which is not usually a good idea (except if you spefically want a Variant for some special reson). In the above example you would be better off doing: Dim Photo as StdPicture, MaxWidth as Single, MaxHeight as Single, etc > MaxHeight = 40500 '2 inch One of the above values is more than ten times the other (although the > MaxWidth = 3540 '1.50 inch specified inch equivalents are not) and so they cannot both be correct unless you are using completely different scale units for the vertical and horizontal directions, which is possible but quite unusual. I'm not sure what scale units you are actually using but I assume they are supposed to be hiMetric units to match the units used by the StdPicture's Width and Height properties? In any case, it would be better to set your Printer scale units to something with which you are comfortable, inches perhaps, and then you will be able to see more clearly what your code is doing. > If picHeight > picWidth Then If you have (as in your case) a "maximum output size" rectangle whose aspect > 'if height is more than width > 'get Scale factor based on height > sFactor = MaxHeight / picHeight ratio can be set to arbitrary values and an original picture which can have its own quite different aspect ratio and if you want the picture drawn at its maximum possible size into the "maximum output size" rectangle whilst maintaining the original apsect ratio of the picture (phew, nearly lost myself there!) then it is not sufficient to merely check the aspect ratio of only the original picture (as you are doing) because this can produce entirely the wrong result in many cases. For such a thing to work under all circumstances you must check both the aspect ratio of the original image and the aspect ratio of the maximum output size rectangle and have your code decide which is the "fatter" of the two, adjusting the output size accordingly. > Is there a way to make the printer print a centered Yes. Just use the same method as was posted for producing centred text, > logo of specified height and width... except use the output width of the printed logo in the calculation instead of the width of the printed text. > Again one problem i notice is after printing logo the printer The vertical printed position of a line of text is determined by the value > does seem to print the next line over the log. Please help > and thanks in adavance of the Printer.CurrentY property at the time you print that text, and after printing the line of text the Printer automatically updates its CurrentY property by the height of the printed text, so that when you print another line of text it will be printed beneath the previous one (although this automatic update of the CurrentY property after printing a line of text can be suppressed if you wish by using a semi colon at the enbd of the Print statement). However, the Printer.PaintPicture method draws the picture at the coordinates (and at the size) specified in the PaintPicture statement, and using PaintPicture has no effect whatsoever on the value of the Printer.CurrentY property. So, if you wish to print a line of text below a picture which you have printed then you need to set Printer.CurrentY accordingly, in accordance with the location of the printed picture and its printed height (the values you specified in the PaintPicture statement). Putting all of the above together you would end up with something like the following code, which is just a simple example to print an image close to the top of the page and centred horozontally and to print some text beneath the printed picture. Paste the example into a Form containing a Command Button and of course change ther hard coded "c:\temp\han1.jpg" to a picture that exists on your own system: Mike Option Explicit Private Sub Command1_Click() Dim MaxWidth As Single, MaxHeight As Single Dim MaxRatio As Single, PicRatio As Single Dim outWide As Single, outHigh As Single Dim pX As Single, pY As Single Dim p1 As StdPicture, s1 As String Printer.ScaleMode = vbInches ' set printer scale units MaxHeight = 2 ' desired max height in inches MaxWidth = 1.5 ' desired max width in inches MaxRatio = MaxWidth / MaxHeight Set p1 = LoadPicture("c:\temp\jan1.jpg") ' calculate the picture's aspect ratio PicRatio = p1.Width / p1.Height If PicRatio > MaxRatio Then ' the picture aspect ratio is "fatter" than the ' maximum size aspect ratio so make the output ' width equal to the maximum width and adjust ' the height according to the pic ratio outWide = MaxWidth outHigh = outWide / PicRatio Else ' the picture aspect ratio is "thinner" than the ' maximum size aspect ratio so make the output ' height equal to the maximum height and adjust ' the width according to the pic ratio outHigh = MaxHeight outWide = outHigh * PicRatio End If pX = (Printer.ScaleWidth - outWide) / 2 pY = 0.05 ' desired position from top (inches) ' paint the picture Printer.PaintPicture p1, pX, pY, outWide, outHigh s1 = "Some Text below picture" ' set current y coord to 0.05 inch below bottom of picture Printer.CurrentY = pY + outHigh + 0.05 ' set current x coord so that text is centred Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(s1)) / 2 ' print the text Printer.Print s1 Printer.EndDoc End Sub I appreciate the pointers, comments and codes
Thank you Show quoteHide quote "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message news:uvemcR4kJHA.3868@TK2MSFTNGP05.phx.gbl... > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message > news:u5Am7z2kJHA.5836@TK2MSFTNGP02.phx.gbl... > >> ... but I am wondering if this could be adapted to print >> centered logo (image). Below is the code I am using to print Logo [most >> of code snipped] > >> Dim Photo As StdPicture, MaxWidth, MaxHeight, picHeight, etc > > When declaring variables you really should get into the habit of > specifically setting them to the most suitable data type. If you fail to > specify a particular type (as you have done above) then they will by > default be declared as Variants, which is not usually a good idea (except > if you spefically want a Variant for some special reson). In the above > example you would be better off doing: > > Dim Photo as StdPicture, MaxWidth as Single, MaxHeight as Single, etc > >> MaxHeight = 40500 '2 inch >> MaxWidth = 3540 '1.50 inch > > One of the above values is more than ten times the other (although the > specified inch equivalents are not) and so they cannot both be correct > unless you are using completely different scale units for the vertical and > horizontal directions, which is possible but quite unusual. I'm not sure > what scale units you are actually using but I assume they are supposed to > be hiMetric units to match the units used by the StdPicture's Width and > Height properties? In any case, it would be better to set your Printer > scale units to something with which you are comfortable, inches perhaps, > and then you will be able to see more clearly what your code is doing. > >> If picHeight > picWidth Then >> 'if height is more than width >> 'get Scale factor based on height >> sFactor = MaxHeight / picHeight > > If you have (as in your case) a "maximum output size" rectangle whose > aspect ratio can be set to arbitrary values and an original picture which > can have its own quite different aspect ratio and if you want the picture > drawn at its maximum possible size into the "maximum output size" > rectangle whilst maintaining the original apsect ratio of the picture > (phew, nearly lost myself there!) then it is not sufficient to merely > check the aspect ratio of only the original picture (as you are doing) > because this can produce entirely the wrong result in many cases. For such > a thing to work under all circumstances you must check both the aspect > ratio of the original image and the aspect ratio of the maximum output > size rectangle and have your code decide which is the "fatter" of the two, > adjusting the output size accordingly. > >> Is there a way to make the printer print a centered >> logo of specified height and width... > > Yes. Just use the same method as was posted for producing centred text, > except use the output width of the printed logo in the calculation instead > of the width of the printed text. > >> Again one problem i notice is after printing logo the printer >> does seem to print the next line over the log. Please help >> and thanks in adavance > > The vertical printed position of a line of text is determined by the value > of the Printer.CurrentY property at the time you print that text, and > after printing the line of text the Printer automatically updates its > CurrentY property by the height of the printed text, so that when you > print another line of text it will be printed beneath the previous one > (although this automatic update of the CurrentY property after printing a > line of text can be suppressed if you wish by using a semi colon at the > enbd of the Print statement). However, the Printer.PaintPicture method > draws the picture at the coordinates (and at the size) specified in the > PaintPicture statement, and using PaintPicture has no effect whatsoever on > the value of the Printer.CurrentY property. So, if you wish to print a > line of text below a picture which you have printed then you need to set > Printer.CurrentY accordingly, in accordance with the location of the > printed picture and its printed height (the values you specified in the > PaintPicture statement). > > Putting all of the above together you would end up with something like the > following code, which is just a simple example to print an image close to > the top of the page and centred horozontally and to print some text > beneath the printed picture. Paste the example into a Form containing a > Command Button and of course change ther hard coded "c:\temp\han1.jpg" to > a picture that exists on your own system: > > Mike > > Option Explicit > > Private Sub Command1_Click() > Dim MaxWidth As Single, MaxHeight As Single > Dim MaxRatio As Single, PicRatio As Single > Dim outWide As Single, outHigh As Single > Dim pX As Single, pY As Single > Dim p1 As StdPicture, s1 As String > Printer.ScaleMode = vbInches ' set printer scale units > MaxHeight = 2 ' desired max height in inches > MaxWidth = 1.5 ' desired max width in inches > MaxRatio = MaxWidth / MaxHeight > Set p1 = LoadPicture("c:\temp\jan1.jpg") > ' calculate the picture's aspect ratio > PicRatio = p1.Width / p1.Height > If PicRatio > MaxRatio Then > ' the picture aspect ratio is "fatter" than the > ' maximum size aspect ratio so make the output > ' width equal to the maximum width and adjust > ' the height according to the pic ratio > outWide = MaxWidth > outHigh = outWide / PicRatio > Else > ' the picture aspect ratio is "thinner" than the > ' maximum size aspect ratio so make the output > ' height equal to the maximum height and adjust > ' the width according to the pic ratio > outHigh = MaxHeight > outWide = outHigh * PicRatio > End If > pX = (Printer.ScaleWidth - outWide) / 2 > pY = 0.05 ' desired position from top (inches) > ' paint the picture > Printer.PaintPicture p1, pX, pY, outWide, outHigh > s1 = "Some Text below picture" > ' set current y coord to 0.05 inch below bottom of picture > Printer.CurrentY = pY + outHigh + 0.05 > ' set current x coord so that text is centred > Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(s1)) / 2 > ' print the text > Printer.Print s1 > Printer.EndDoc > End Sub > > > > On Feb 19, 7:59 am, "jpBless" <jp3blessNoS***@hotmail.com> wrote: Very simple,> I am stomped on this one... I am trying to center text using printer object. > I am printing to a receipt printer. I have tried many things; sometimes it > centers the text sometimes it "gets confused" and print just about at any > point. Is there a built in text centering command using printer object? > Anyone have an ideas? > > Thanks in advance Get the width of the printer paper (it's part of the printer object [maybe something like printer.printwidth] - I'm not sure I remember correctly) , then subtract the width of the text, the remaining result should be devided in two and that is your starting character to print from. Sorry I couldn't give you code, I have very bad memory of code, but the description is 100% of how to center align receipt printer's printing for a certain string. Support, www.AlexandriaComputers.com Immense info... thanks all
Show quoteHide quote "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >I am stomped on this one... I am trying to center text using printer >object. I am printing to a receipt printer. I have tried many things; >sometimes it centers the text sometimes it "gets confused" and print just >about at any point. Is there a built in text centering command using >printer object? Anyone have an ideas? > > Thanks in advance > See how much help you get when you post your code? <g>
-- Show quoteHide quoteMike "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message news:uzmdOkukJHA.3380@TK2MSFTNGP04.phx.gbl... > Immense info... thanks all > > > "jpBless" <jp3blessNoSpam@hotmail.com> wrote in message > news:u17qxHpkJHA.2384@TK2MSFTNGP04.phx.gbl... >>I am stomped on this one... I am trying to center text using printer >>object. I am printing to a receipt printer. I have tried many things; >>sometimes it centers the text sometimes it "gets confused" and print just >>about at any point. Is there a built in text centering command using >>printer object? Anyone have an ideas? >> >> Thanks in advance >> > > >
ShellExecute
OT: Recommend web host Is that possible? Dot matrix network printer problem Number Of Application Automation "Object invoked has disconnected...." error Take taskbar/quicklauch bars into account??? Call sub or function using a string value for the name How to delete an Oracle Blob field with VB6....? History of Languages |
|||||||||||||||||||||||