bugGNU Octave - Bugs: bug #63813, Can't print plot directly to...

 
 

bug #63813: Can't print plot directly to printer

Submitter:  None
Submitted:  Fri 17 Feb 2023 08:12:45 AM UTC
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 7.3.0
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

( Jump to the original submission )

Sun 26 Feb 2023 07:44:17 PM UTC, comment #18: 

@paul:

>> is there a forum where these noobie types of questions would be more appropriate?


I'd suggest you open a new discussion thread on discourse to get help from a broader set of contributors:

https://octave.discourse.group/

Pantxo Diribarne <pantxo>
Project Member
Sun 26 Feb 2023 10:14:36 AM UTC, comment #17: 

RE: @pantxo,

comment #15: This suggestion works, however when I print it the font is small. Is there a way to configure this using this solution?

To give a little context of what I'm working on and what I'm trying to achieve: I'm building upon and rewriting many parts of a program that was written in MATLAB. One feature I want is displaying all relevant info from several different functions. I'm currently using classes/methods to store the data to be printed on a summary page later. I'm trying to format this summary page to be as readable and refined as possible. I want the program to be very easy for the user to use and get a summary with a click of a button. And then to be printed or saved. Any suggestions on formatting and text manipulation would be appreciated. (I'm not sure if its appropriate to ask for suggestions in this forum, if not is there a forum where these noobie types of questions would be more appropriate?) Thank you




Paul <anon1337>
Wed 22 Feb 2023 10:11:00 PM UTC, comment #16: 

I attached a patch that make Octave use Qt rather than "lpr" for printing when using svgconvert.

(file #54389)

Pantxo Diribarne <pantxo>
Project Member
Sun 19 Feb 2023 07:06:21 PM UTC, comment #15: 

@paul:

  • comment #7 : >> Could this just be an administrative issue on my side?

 If you can have `lpr` be made available by your admin, then `print -dpsc` should work.

  • comment #9: If you only need to print text then another workaround is to build a text file, open it in the GUI editor and use the print menu from there. Something like:



tmpfname = tempname ();
fid = fopen (tmpfname, "w+");
text_data = "header\n1\n2\n3\n";
fprintf (fid, "%s", text_data)
fclose (fid)
edit (tmpfname)


Pantxo Diribarne <pantxo>
Project Member
Sun 19 Feb 2023 06:49:13 PM UTC, comment #14: 

So it looks like `lpr` is not present by default on recent versions of Windows (see [1]) but there doesn't seem to be an equivalent command line utility (see [2]). So we definitely need another approach. I thus marked this bug confirmed but restricted to Windows.

>> I don't know what is required to make it work for printing the contents of the figure window.


AFAICS Qt only supports printing using their QPainter system (not printing an arbitrary PDF/PS file as `lpr` does), so the easiest way I can see to print figures would be to use octave-svgconvert which already has a QPrinter based class for printing to PDF.



[1] https://superuser.com/questions/420409/print-using-lpr-command-in-64-bit-windows
[2] https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/print-command-reference

Pantxo Diribarne <pantxo>
Project Member
Sat 18 Feb 2023 08:03:58 AM UTC, comment #13: 

RE: @jwe,
The closest thing that I have found to your suggestion is on this page - https://wiki.octave.org/Uicontrols .
Going back to your suggestion though, do you have any pointers on how I would go about calling C++ code, and building a print menu that way? Can you give an example of what that would look like?

Paul <anon1337>
Sat 18 Feb 2023 05:30:53 AM UTC, comment #12: 

I assume that we could use this widget in the GUI:

https://doc.qt.io/qt-5/qprintdialog.html

We are already using it for the editor.  I don't know what is required to make it work for printing the contents of the figure window.

John W. Eaton <jwe>
Project Administrator
Sat 18 Feb 2023 05:12:08 AM UTC, comment #11: 

I'm basically looking for any solution where I can print the table in comment #9. In such a way that the system 'print menu' pops up with available printers/pdf/etc. The way that the code is currently written the table pops up in a Figure window. I still have TODO: https://wiki.archlinux.org/title/CUPS/Printer_sharing which might solve the issue. Here is the button to 'print':

https://file.savannah.gnu.org/file/Screenshot_2023-02-17_21-04-40.png?file_id=54376" />

Paul <anon1337>
Sat 18 Feb 2023 04:34:42 AM UTC, comment #10: 

wait, so are you trying to print something in a Figure window, or text from the command window?  a 'plot' is specifically a graphic appearing in a figure window.

Nicholas Jankowski <nrjank>
Project Member
Sat 18 Feb 2023 12:51:23 AM UTC, comment #9: 

Also the "plot" I am trying to print is more of a table, as seen in the attached screen shot. Is there a separate function to use for table, or even simple text output? Or everything treated as a plot?

OP

https://file.savannah.gnu.org/file/Screenshot@2023-02-17@161541.png?file_id=54374" />

Paul <anon1337>
Sat 18 Feb 2023 12:24:12 AM UTC, comment #8: 

that would be a reasonable next thing to check

Nicholas Jankowski <nrjank>
Project Member
Fri 17 Feb 2023 11:01:32 PM UTC, comment #7: 

Hi this is OP

I can't get print function to work on Manjaro (I don't have a printer connected to my Linux machine nor have I ever needed to) or Windows 10. But for Marjaro it doesn't matter because the software will be used on Windows based machines. I will add that I am using a computer where I don't have Administrative privilege's and I looked online and there was an option to enable lpr printing. I went to enable lpr printing but I did not have the privilege's to do so. Could this just be an administrative issue on my side?

P

Anonymous
Fri 17 Feb 2023 09:39:53 PM UTC, comment #6: 

I think from comment #2 the OP says he can get this to work in Manjaro, just not in windows.

is this the same problem discussed over at https://octave.discourse.group/t/how-to-print-a-figure-plotted-in-octave-5-2-0/3900/7  ?

Nicholas Jankowski <nrjank>
Project Member
Fri 17 Feb 2023 09:08:40 PM UTC, comment #5: 

Sorry @nrjank, just saw your post.

Pantxo Diribarne <pantxo>
Project Member
Fri 17 Feb 2023 09:07:04 PM UTC, comment #4: 

I think there are two issues:

  • Running `print -dpsc` should send a postscript document to the default printer using the external "lpr" binary on linux. From the message in comment #0, I understand that Octave was unable to find "lpr". This is either because it is not installed by default on Manjaro (is it? what does `system ("which lpr")` return?) or because you are running Octave from a sandboxed environment (how did you install Octave?).
  • You seam to be expecting a regular print dialog showing all available printers and eventually a preview of the output, like in many other software. Unfortunately no such menu has ever been been implemented to my knowledge. You could file a feature request about implementing that.
Pantxo Diribarne <pantxo>
Project Member
Fri 17 Feb 2023 08:53:01 PM UTC, comment #3: 

Octave GUI does not currently have a Print menu option for the figure window when using qt (default) or fltk graphics. If you use the gnuplot graphics, there is a print button that brings up the Operating System's native print dialog. (just verified it works on Windows.)  I suspect this is just something inherited from gnuplot and not implemented by Octave itself.

I do recognize the utility of such a feature, Matlab does have Print/PrintPreview options in their figure Menu, but it's a separate issue from the original report about not even being able to print on Windows using the print commands at the command line.   It may provide a workaround in the meantime by switching to the (not really supported anymore) gnuplot toolkit with :

>> graphics_toolkit("gnuplot")


I did file a feature request for a Menu/button in the other toolkits over at bug #63814

Nicholas Jankowski <nrjank>
Project Member
Fri 17 Feb 2023 07:26:56 PM UTC, comment #2: 

TLDR: How to get the "print" menu when printing a plot in Windows 10 so the user can choose to print to a specified printer or to pdf? Without automatically saving the document(could get cluttered if it auto-saves). Getting the same error as comment #1.

I'm doing development on the program both on Windows 10 and on Linux (Manjaro). The priority is to get it to work seamlessly on Windows as this is the platform the software will be used on mainly. I also get this error on Windows also when I run the print command. Do you know any workarounds in Windows 10 to get the "print" pop up menu? I couldn't find any easy solution for this, and I'm hoping there is one. The other more complicated solution is to use the system() function to call a PowerShell then try to call the printer menu from there, but I at this point only found out how to print directly to the printer without the menu popping up with:
Get-Content -Path ./readme.txt | Out-Printer

Anonymous
Fri 17 Feb 2023 08:57:50 AM UTC, comment #1: 

On linux, lpr has been the default command line print utility for a while so Octave relies on it.
Doesn't your distro provide that utility ? Or maybe you are running Octave in a sandbox (snap, flatpak...) the system lpr is not accessible ?

Pantxo Diribarne <pantxo>
Project Member
Fri 17 Feb 2023 08:12:45 AM UTC, original submission:  

TL;DR: Can't print directly to printer getting this message: error: print: 'lpr' not found in PATH
error: called from
    print>lpr at line 1095 column 5
    _opengl_print_ at line 164 column 17
    print at line 771 column 16
    dismoor at line 445 column 9

CODE: see in attachment line 172

print -dpsc


I have a "print document" GUI button that when pressed should display the plot without saving it, and simultaneously open the default printer menu for the system (print to specified printer, or print to pdf) so that the user can specify where they want to print the document, or if they want to save it as a pdf.

One work around obviously would be to create a .pdf (saveas) then use open (doc.pdf) which works. But this is not the desired result.

I read a lot of the documentation ie 15.2.9 Printing and Saving Plots
but no luck. Is there a simple fix for this? Thank you.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #54389:  bug63813.patch added by pantxo (13KiB - text/x-patch)
file #54374:  Screenshot@2023-02-17@161541.png added by anon1337 (19KiB - image/png - output of "figure")
file #54368:  dismoor.m added by None (15KiB - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by anon1337 (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.

     

     

     

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-02-22 pantxo Attached File- Added bug63813.patch, #54389
    2023-02-19 pantxo StatusNeed Info Confirmed
        Operating SystemGNU/Linux Microsoft Windows
    2023-02-18 anon1337 Attached File- Added Screenshot_2023-02-17_21-04-40.png, #54376
    2023-02-18 anon1337 Attached File- Added Screenshot@2023-02-17@161541.png, #54374
    2023-02-17 pantxo Item GroupUnexpected Error or Warning None
    2023-02-17 nrjank Item GroupNone Unexpected Error or Warning
    2023-02-17 pantxo StatusNone Need Info
    2023-02-17 None Attached File- Added dismoor.m, #54368

    Back to the top

    Powered by Savane 3.11