Recent

Author Topic: [partially solved] Win32 Printing  (Read 7943 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
[partially solved] Win32 Printing
« on: December 20, 2014, 08:42:58 pm »
I've included the Printer4Lazarus package, added Printers to my Uses clause and I've tried several approaches for printing a bitmap. They all compile but have the same error on execution- a little box that says "the GDB process is no longer running". This appears after trying to execute the Printer.BeginDoc line. Anyone know the solution?
« Last Edit: December 21, 2014, 07:54:06 pm by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

kpeters58

  • Sr. Member
  • ****
  • Posts: 267
Re: Win32 Printing
« Reply #1 on: December 21, 2014, 02:41:24 am »
maybe there's something in this thread for you...?

http://forum.lazarus.freepascal.org/index.php?topic=16495.0
Lazarus 2.0.4/FPC 3.0.4/Win 64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Win32 Printing
« Reply #2 on: December 21, 2014, 01:37:14 pm »
Code: [Select]
// uses Printers;
var
  Scale :LongInt;
begin
  with Printer do
    begin
      BeginDoc;
      Scale := Min(
        Printer.PageWidth div Image1.Picture.Bitmap.Width,
        Printer.PageHeight div Image1.Picture.Bitmap.Height);

      Printer.Canvas.StretchDraw(
        Rect(0, 0, Image1.Picture.Bitmap.Width*Scale, Image1.Picture.Bitmap.Height*Scale),
        Image1.Picture.Bitmap);

      EndDoc;
    end;
end;     

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: Win32 Printing
« Reply #3 on: December 21, 2014, 07:15:18 pm »
Thank you typo. I used your code (plus the Math unit) but still had a problem.  When executing BeginDoc, it bombed on the 2nd line of code in Printers:
  In the CheckPrinting function it stumbles on

    if Printing<>Value then   

It seems to me that Printer needs to be instantiated. It is still = nil.

So I added the Printer4Lazarus package [Printer gets instantiated there]and then ran. Now I'm back to the same error message. Here's the error I always get:



« Last Edit: December 21, 2014, 07:24:25 pm by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Win32 Printing
« Reply #4 on: December 21, 2014, 07:24:02 pm »
Try this:

Code: [Select]
{...}
MyPrinter := Printer;
with MyPrinter do
{...}

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: Win32 Printing
« Reply #5 on: December 21, 2014, 07:29:26 pm »
Nope - Same Debugger Error.  :(
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Win32 Printing
« Reply #6 on: December 21, 2014, 07:36:17 pm »
Well, I can run this code on my system,

Lazarus 1.2.6 r46529 FPC 2.6.4 i386-win32-win32/win64

Windows7 32bit

and I use PDFCreator for printing. It asks me for a document title and I need to provide it in order to print. Maybe it is your problem.

No errors here.
« Last Edit: December 21, 2014, 07:48:20 pm by typo »

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: Win32 Printing
« Reply #7 on: December 21, 2014, 07:53:33 pm »
I changed my Default printer from my Dell Laser to CutePDF and it worked!!! Like your PDFCreator, CutePDF creates a PDF file which I have to name. I was hoping to print directly on the printer but this is certainly better than nothing. Thank you.
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: [partially solved] Win32 Printing
« Reply #8 on: December 21, 2014, 08:21:30 pm »
When my Dell Color Laser is the default printer, the program crashes at:

file: winprinters.inc
function TWinPrinter.UpdateDevMode(APrinterIndex:Integer): boolean;
line: 260

    PDev.DevModeSize := DocumentPropertiesW(0, FPrinterHandle, Pwidechar(UTF8Decode(PDev.Name)),
                        nil, nil, 0);

PDev.Name = 'Dell Color Laser'
fPrinterHandle = 3035636

Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: [partially solved] Win32 Printing
« Reply #9 on: December 21, 2014, 08:26:03 pm »
You could try to set printer title inside the procedure:

Code: [Select]
Printer.Title := SomeString;

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: [partially solved] Win32 Printing
« Reply #10 on: December 21, 2014, 08:30:55 pm »
I tried that - didn't work.

So then I set the default printer to my wife's printer - in another room. IT WORKED!! That's a Samsung B/W Laser printer. The image printed directly without having to save to a file.

The problem seems to occur only when the Dell Color Laser is my default printer. WOW!!
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: [partially solved] Win32 Printing
« Reply #11 on: December 21, 2014, 08:44:55 pm »
Maybe lack of SEH (Structured Exception Handling) support for FPC 2.6.4 is manifesting in this situation. You might want to check out if FPC trunk solves this. Use fpcup (https://bitbucket.org/reiniero/fpcup/downloads) with this flag  :-dTEST_WIN32_SEH

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: [partially solved] Win32 Printing
« Reply #12 on: December 21, 2014, 09:02:35 pm »
I'm new to Lazarus and I'm not quite sure what you're asking. I downloaded fpcup.exe and ran it. I don't know how to set any flags -dTEST_WIN32_SEH.  When the Dell Lazer is the default printer, it still crashes. Cyrax, please point me to some more instructions so I can follow up on your suggestion.
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: [partially solved] Win32 Printing
« Reply #13 on: December 22, 2014, 12:53:25 am »
See attached settings file for fpcup. Save it to same location where fpcup is and rename it to fpc_win32_trunk.ini

Then open up command prompt into that location where you did save fpcup program and type :
Code: [Select]
fpcup.exe --inifile=fpc_win32_trunk.ini --inisection=fpc_trunk

Wait a while when fpcup fetches and compiles trunk version of FPC. Then run Lazarus and go to Tools->Options->Environment and put full path of compiled FPC trunk here, in text box "Compiler Executable" and "FPC source directory". After that rebuild whole Lazarus by going Tools->"Build Lazarus by profile ..."

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: [partially solved] Win32 Printing
« Reply #14 on: December 22, 2014, 01:21:12 am »
It seems strange that inisection=fpc_trunk.ini
when I just added a file called fpc_win32_trunk.ini
But I did what you wrote. The output from the compand line program was about 200-250 lines long and ended with:
Share and enjoy!
fpcup: info: 12/21/2014 16:01:03 fpcup finished.

Where do I find the "full path of compiled FPC trunk"? Is that the same as my lazarus exe which is just C:\lazarus
or is it something like
C:\lazarus\fpc\2.6.4\bin\i386-win32
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018