News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

printing a file on my printer

Started by allynm, October 29, 2009, 02:30:19 AM

Previous topic - Next topic

jj2007

Quote from: RuiLoureiro on November 02, 2009, 10:12:31 PM
             Thank you for your comment «The font is a big high ... » !

Rui,
Fine code, compliments :U
Re the "high" font:
                xor eax, eax
                mov     _lf.lfHeight, eax

Not specifying the height will provide you with a wellshaped font. There is another problem: Much of the page is wasted by a huge lower margin; however, this is probably not your code's fault but rather a problem of the PdfCreator printer driver returning wrong values for invoke  GetDeviceCaps, _hpdc, VERTRES
Do people with real printers experience a huge bottom page gap??

allynm

Hi RuiLoureiro:

I downloaded Printer 10 and ran it.  I'm not entirely sure, but it doesn't seem to actually associate the file I would like to print with what the printer actually prints.  I use the print dialog box to select a file -- in this case a txt file -- and the printer is activated and turns out a piece of paper.  But, the stuff that is printed doesn't seem to be related to what's in the txt file.

Mebbe I'm doing something wrong??

Regards,
Mark

hutch--

JJ,

It usually has something to do with the paper size. I have a number of drivers loaded to create PDF, PrimoPDF works fine, the old Adobe Acrobat works fine and there are a few others. Some have setting depending on what you want, display PDF or printing PDF, for test bits I use the display option.

Another factor is if the printing software sets the margin sizes, if it is working properly you should not get the effect you mention.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on November 03, 2009, 03:34:25 AM
JJ,

It usually has something to do with the paper size. I have a number of drivers loaded to create PDF, PrimoPDF works fine, the old Adobe Acrobat works fine and there are a few others. Some have setting depending on what you want, display PDF or printing PDF, for test bits I use the display option.

Another factor is if the printing software sets the margin sizes, if it is working properly you should not get the effect you mention.

Hutch,

I guess you saw my rant in the Colosseum. Furthermore, the GetDeviceCaps returns clearly false values. I have tested it with PdfCreator/PrimoPDF (thanks for the hint)/Ms Office Document Image Write, and get this:
   mov ebx, rv(GetDeviceCaps, hPrDC, PHYSICALWIDTH)   ; yields 4958/4961/2480 - expected 11907 for A4
   mov esi, rv(GetDeviceCaps, hPrDC, PHYSICALHEIGHT)   ; yields 7017/7016/3508 - expected 16840 for A4

MSDN on GetDeviceCaps PHYSICALWIDTH:
For printing devices: the width of the physical page, in device units. For example, a printer
set to print at 600 dpi on 8.5-x11-inch paper has a physical width value of 5100 device units.


"device units" should be twips, but of course MS does not see a need to explain what they mean. If the above is not confusing enough, try Device vs. Design Units on MSDN.

Anyway, I got it working perfectly for RichMasm ;-)

@Mark: Printer10.asm prints the file I want it to print. Check if you had an old job in the printer queue ;-)
@Rui: There is a potential GPF, see attachment. When I try to print ClearFPU.asm, it chokes.
Sorry for that, jj.

RuiLoureiro

Hi Jochen,
           1. Thank you for reply. You got the bug quickly ! Thanks for that  :U

           2. The bug is here:
Quote
NxtLinFrm       proc
                mov     edi, _pFrmBuf                   
                mov     eax, dword ptr [edi - EndRegLst]
                add     eax, 1
                cmp     eax, dword ptr [edi - MaxRegLst]
                jbe     short @F
                ;
                fn   MessageBox, _hWnd, "Insufficient buffer", "Warning", MB_OK
                stc
                ret
                ;
@@:             mov     dword ptr [edi - EndRegLst], eax
                ;
                sub     eax, 1
                mul     dword ptr [edi - LenRegLst]
                add     edi, eax
                mov     edx, edi        ;<<<<<<<<<-------------- HERE ###############
                ;
                mov     dword ptr [edi - 4], 0              ; string length  = 0
                clc
                ret
NxtLinFrm       endp
           

Hi Allynm,
           Please zip the file you are using and post it if you can. Is it a text file ?
           A text file is one where each line ends in Return (13) and LineFeed (10).
           You should use print dialog box to select a file. Read the rest

            New Printer10
            I modified GetPrinterDC and
            now, with Printer10, we can print Vertically or Horizontally
            I made some comments in the code too.

            If we dont want to see the printer dialog Box,
            comment this:
            mov     _pd.Flags, PD_RETURNDC or PD_PRINTSETUP
            and uncomment this:
            ;mov     _pd.Flags, PD_RETURNDC or PD_RETURNDEFAULT
            and assemble Printer10.asm.
            It returns a printer DC without dialog box.

    LATER:  Jochen,
            In GetPrinterDC do this:
                    ;invoke    CreateFontX, addr _FontMSSSerif, edx, eax, FW_NORMAL, 0
                    invoke    CreateFontX, addr _FontMSSSerif, 0, eax, FW_NORMAL, 0
            In PrintPage do this:
                    @@:       mov     MaxLin, 78      ;49             ;_mLines
           
Rui Loureiro

allynm

Hi RuiLoureiro-

Finally got a chance to try new Printer 10.  Seems to work fine.  I didn't realize previously that it was for txt files only.  I should have figured that out....Sorry.

The "choose printer" function works perfectly.  I have a bunch of printers in my office here at the university and it selected the Dell Laser printer I have and ran a multiple page document OK.

Great job!!

Mark

RuiLoureiro

Hi Allynm,
               ok i hope i have helped you. If you have some problems with the code,
               please tell me. I was a teacher but retired now  :U               

Hi jj,
                Do you know how i can know the orientation that was chosen after PrintDlg returns ?
                I know it is a word in DEVMODE  (dmOrientation), but how to access it ?
                I want to call PrintDlg with hDevMode=NULL and hDevNames =NULL. No ?

                Anyone can help me ?
Thanks
Rui

jj2007

#52
Quote from: RuiLoureiro on November 03, 2009, 09:38:03 PM
                Do you know how i can know the orientation that was chosen after PrintDlg returns ?

Hi Rui,

Here is a snippet. But you don't really need it if you use CreateDC as shown attached.

invoke PageSetupDlg, addr psd ; get a printer
...
pushad
mov esi, rv(GlobalLock, psd.hDevMode) ; we need to access the memory
movzx eax, word ptr [esi.DEVMODE.dmOrientation] ; it's a "short" variable, but Masm needs "word"
.if eax==DMORIENT_PORTRAIT
MsgBox 0, "Portrait", "Hi", MB_OK
.elseif eax==DMORIENT_LANDSCAPE
MsgBox 0, "Landscape", "Hi", MB_OK
.else
MsgBox 0, "WTF", 0, MB_OK
.endif
invoke GlobalUnlock, psd.hDevMode ; unlock the mem
invoke GlobalFree, psd.hDevMode ; and free it
popad

:thumbu

jj2007

If anybody is interested in scaling the output, see here and the attached algo.

RuiLoureiro

Quote from: jj2007 on November 04, 2009, 06:15:39 AM
Here is a snippet. But you don't really need it if you use CreateDC as shown attached.
Jochen,
            Thank you for reply.
            That helped me to get the solution. Thanks
            The solution is to get the DEVMODE structure pointer using GlobalLock.
           
            First we invoke  PrintDlg, addr _pd with
           
                        mov     _pd.hDevMode, NULL
                        mov     _pd.hDevNames, NULL

            and when PrintDlg returns we use «invoke GlobalLock, _pd.hDevMode»
           
            Thank you Jochen!  :thumbu           

Quote         
GetOrientation      proc

                    mov         _Orientation, 0              ; assume 0 means vertical
                    mov         _PrinterLines, PRINTERLINESV ; number of lines
                   
                    ; »»»»»»»»»»»»»»»»»»»»»»»»
                    ; Get the Memory Pointer
                    ; to DEVMODE structure
                    ; »»»»»»»»»»»»»»»»»»»»»»»
                    invoke      GlobalLock, _pd.hDevMode           ; memory handle
                    cmp         eax, NULL
                    jne         short @F

                    fn  MessageBox, _hWnd, "GlobalLock error","Error", MB_OK
                    stc
                    ret
                    ; »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
                    ; EAX = starting memory address of DEVMODE structure
                    ; »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
@@:                 mov         ebx, eax
                    mov         eax, [ebx].DEVMODE.dmFields
                    and         eax, DM_ORIENTATION
                    jnz         short @F
                    stc
                    ret

@@:                 mov         ax, [ebx].DEVMODE.dmOrientation
                    cmp         ax, DMORIENT_PORTRAIT
                    jne         short @F                   
                    clc
                    ret
                   
@@:                 mov     ax, [ebx].DEVMODE.dmOrientation
                    cmp     ax, DMORIENT_LANDSCAPE
                    jne     short @F

                    mov         _PrinterLines, PRINTERLINESH
@@:                 clc         ; assume 0
                    ret
GetOrientation      endp
 

                Printer10 has a potential bug if number of pages are larger than 100.
               
                I followed your suggestion and in Printer12 i create a font
                with height=0 width=0. It seems to print correctly when the orientation
                is DMORIENT_LANDSCAPE or DMORIENT_PORTRAIT in A4 sheets. It prints
                number of pages like «Page 3/12» when it has 12 pages.

                This Printer12 is not a prog to print text files but to try to
                understand what to do to and to learn some things to help Mark Allynm.
                Meanwhile it prints text files. Correctly, i hope.

Allynm,
                Thanks for your words ! Now, you can read the .asm file (and .inc) and
                write your own procedures, improve others, etc. to print what you want,
                i hope. You can comment out the lines of code you are not interested in
                and assemble the .asm file again. I suggest you save it with another
                name and than comment out ... etc assemble and run...

Rui Loureiro

RuiLoureiro

#55
Hi
    New version: PrintIt to print text files up to 800 pages vertically or horizontally in A4
    Try it and say something
     Files: PrintIt.zip (.ini, .asm, .inc) and rsrc.zip
     LATER:Printer12 has a problem. See «GetOpenFileName causes an error»
Rui

scjain

hi everyone,
thanks all for valuable examples and tutorials on printing subject.after going through all the posts i found that nothing is available on printing records from a database table aligning fields . can you help in this matter.The sample requirement is as below-
fields in database table-date c(10), Name C(40), Add1 C(30), Add2 C(25)
Print on row1,col 01 date
Print on row1,col 12 Name - length varies from records to records.
Print on row1,col 55 Add1  - length varies from records to records.
Print on row1,col 90 Add2  - length varies from records to records.
thanking all
scj

Magnum

Quote from: hutch-- on October 29, 2009, 03:52:12 AM
Mark,

This is not exactly what you were after but it does print to a default printer correctly, its the complete code for a printing DLL complete with preview window and font settings. You call the DLL from this procedure,



[/quote]

This doesn't work on my computer. I use a Canon printer.

It shoots out a page, but it is blank.

Have a great day,
                         Andy