Paper size problems

Paper size problems

Postby cdmmaui » Fri Apr 23, 2010 4:27 pm

Hello Everyone, I am having inconsistancy problems when setting the paper size on printer. We are trying to set the paper size to 4 inches wide by 6 inches high on a thermal printer that only prints 4 by 6 labels. However, when we send output to printer it prints at 8.5 by 11 ignoring our printer size request. My source code is listed below, can anyone provide sample code that will resolve my problem. I thank you in advance for your assistance.

// Paper Size...
nPWid := 254 * 4
nPHgt := 254 * 6
PrnSetSize( nPWid, nPHgt )

PRINT oPrinter FROM USER NAME "M/R Package Detail Label " + ALLTRIM( cPartno ) PREVIEW

/* Check if Object is Empty */
if empty( oPrinter:hDC )
return nil
endif

// Fonts...
DEFINE FONT oFont1 NAME "Arial" SIZE 0,-24 BOLD OF oPrinter
DEFINE FONT oFont2 NAME "Arial" SIZE 0,-18 OF oPrinter
DEFINE FONT oFont3 NAME "Arial" SIZE 0,-10 OF oPrinter
DEFINE FONT oFont4 NAME "Arial" SIZE 0,-8 OF oPrinter

// Init...
Mwidth = oPrinter:nHorzRes()
Mheight = oPrinter:nVertRes()
M_hgt = oPrinter:GetTextHeight("X", oFont3 )

SELECT (cTmpDb)
GO TOP
DO WHILE ! EOF()
IF EMPTY( (cTmpdb)->prt )
SKIP
LOOP
ENDIF

// Start...
PAGE

M_row = ROUND( Mheight * .03, 2)
M_rto = ROUND( Mheight * .13, 2)
M_col = ROUND( Mwidth * .05, 2)
M_cto = ROUND( Mwidth * .25, 2)

IF FILE(cLogo)
DEFINE BITMAP oLogo FILENAME cLogo
oPrinter:SayBitmap( M_row, M_col, cLogo, (M_cto-M_col), M_row+(M_rto-M_row) )
ENDIF

// Header...
Mrow := ROUND( Mheight * .03, 0)
FOR nX=1 TO LEN( aHeader )
M_dat = aHeader[nX]
M_col = ROUND( Mwidth * .40,0)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt
NEXT nX

// Part No...
Mrow := ROUND( Mheight * .20, 0)
M_dat = "PART NUMBER"
M_wid = oPrinter:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

M_dat = ALLTRIM( cPartno )
M_wid = oPrinter:GetTextWidth(M_dat, oFont2 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont2 )
oPrinter:Say( Mrow, M_col, M_dat, oFont2 )
Mrow += M_hgt

// Barcode...
@Mrow, M_col CODE128 M_dat of oPrinter MODE 'A'
Mrow += M_hgt
Mrow += M_hgt
Mrow += M_hgt

// Init...
nW = 28
nN = MLCOUNT( (cTmpdb)->desc, nW, 0, .T.)
IF nN>2
nN := 2
ENDIF
FOR nZ = 1 TO nN
M_dat = MEMOLINE( (cTmpdb)->desc, nW, nZ )
M_wid = oPrinter:GetTextWidth(M_dat, oFont3 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont3 )
oPrinter:Say( Mrow, M_col, M_dat, oFont3 )
Mrow += M_hgt
NEXT nZ
Mrow += M_hgt

// Serial...
Mrow := ROUND( Mheight * .50, 0)
M_dat = "SERIAL / CCL NUMBER"
M_wid = oPrinter:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

M_dat = ALLTRIM( (cTmpdb)->number )
M_wid = oPrinter:GetTextWidth(M_dat, oFont2 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont2 )
oPrinter:Say( Mrow, M_col, M_dat, oFont2 )
Mrow += M_hgt

// Barcode...
@Mrow, M_col CODE128 M_dat of oPrinter MODE 'A'

// Date-Time...
Mrow := ROUND( Mheight * .75, 0)
M_dat = "DATE / TIME"
M_wid = oPrinter:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

M_dat = DTOC( DATE() )
M_wid = oPrinter:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .25,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )

M_dat = TIME()
M_wid = oPrinter:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .75,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt
Mrow += M_hgt

// Packer...
Mrow := ROUND( Mheight * .90, 0)
M_dat = "PACKER NAME"
M_wid = oPrinter:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrinter:GetTextHeight("X", oFont4 )
oPrinter:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

// End page...
ENDPAGE

SELECT (cTmpdb)
SKIP
ENDDO

// End...
ENDPRINT

nPWid := 254 * 8.5
nPHgt := 254 * 11
PrnSetSize( nPWid, nPHgt )
PrnSetPage(1)

// Release Fonts...
RELEASE oFont1
RELEASE oFont2
RELEASE oFont3
RELEASE oFont4
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Paper size problems

Postby James Bott » Fri Apr 23, 2010 6:53 pm

Darrell,

It appears you are setting the size of the default printer, then allowing the user to change the printer.

I suggest trying:

PRINT oPrinter FROM USER NAME "M/R Package Detail Label " + ALLTRIM( cPartno ) PREVIEW

oPrinter:PrnSetSize( nPWid, nPHgt )

Also I am not sure about your calcualtion of nPWid, and nPHgt. Where is the 254 coming from? I assume that is pixels/inch, but this will vary with different printers. You really need a generic routine that will set the size in inches. So you need to get the pixels per inch from oPrinter. Try this:

nPWid:= 4 // in inches
nPHgt:= 6 // in inches
oPrinter:SetSize( oPrinter:nLogPixelx() * nPWid, oPrinter:nLogPixely() * nPHgt )

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Paper size problems

Postby cdmmaui » Fri Apr 23, 2010 11:23 pm

Hi James,

Thank you for your response, however the parameters to for oPrinter:SetSize( <nWidth>, <nHeight> )

Parameters:
<nWidth> Width of the paper of the printer in tenths of millimeter.
<nHeight> Height of the paper of the printer in tenths of millimeter.

I know the printer supports the paper size, the 254 is number of tenths of millimeters where 25.4 millimeters equals one inch.

I appreciate any additional assistance you can provide.
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Paper size problems

Postby James Bott » Fri Apr 23, 2010 11:38 pm

Darrell,

OK, my mistake. So your original numbers were right.

Code: Select all  Expand view  RUN
// Paper Size...
nPWid := 254 * 4
nPHgt := 254 * 6
//PrnSetSize( nPWid, nPHgt ) // Remove this

PRINT oPrinter FROM USER NAME "M/R Package Detail Label " + ALLTRIM( cPartno ) PREVIEW

oPrinter:setSize( nPWid, nPHgt )  // add this


Try that.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Paper size problems

Postby cdmmaui » Sat Apr 24, 2010 12:55 am

Hi James, I tried that as well with no luck. I am using FWB 8.10, do you think there is a newer version that corrects this problem?
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Paper size problems

Postby James Bott » Sat Apr 24, 2010 1:08 am

I think it is more likely a problem with the printer driver. Have you tried setting the size with other software? Word perhaps?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Paper size problems

Postby cdmmaui » Sat Apr 24, 2010 12:55 pm

Good Morning James, I tested from MS Word and it printed correctly.
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Paper size problems

Postby cdmmaui » Sat Apr 24, 2010 2:57 pm

// 4 by 6
PrnSetSize( 1016,1524 )

PRINT oPrn FROM USER NAME "M/R Package Detail Label" PREVIEW

/* Check if Object is Empty */
if empty( oPrn:hDC )
return nil
endif

// Fonts...
DEFINE FONT oFont1 NAME "Arial" SIZE 0,-24 BOLD OF oPrn
DEFINE FONT oFont2 NAME "Arial" SIZE 0,-18 OF oPrn
DEFINE FONT oFont3 NAME "Arial" SIZE 0,-10 OF oPrn
DEFINE FONT oFont4 NAME "Arial" SIZE 0,-8 OF oPrn

// Init...
Mwidth = oPrn:nHorzRes()
Mheight = oPrn:nVertRes()
M_hgt = oPrn:GetTextHeight("X", oFont3 )

SELECT (cTmpDb)
GO TOP
DO WHILE ! EOF()
IF EMPTY( (cTmpdb)->prt )
SKIP
LOOP
ENDIF

// Start...
PAGE

M_row = ROUND( Mheight * .03, 2)
M_rto = ROUND( Mheight * .13, 2)
M_col = ROUND( Mwidth * .05, 2)
M_cto = ROUND( Mwidth * .25, 2)

IF FILE(cLogo)
DEFINE BITMAP oLogo FILENAME cLogo
oPrn:SayBitmap( M_row, M_col, cLogo, (M_cto-M_col), M_row+(M_rto-M_row) )
ENDIF

// Header...
Mrow := ROUND( Mheight * .03, 0)
FOR nX=1 TO LEN( aHeader )
M_dat = aHeader[nX]
M_col = ROUND( Mwidth * .40,0)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt
NEXT nX

// Part No...
Mrow := ROUND( Mheight * .20, 0)
M_dat = "PART NUMBER"
M_wid = oPrn:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

M_dat = ALLTRIM( cPartno )
M_wid = oPrn:GetTextWidth(M_dat, oFont2 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont2 )
oPrn:Say( Mrow, M_col, M_dat, oFont2 )
Mrow += M_hgt

// Barcode...
@Mrow, M_col CODE128 M_dat of oPrn MODE 'A'
Mrow += M_hgt
Mrow += M_hgt
Mrow += M_hgt

// Init...
nW = 28
nN = MLCOUNT( (cTmpdb)->desc, nW, 0, .T.)
IF nN>2
nN := 2
ENDIF
FOR nZ = 1 TO nN
M_dat = MEMOLINE( (cTmpdb)->desc, nW, nZ )
M_wid = oPrn:GetTextWidth(M_dat, oFont3 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont3 )
oPrn:Say( Mrow, M_col, M_dat, oFont3 )
Mrow += M_hgt
NEXT nZ
Mrow += M_hgt

// Serial...
Mrow := ROUND( Mheight * .50, 0)
M_dat = "SERIAL / CCL NUMBER"
M_wid = oPrn:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

M_dat = ALLTRIM( (cTmpdb)->number )
M_wid = oPrn:GetTextWidth(M_dat, oFont2 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont2 )
oPrn:Say( Mrow, M_col, M_dat, oFont2 )
Mrow += M_hgt

// Barcode...
@Mrow, M_col CODE128 M_dat of oPrn MODE 'A'

// Date-Time...
Mrow := ROUND( Mheight * .75, 0)
M_dat = "DATE / TIME"
M_wid = oPrn:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

M_dat = DTOC( DATE() )
M_wid = oPrn:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .25,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )

M_dat = TIME()
M_wid = oPrn:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .75,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt
Mrow += M_hgt

// Packer...
Mrow := ROUND( Mheight * .90, 0)
M_dat = "PACKER NAME"
M_wid = oPrn:GetTextWidth(M_dat, oFont4 )
M_col = ROUND( Mwidth * .50,0) - (M_wid/2)
M_hgt = oPrn:GetTextHeight("X", oFont4 )
oPrn:Say( Mrow, M_col, M_dat, oFont4 )
Mrow += M_hgt

// End page...
ENDPAGE

SELECT (cTmpdb)
SKIP
ENDDO

// End...
ENDPRINT

// 8.5 by 11
PrnSetSize( 2159,2794 )

// Release Fonts...
RELEASE oFont1
RELEASE oFont2
RELEASE oFont3
RELEASE oFont4
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Paper size problems

Postby cdmmaui » Sat Apr 24, 2010 2:57 pm

Hi James, the code I just posted worked
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Paper size problems

Postby James Bott » Sat Apr 24, 2010 4:15 pm

Darrell,

I don't see what is different in your latest code?

I still think you need to call PrnSetSize() AFTER allowing the user to pick a printer. In your test example you may have not changed the default printer.

Better would be to set the printer for this job via a different menu or setup screen then always print to the specified printer, then change back to whatever printer was current before the print task. This prevents the user from having to select the proper printer each time they have to print. I have posted routines for how to do this on this forum before. If you can't find them, let me know.

This concept is the "less is more" (less is better) interface design.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Marc Venken and 79 guests