Printing does not work under Linux

Linux specific forum
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Printing does not work under Linux

Post by Hexagon »

I made a small invoicing application for Linux in a long time ago, where printing the invoices are one of the major functions.
The latest version was compiled with PureBasic 4.10, about 15 years ago already :o

This program worked for several years under Ubuntu, then the printing failed to work properly. I do not know when. Which year, or which version of Ubuntu I cannot remember.
The error: Only the top-left of the image was printed in huge size on the printer. Different printers, or even printing to PDF or SVG all gave the same results. The user "solved" this problem by using a version compiled for Windows, executed in Ubuntu using Wine :?

Wine is not ideal, so lately I have been playing with different Ubuntu installs, but they all gave the same results on the old binaries.
I noticed the Linux printer lib changed to GtkPrint instead of GnomePrint in PureBasic 5.40. So I tried this version with the old source code. For some odd reason, the very same thing happened there. Trying the PureBasic printer example, the same thing happened there as well. Only the top-left part of the "image" gets printed in huge size, compared to the same program running under Windows.

Tried PureBasic 6.00 as well, on different computers, with identical results. Even under fresh installs of Ubuntu 20.04 and 22.04, the PureBasic Printer.pb example does not work properly.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Printer example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

If PrintRequester()

  If StartPrinting("PureBasic Test")
  
    LoadFont(0, "Arial", 30)
    LoadFont(1, "Arial", 100)
    If StartDrawing(PrinterOutput())
          Debug "OutputHeight: " + OutputHeight()
          Debug "OutputWidth: " + OutputWidth()    
          Debug "PrintHeight: " + PrinterPageHeight()
          Debug "PrintWidth:  " + PrinterPageWidth()
      BackColor(RGB(255, 255, 255)) ; Uses white as back color, usuful when printing on a white sheet
      FrontColor(RGB(0, 0, 0)) ; Use black for standard text color
      
      Box(0, 0, 595, 842, RGB(255, 0, 0)) ; Draw a red box, becoming the outher border of the printed page.
      Box(1, 1, 593, 840, RGB(0, 0, 255)) ; Draw a blue box.
      Box(3, 3, 589, 836, RGB(255, 255, 255)) ; Draw a white box not to waste printer ink. Becoming the center of the printed page.
      
      DrawingFont(FontID(0))
      Debug "TextWidht:  " + TextWidth("PureBasic Printer Test")
      Debug "TextHeight: " + TextHeight("PureBasic Printer Test")
      DrawText(100, 100, "PureBasic Printer Test")
      
      DrawingFont(FontID(1))
      Debug "TextWidht:  " + TextWidth("PureBasic Printer Test 2")
      Debug "TextHeight: " + TextHeight("PureBasic Printer Test 2")
      DrawText(100, 400, "PureBasic Printer Test 2")
    
      If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
        DrawImage(ImageID(0), 200, 600)
      Else
        MessageRequester("Error","Can't load the image")
      EndIf
                          
      StopDrawing()
      MessageRequester("Completed","Printing completed.")
    EndIf
    
    StopPrinting()
  EndIf
EndIf
After playing a bit with the Printer.db example, I noticed that the top 595x842 pixels are printed. Always this size, independent of selected printer and resolution. PrinterPageHeight() and PrinterPageWidth() both change when different printers are selected, as well as when I choose 300DPI, 600DPI, or 1200DPI. The printed area always remain being the top left 595*842 pixels.

As I really doubt there are some PureBasic bugs lasting for 15 years without being addressed, I hope anyone can please let me know what I am doing wrong?
User avatar
Janni
Enthusiast
Enthusiast
Posts: 127
Joined: Mon Feb 21, 2022 5:58 pm
Location: Norway

Re: Printing does not work under Linux

Post by Janni »

I can't help much besides I was tempted to try using Linux Mint 20.3 and PB6.

Running the printer example file i get:
[17:00:34] [WARNING] Line: 11
[17:00:34] [WARNING] Gtk (CRITICAL): gtk_notebook_get_tab_label: assertion 'list != NULL' failed

Line 11 is the

Code: Select all

If PrintRequester()
On the output I got this:
https://ibb.co/0YW3mtT
Spec: Linux Mint 20.3 Cinnamon, i7-3770K, 16GB RAM, RTX 2070 Super
User avatar
mk-soft
Always Here
Always Here
Posts: 6314
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Printing does not work under Linux

Post by mk-soft »

On macOS the same as Windows ... No clip output
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

Janni wrote: Tue Dec 27, 2022 5:10 pm I can't help much besides I was tempted to try using Linux Mint 20.3 and PB6.

On the output I got this:
https://ibb.co/0YW3mtT
You did help, since you proved that you got the exact same results as me. Only the 595*842pixel image.
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

Thanks for testing and sharing!
Exact same results as me, for both Linux and Windows. I do get the same even for very old Ubuntu versions and PureBasic 4.10/4.20 dating 15 years back in time.
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

mk-soft wrote: Tue Dec 27, 2022 7:41 pm On macOS the same as Windows ... No clip output
Thanks for checking. Then we know it only applies to Linux. And to other people than just me.

Thanks for kind testing and prompt feedback everyone!
Any ideas how to solve this issue?
TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Printing does not work under Linux

Post by TassyJim »

Try using the qt subsystem. That 'fixed it' for me.

There will be other layout issues to fix if you change subsystems...

Jim
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

TassyJim wrote: Tue Dec 27, 2022 10:01 pm Try using the qt subsystem. That 'fixed it' for me.

There will be other layout issues to fix if you change subsystems...

Jim
OK, I will look into this, thanks Jim.
Since others had this problem, I have a feeling this really can be a PureBasic bug, not only a major mistake by myself. Did anyone report it?
User avatar
deeproot
Enthusiast
Enthusiast
Posts: 284
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: Printing does not work under Linux

Post by deeproot »

Hexagon wrote: Wed Dec 28, 2022 10:46 am Since others had this problem, I have a feeling this really can be a PureBasic bug, not only a major mistake by myself. Did anyone report it?
It appears I have the same problem :( After reading this thread I (re)tested my Linux program and got results similar to above. Weird thing is I seem to remember testing my report printing from Linux about year or so ago and thought it was working - but might be my memory playing tricks!!

I see that juergenkulow has now logged this a bug. Thanks to both of you for raising this issue. The Linux version of my application is in long-term Beta status and I haven't had any user complaints yet but it could be very important in future. The print routines are almost identical to the Windows code written over 10 years ago which works fine.
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

Thanks for all your feedback. PureBasic forums indeed seem to have many helpful users :)
Since it seems to be a PureBasic bug, I will do some testing on old software and old Linux distributions, to see where it all went wrong.

As a side-note, I tried the "new" vector drawing feature StartVectorDrawing() with the exact same results. Whatever method or type of printer I use, I am limited to 595 x 842 pixel resolution when printing under Linux.
tored
User
User
Posts: 90
Joined: Wed Feb 16, 2022 12:47 pm
Location: Sweden

Re: Printing does not work under Linux

Post by tored »

This example is not entirely correct, the last MessageRequester says "Printing completed." when it actually isn't, printing is completed after StopPrinting() call, thus if you are like me and missed that MessageRequester becuase it wasn't focused and then checked the PDF output it will be empty until you click it.
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

tored wrote: Thu Dec 29, 2022 1:28 pm This example is not entirely correct, the last MessageRequester says "Printing completed." when it actually isn't, printing is completed after StopPrinting() call, thus if you are like me and missed that MessageRequester becuase it wasn't focused and then checked the PDF output it will be empty until you click it.
Yes, you are correct. My mistake to move the MessageRequester without updating the text. Updated version here:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Printer example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

If PrintRequester()

  If StartPrinting("PureBasic Test")
  
    LoadFont(0, "Arial", 30)
    LoadFont(1, "Arial", 100)
    If StartDrawing(PrinterOutput())
      OutputHeight.i = OutputHeight()
      OutputWidth.i = OutputWidth()    
      PrintHeight.i = PrinterPageHeight()
      PrintWidth.i = PrinterPageWidth()

      BackColor(RGB(255, 255, 255)) ; Uses white as back color, usuful when printing on a white sheet
      FrontColor(RGB(0, 0, 0)) ; Use black for standard text color
      
      Box(0, 0, 595, 842, RGB(255, 0, 0)) ; Draw a red box, becoming the outher border of the printed page.
      Box(1, 1, 593, 840, RGB(0, 0, 255)) ; Draw a blue box.
      Box(3, 3, 589, 836, RGB(255, 255, 255)) ; Draw a white box not to waste printer ink. Becoming the center of the printed page.
      
      DrawingFont(FontID(0))
      DrawText(100, 100, "PureBasic Printer Test")
      
      DrawingFont(FontID(1))
      DrawText(100, 400, "PureBasic Printer Test 2")
    
      If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
        DrawImage(ImageID(0), 200, 600)
      Else
        MessageRequester("Error","Can't load the image")
      EndIf
                          
      StopDrawing()
      MessageRequester("Drawing Completed","Drawing completed, click OK to print." + #LF$ + #LF$ + "Program compiled With PureBasic version " + #PB_Compiler_Version + #LF$ + "OutputHeight() = " + OutputHeight.i + #LF$ + "OutputWidth() = " + OutputWidth.i + #LF$ + "PrintHeight() = " + PrintHeight.i + #LF$ + "PrintWidth() = " + PrintWidth.i , #PB_MessageRequester_Ok )
    EndIf
    
    StopPrinting()
  EndIf
EndIf
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

Re: Printing does not work under Linux

Post by Hexagon »

I updated the code to make it work with PureBasic versions older than 5.10, since they do not support autocasting.

Code: Select all

If PrintRequester()

  If StartPrinting("PureBasic Test")
  
    LoadFont(0, "Arial", 30)
    LoadFont(1, "Arial", 100)
    If StartDrawing(PrinterOutput())
      OutputHeight$ = "OutputHeight() = " + Str(OutputHeight()) + #LF$
      OutputWidth$ = "OutputWidth() = " + Str(OutputWidth()) + #LF$
      PrintHeight$ = "PrintHeight() = " + Str(PrinterPageHeight()) + #LF$
      PrintWidth$ = "PrintWidth() = " + Str(PrinterPageWidth()) + #LF$
      PBVersion$="Program compiled With PureBasic version " + Str(#PB_Compiler_Version) + #LF$

      BackColor(RGB(255, 255, 255)) ; Uses white as back color, usuful when printing on a white sheet
      FrontColor(RGB(0, 0, 0)) ; Use black for standard text color
      
      Box(0, 0, 595, 842, RGB(255, 0, 0)) ; Draw a red box, becoming the outher border of the printed page.
      Box(1, 1, 593, 840, RGB(0, 0, 255)) ; Draw a blue box.
      Box(3, 3, 589, 836, RGB(255, 255, 255)) ; Draw a white box not to waste printer ink. Becoming the center of the printed page.
      
      DrawingFont(FontID(0))
      DrawText(100, 100, "PureBasic Printer Test")
      
      DrawingFont(FontID(1))
      DrawText(100, 400, "PureBasic Printer Test 2")
    
      If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
        DrawImage(ImageID(0), 200, 600)
      Else
        MessageRequester("Error","Can't load the image")
      EndIf
                          
      StopDrawing()
      MessageRequester("Drawing Completed","Drawing completed, click OK to print." + #LF$ + #LF$ + PBVersion$ + OutputHeight$ + OutputWidth$ + PrintHeight$ + PrintWidth$ , #PB_MessageRequester_Ok )
    EndIf
    
    StopPrinting()
  EndIf
EndIf
Post Reply