Fl_Printer and multiple pages

26 views
Skip to first unread message

Jeffrey Ellis

unread,
Nov 2, 2021, 11:55:20 AM11/2/21
to fltk.general
1.3.7 documentation says that the argument to start_job is the number of pages to print, and you can pass 0 if you don't know. However when I pass 0, start_job returns a non-zero value indicating an error, and the printer dialog never opens. Am I doing something wrong? Should I instead just pass a large page number and end before that number is reached?

Also, does anybody know of a good code example for how to print multiple pages?

Thanks in advance.

Albrecht Schlosser

unread,
Nov 2, 2021, 12:13:11 PM11/2/21
to fltkg...@googlegroups.com
On 11/2/21 4:55 PM Jeffrey Ellis wrote:
> 1.3.7 documentation says that the argument to start_job is the number
> of pages to print, and you can pass 0 if you don't know. However when
> I pass 0, start_job returns a non-zero value indicating an error, and
> the printer dialog never opens. Am I doing something wrong? Should I
> instead just pass a large page number and end before that number is
> reached?

I can't answer this question but I would trust the docs. If you get an
error this may be caused by something else. Does it work if you pass a
higher number? Did you try this?

> Also, does anybody know of a good code example for how to print
> multiple pages?

Just recently Manolo posted an example in this thread:
https://groups.google.com/g/fltkgeneral/c/xNJasYuP21U

In this reply:
https://groups.google.com/g/fltkgeneral/c/xNJasYuP21U/m/uVs3YFCABwAJ he
shows the example code, but for 1.4 current (Git) and some of this may
have changed since 1.3.7 (he committed a change). Maybe you can try FLTK
1.4.0. There are weekly snapshots you can download if you can't use Git
but the latest commit will obviously be available in the next snapshot
on Friday (Nov 5).

Philip Rose

unread,
Nov 2, 2021, 12:20:29 PM11/2/21
to fltkg...@googlegroups.com

 

From: Jeffrey Ellis
Sent: 02 November 2021 15:55
To: fltk.general
Subject: [fltk.general] Fl_Printer and multiple pages

 

1.3.7 documentation says that the argument to start_job is the number of pages to print, and you can pass 0 if you don't know. However when I pass 0, start_job returns a non-zero value indicating an error, and the printer dialog never opens. Am I doing something wrong? Should I instead just pass a large page number and end before that number is reached?

 

Hi Jeffrey,

 

I call start_job with:

 

bool printer::start_printer(int& from_page, int& to_page) {

                char* error_message = new char[256];;

                memset(error_message, 0, 256);

                char* message = new char[266];

                bool result;

                // Start the job with unknown number of pages - exit if cancelled

                switch (start_job(0, &from_page, &to_page, &error_message)) {

 

Also, does anybody know of a good code example for how to print multiple pages?

 

I have an example but it’s not simple:

 

I attach the code. It prints my database in two ways – a table and a set of labels. It’s reasonably well commented. It shows how I paginate.

 

Regards Phil.

 

 

printer.cpp

Jeffrey Ellis

unread,
Nov 2, 2021, 12:22:54 PM11/2/21
to fltk.general
If I pass it 1, it works. If I pass it 0, it does not.  Here is my code:

Fl_Printer* pPrinter = new Fl_Printer();
if (!pPrinter->start_job(0)) {
   pPrinter->start_page();
   ...
}
else {
   printf( "start_job returned non-zero\n" ); fflush( stdout );
}

Returns non-zero whenever I pass 0 as the page count.

Jeffrey Ellis

unread,
Nov 2, 2021, 12:24:27 PM11/2/21
to fltk.general
Thank you for the code example.

Jeffrey Ellis

unread,
Nov 2, 2021, 12:55:47 PM11/2/21
to fltk.general
I think I figured it out. 

TLDR: the page count is nothing more than the maximum of the page range that the user can select from the printer dialog when selecting a range of pages to print. There should be no harm in just making this something high like 100.

Longer version...

Fl_Printer::start_job redirects the call to Fl_System_Printer::start_job (in Fl_GDI_Printer.cxx).  This method makes a call to the MS-Windows PrintDlg method which apparently is returning an error, since the dialog never opens. Since the struct provided to PrintDlg has min page (nMinPage) set to 1 and max page (nMaxPage) set to my provided page count (which is 0), I can only surmise that PrintDlg does not handle this situation. A bit of Googling reveals that the nMaxPage element of the struct is only used to specify the maximum page in the page range the user can enter in the dialog. Experimenting confirms this to be the case. So don't interpret the "pagecount" arg to start_job as the number of pages you will be printing!

Manolo

unread,
Nov 3, 2021, 12:26:23 PM11/3/21
to fltk.general
Le mardi 2 novembre 2021 à 17:55:47 UTC+1, jeffe...@gmail.com a écrit :
I think I figured it out. 

TLDR: the page count is nothing more than the maximum of the page range that the user can select from the printer dialog when selecting a range of pages to print. There should be no harm in just making this something high like 100.

Longer version...

Fl_Printer::start_job redirects the call to Fl_System_Printer::start_job (in Fl_GDI_Printer.cxx).  This method makes a call to the MS-Windows PrintDlg method which apparently is returning an error, since the dialog never opens.

I've looked into this issue and believe Fl_Printer::start_job(0) should work OK under MSWindows.
That's because the first statement of Fl_System_Printer::start_job(int pagecount,…) is, since FLTK 1.3.4 :
  if (pagecount == 0) pagecount = 10000;
Thus, Fl_Printer::start_job(0) is the same as Fl_Printer::start_job(10000).

I've experimented with Windows 10, modifying line #604 of the test program test/device.cxx, replacing
    if (!p->start_job(1)) {
by
    if (!p->start_job(0)) {
and I see the printing operation runs well.

I've tried Windows 10 and Windows XP.

Jeffrey Ellis

unread,
Nov 3, 2021, 12:56:17 PM11/3/21
to fltk.general
Oops. As it turns out I am using 1.3.2 on this particular computer, so no wonder it worked differently for me.  Time to upgrade.  Thanks for the info.
Reply all
Reply to author
Forward
0 new messages