Announcement

Collapse
No announcement yet.

GETPHYSPAGESIZE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GETPHYSPAGESIZE

    The hp5 i use, does not return valid A4 sizes.

    Would like to know the physical pagesize and printable area.

    The printable area seems to work ok.
    But the ph. size looks if it was recalculated: A4 - printable area or sort of..

    Maybe someone has a good tip to collect the sizes for w95 and nt?

    My code used;

    Code:
    '// Printing offset
    Escape hDC, %GETPRINTINGOFFSET, ByVal 0&, ByVal 0&, pt
    
    If pt.x = 0 Then
    
        pt.x = GetDeviceCaps( hDC, %PHYSICALOFFSETX )
        pt.y = GetDeviceCaps( hDC, %PHYSICALOFFSETY )
    
    End If
    
    '// Physical
    Escape hDC, %GETPHYSPAGESIZE, ByVal 0&, ByVal 0&, ptf
    
    If ptf.x = 0 Then
    
        ptf.x = GetDeviceCaps( hDC, %PHYSICALWIDTH )
        ptf.y = GetDeviceCaps( hDC, %PHYSICALHEIGHT )
    
    End If
    Note that A4 = 21 x 27 = 16840 x 11908 twips

    Thanks,

  • #2
    Edwin --
    With physical sizes all is clear
    Letter, 8 1/2 x 11 in.
    Letter Small, 8 1/2 x 11 in.
    Tabloid, 11 x 17 in.
    Ledger, 17 x 11 in.
    Legal, 8 1/2 x 14 in.
    Statement, 5 1/2 x 8 1/2 in.
    Executive, 7 1/2 x 10 1/2 in.
    A3, 297 x 420 mm
    A4, 210 x 297 mm
    A4 Small, 210 x 297 mm
    A5, 148 x 210 mm
    B4, 250 x 354 mm
    B5, 182 x 257 mm
    Folio, 8 1/2 x 13 in.
    Quarto, 215 x 275 mm
    10 x 14 in.
    11 x 17 in.
    Note, 8 1/2 x 11 in.
    Envelope #9, 3 7/8 x 8 7/8 in.
    Envelope #10, 4 1/8 x 9 1/2 in.
    Envelope #11, 4 1/2 x 10 3/8 in.
    Envelope #12, 4 1/2 x 11 in.
    Envelope #14, 5 x 11 1/2 in.
    C size sheet
    D size sheet
    E size sheet
    Envelope DL, 110 x 220 mm
    Envelope C3, 324 x 458 mm
    Envelope C4, 229 x 324 mm
    Envelope C5, 162 x 229 mm
    Envelope C6, 114 x 162 mm
    Envelope C65, 114 x 229 mm
    Envelope B4, 250 x 353 mm
    Envelope B5, 176 x 250 mm
    Envelope B6, 176 x 125 mm
    Envelope, 110 x 230 mm
    Envelope Monarch, 3 7/8 x 7 1/2 in.
    Envelope, 3 5/8 x 6 1/2 in.
    U.S. Standard Fanfold, 14 7/8 x 11 in.
    German Standard Fanfold, 8 1/2 x 12 in.
    German Legal Fanfold, 8 1/2 x 13 in.

    but printable area depends of driver.

    ------------------

    Comment


    • #3
      I need to know what pagesize is choosen.
      I don't care for measuring the ph. size as you suggested.

      But what size IS choosen by user?

      The printable area is part printer depending but also the Windows margins set.
      Some(all?) drivers can't handle a margin of 0.
      But that's not important for now.

      Thanks,


      ------------------

      Comment


      • #4
        Edwin --
        GevDevCaps, for printers
        HORZSIZE Width, in millimeters, of printable area
        VERTSIZE Height, in millimeters, of printable area
        HORZRES Width, in pixels, of printable area
        VERTRES Height, in pixels, of printable area
        LOGPIXELSX Number of pixels per horizontal logical inch
        LOGPIXELSY Number of pixels per vertical logical inch
        You need something else ?


        ------------------

        Comment


        • #5
          Yes, please read more carefully..

          See my original post;
          It's about the physical area, how to determine sizes or what the user selected.
          Something that should work on each platform/country.

          Thanks,


          ------------------

          Comment


          • #6
            Yes, I really do not understand you (language problems ?).
            In any case on my PC with russian settings, HP Deskjet 600,
            following fragment (last Msgbox) for A4 returns 210 * 297 mm.
            If I change a paper size - also new correct values.
            Code:
            #Compile Exe
            #Register None
            #Include "Win32Api.Inc"
            
            Function PbMain
              Dim PrinterName As Asciiz * %MAX_PATH
              Dim Printer_hDC As Long
            
              GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName$, SizeOf(PrinterName$)
              PrinterName$ = Left$(PrinterName$, Instr(PrinterName$, ",") -1)
              If PrinterName$ = "" Then Exit Function
            
              Printer_hDC& = CreateDC(ByVal %Null, PrinterName$, ByVal %Null, ByVal %Null)
              MsgBox "Physical, Pixels : "   + Str$(GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH)) + _
                                               Str$(GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT))
              MsgBox "Offsets, Pixels  : "   + Str$(GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETX)) + _
                                               Str$(GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETY))
              MsgBox "Resolution, dpi  : "   + Str$(GetDeviceCaps(Printer_hDC&, %LOGPIXELSX)) + _
                                               Str$(GetDeviceCaps(Printer_hDC&, %LOGPIXELSY))
              MsgBox "Print Area, Pixels : " + Str$(GetDeviceCaps(Printer_hDC&, %HORZRES)) + _
                                               Str$(GetDeviceCaps(Printer_hDC&, %VERTRES))
            
             MsgBox "Physical paper size (twips): "  + Format$(1440 * GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH) / _
                                                       GetDeviceCaps(Printer_hDC&, %LOGPIXELSX), "#") + " x " + _
                                                       Format$(1440 * GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT) / _
                                                       GetDeviceCaps(Printer_hDC&, %LOGPIXELSY), "#")
            
              MsgBox "Physical paper size (mm): "  + Format$(25.4 * GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH) / _
                                                       GetDeviceCaps(Printer_hDC&, %LOGPIXELSX), "#") + " x " + _
                                                     Format$(25.4 * GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT) / _
                                                       GetDeviceCaps(Printer_hDC&, %LOGPIXELSY), "#")
            
              DeleteDc Printer_hDC&
            End Function
            Note, that I use drivers, included in Windows (not separate HP' drivers)

            [This message has been edited by Semen Matusovski (edited March 08, 2000).]

            Comment


            • #7
              Semen,
              an excellent sample! I just played with it a little to get the kind of output I am looking for just now.

              Code:
              #COMPILE EXE
              #REGISTER NONE
              #INCLUDE "Win32Api.Inc"
              FUNCTION PBMAIN
                DIM PrinterName AS ASCIIZ * %MAX_PATH
                DIM Printer_hDC AS LONG
                GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName$, SIZEOF(PrinterName$)
                PrinterName$ = LEFT$(PrinterName$, INSTR(PrinterName$, ",") -1)
                IF PrinterName$ = "" THEN EXIT FUNCTION
                Printer_hDC& = CreateDC(BYVAL %Null, PrinterName$, BYVAL %Null, BYVAL %Null)
              
                ResolutionWidth& = GetDeviceCaps(Printer_hDC&, %LOGPIXELSX)
                ResolutionHeight& = GetDeviceCaps(Printer_hDC&, %LOGPIXELSY)
              
                pixelsLeftMargin& =GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETX)
                pixelsTopMargin& =GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETY)
              
                pixelsPrintWidth&  = GetDeviceCaps(Printer_hDC&, %HORZRES)
                pixelsPrintHeight& = GetDeviceCaps(Printer_hDC&, %VERTRES)
              
                pixelsPhysicalWidth& = GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH)
                pixelsPhysicalHeight& = GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT)
              
                [email protected] = pixelsPhysicalWidth&/ResolutionWidth&
                [email protected] = pixelsPhysicalHeight&/ResolutionHeight&
              
                [email protected] = pixelsLeftMargin&/ResolutionWidth&
                [email protected] = (pixelsPhysicalWidth& - pixelsPrintWidth& - pixelsLeftMargin&)/ResolutionWidth&
                [email protected] = pixelsTopMargin&/ResolutionHeight&
                [email protected] = (pixelsPhysicalHeight& - pixelsPrintHeight& - pixelsTopMargin&)/ResolutionHeight&
                
                MSGBOX "Resolution (dpi): "   + STR$(ResolutionWidth&) + " Wide x" _
                                              +STR$(ResolutionWidth&) + " High" + CHR$(13,13) + _
                       "Physical paper size (inch): " + STR$([email protected]) + " Wide x" _
                                                      + STR$([email protected]) + " High" + CHR$(13,13) + _
                       "Margins (inch): " + CHR$(13) _
                        + "Left: " + FORMAT$([email protected],"#.##") _
                        + "  Right: " + FORMAT$([email protected],"#.##") + CHR$(13) _
                        + "Top: " + FORMAT$([email protected],"#.##") _
                        + "  Bottom: " + FORMAT$([email protected],"#.##")
              
                DeleteDc Printer_hDC&
              END FUNCTION
              Regards,

              ------------------
              [email protected]
              :) IRC :)

              Comment


              • #8
                I must be on another planet!

                That's what i'm doing ain't it?, why the examples about the same.

                Sorry,

                ------------------

                Comment


                • #9
                  Maybe i need to try swap to error-order.

                  I know that only in NT GetDevicecaps IS a must.
                  Therefore i check it first with Escape.
                  Maybe this returns an invalid size..

                  Tomorrow..


                  ------------------

                  Comment


                  • #10
                    only in NT GetDevicecaps IS a must.
                    Therefore i check it first with Escape.
                    My sample works under Win9x without problems (I tested in 95b).
                    Yes, there are some fields for NT only. But another (see Win32.Hlp)


                    ------------------

                    Comment


                    • #11
                      FYI: both Semen's and Ian's snippets run fine under Win2000.

                      Edwin, why are you using an ESCAPE? While Win32 supports "some" escapes, they are essentially obsolete. Are you writing for API level 3? (NT3.51)

                      When encountering these types of problems, be sure to test them with a wide range of printer drivers - Escapes may not always be "reliable".


                      ------------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment


                      • #12
                        Thanks, i guessed i mixed some MSDN info here and there.

                        I was informed that GetDev.. wasn't supported on all printers (the most do i think)
                        Escape is obsolete, i know, so i tried it using escape first then getdev.
                        It seems Escape does return an incorrect value, need to check this one out later.

                        Thank you all, i'll swap the above example (my example)



                        ------------------

                        Comment

                        Working...
                        X