Printing to trays, DefaultPageSettings

Stimulsoft Reports.NET discussion
Post Reply
a.muehlberger
Posts: 6
Joined: Fri Jul 17, 2015 8:00 am

Printing to trays, DefaultPageSettings

Post by a.muehlberger »

Hi Stimulsoft,

we are currently trying to get a special printer (http://www.primerahealthcare.com/signat ... inter.html) work with our product. The printer has 4 Trays (Hopper #1 to #4) and a manual one. They hold plastic cassettes where tissue will be placed in.

We tried to print to the trays as we do it with laser printers - setting the RawKind-Property in the Printer Settings structure. Unfortunately, the printer does not react on that.

Therefore I did some investigation and found a code snippet for C# which sets the Paper Source in the QueryPageSettings event of the print document. When I set the paper source there, this special printer ignores the value.

Then i found out, that when setting die paper source via PrintDocument.DefaultPageSettings.PaperSource.RawKind, it works!

So my question now is - how do you set the PaperSource during StiReport.Print ? And furthermore, is there a possibility to set it via PrintDocument.DefaultPageSettings ?

To sum it up: this code does not work

Code: Select all

        void TestPrintResultinginDefaultHopper() {
            PrintDocument pd = new PrintDocument();
            pd.QueryPageSettings += pd_QueryPageSettings;
            pd.Print();
        }

        void pd_QueryPageSettings(object sender, QueryPageSettingsEventArgs e) {
            // change the tray to Hopper #4 (260) at that point does not work
            e.PageSettings.PaperSource.RawKind = 260;
        }
this one does:

Code: Select all

void TestPrintResultinginHopper_4() {
            PrintDocument pd = new PrintDocument();
            // changing the tray to Hopper #4 (260) at that point does work
            pd.DefaultPageSettings.PaperSource.RawKind = 260;
            pd.Print();
        }

Thanks a lot for you help!

-- muehlberger
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Printing to trays, DefaultPageSettings

Post by HighAley »

Hello.

We had several issues with printing and had found next solution.
We don't set RawKind directly. We get PaperSource from printer collection and look for the name of Paper Source and take the whole object.

Code: Select all

foreach (PaperSource paperSource in e.PageSettings.PrinterSettings.PaperSources)
{
    if (paperSource.SourceName == page.PaperSourceOfFirstPage)
    {
        e.PageSettings.PaperSource = paperSource;
        break;
    }
}
If you set the DefaultPageSettings, you could get a error with multithreading. When you set default settings for one printer in one thread and in another print the report is printing on other printer.

Thank you.
a.muehlberger
Posts: 6
Joined: Fri Jul 17, 2015 8:00 am

Re: Printing to trays, DefaultPageSettings

Post by a.muehlberger »

Thanks for your reply;

I tested your code in the eventhandler of PrintDocument.QueryPageSettings - unfortunately, it didn't work. :-( Looks like the Driver does not accept changes at that Point. Could you maybe verify that by installing a Printer of that Kind, printing to a null device; when stopping the print Queue, I found the used tray in the properties Dialog.

I did not get the Point on your Statement about the Printer Defaults. I don't want to Change the Printer Defaults of the Printer, but instead the Default page Settings of the PrintDocument.

-- muehlberger
a.muehlberger
Posts: 6
Joined: Fri Jul 17, 2015 8:00 am

Re: Printing to trays, DefaultPageSettings

Post by a.muehlberger »

oh - one Thing I forgot to mention. Of course we first tried printing from Stimulsoft, but since it did not use the correct tray, i tried figuring out the api behind.

Printing from the designer's preview also does not set the trays as expected ; with our HP LaserJet e.g. it works like a charme (both Designer and our app using Stimul; my simple api example).

-- muehlberger
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Printing to trays, DefaultPageSettings

Post by HighAley »

Hello.

Please, try to use one of next ways in the QueryPageSettings event:

Code: Select all

Stimulsoft.Report.Print.StiPrintProvider.SetPaperSource = true;
Stimulsoft.Report.Print.StiPrintProvider.QueryPageSettings += new Stimulsoft.Report.Print.StiQueryPageSettingsEventHandler(StiPrintProvider_QueryPageSettings);

void StiPrintProvider_QueryPageSettings(object sender, Stimulsoft.Report.Print.StiQueryPageSettingsEventArgs e)
        {
            e.PaperSource = new System.Drawing.Printing.PaperSource() { RawKind = 260 };
            // or try
            e.PageSettings.PrinterSettings.DefaultPageSettings.PaperSource = new System.Drawing.Printing.PaperSource() { RawKind = 260 };
        }
Thank you.
a.muehlberger
Posts: 6
Joined: Fri Jul 17, 2015 8:00 am

Re: Printing to trays, DefaultPageSettings

Post by a.muehlberger »

Hi HighAley,

thanks for the provided sample. At first, I didn't work either.

I asked a collegue of mine to do some tests on his machine - and there it worked, even with the original code! After some time, we found out, that he runs his testproject as an x86 program!

So the result is:
running our program as x86 on a x64 machine used the correct tray
running our program as x64 on a x64 machine looses the tray and always uses the Manual tray

Since all other Printers with trays work correct both on x86 and x64, I assume it's an error in the Printer Driver.

Thanks for your help!

-- muehlberger
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Printing to trays, DefaultPageSettings

Post by HighAley »

Hello.

Yes, if you use x64 application, please, try to install x64 printer drivers.

Thank you.
a.muehlberger
Posts: 6
Joined: Fri Jul 17, 2015 8:00 am

Re: Printing to trays, DefaultPageSettings

Post by a.muehlberger »

Of course it's already a x64 driver .

The manufacturer of the Printer is investigating the issue.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Printing to trays, DefaultPageSettings

Post by HighAley »

Hello.

Let us know if we can can do something to help.

Thank you.
Post Reply