Page 1 of 1

Setting Custom PaperSize

Posted: Mon Mar 12, 2012 6:50 am
by Andreas Tastler
Hi all

We use Stimulsoft Reports 2010.3
Today we set specific paper sources whit this code:

Code: Select all

StiPrintProvider.SetPaperSource = false;
PaperSource paperSource = null;

foreach(StiPage currentPage in report.RenderedPages)
{
   // here comes some code that evaluates the paperSource Object for the currentPage
  currentPage.PaperSourceOfFirstPage = paperSource.SourceName;
  currentPage.PaperSourceOfOtherPages = paperSource.SourceName;
}
Now we have customers they use custom PaperSizes to map paper sources for different printers to a specific paper type / form.
Unfortunately the StiPage only provides PaperSize that takes a PaperKind enum.
The PaperSize Class provides a property RawKind, which takes the defined custom paper type.

Is it possible to set the PaperSize to the page so the correct PageSize object will be passed to the printer driver?

Thank you.
Andreas

I see

Setting Custom PaperSize

Posted: Tue Mar 13, 2012 7:32 am
by HighAley
Hello, Andreas.
atastler wrote:Now we have customers they use custom PaperSizes to map paper sources for different printers to a specific paper type / form.
Unfortunately the StiPage only provides PaperSize that takes a PaperKind enum.
The PaperSize Class provides a property RawKind, which takes the defined custom paper type.

Is it possible to set the PaperSize to the page so the correct PageSize object will be passed to the printer driver?
You should set the PaperSize property to Custom and set the PaperHeight and the PaperWidth properties.

Thank you.

Setting Custom PaperSize

Posted: Thu Mar 15, 2012 3:51 am
by Andreas Tastler
Hi

I do not want to set the paper size. Both of the forms we want to set are A4 PaperSize. In this case the PaperType will be used as Form which will control the papertrays of different printers.
Imagine you have two different printers. Both of them have two paper trays. One is filled with white paper, one with paper thas has a header pre printed. Now you can define to paper types and configure the printers papertray to the correct papertype. In this case you dont have to set specific papertrays in report.
The class System.Drawing.Printing.PaperSize has a Kind and a RawKind property, but only the Kind property goes to the printer. I want to be able to give the RawKind-Property into the Settings of a StiPage.

Thank you
Andreas

Setting Custom PaperSize

Posted: Fri Mar 16, 2012 5:06 am
by Alex K.
Hello,

The System.Drawing.Printing.PaperSize.RawKind property has the following implementation:

Code: Select all

public int RawKind
{
    get
    {
        return (int) this.kind;
    }
    set
    {
        this.kind = (PaperKind) value;
    }
}

So RawKind and Kind property is equal.

Please clarify your problem in more details and why you need RawKind?

Thank you.

Setting Custom PaperSize

Posted: Mon Mar 19, 2012 4:23 am
by Andreas Tastler
Hi

System.Drawing.Printing.PaperSize holds the current PaperKind identifier in the private kind field. The Kind-Property is ReadOnly and returns always the enumeration item PaperKind.Custom for custom paper types (which has the int value 0).

Code: Select all

public PaperKind get_Kind()
{
    if (((this.kind <= PaperKind.PrcEnvelopeNumber10Rotated) && (this.kind != (PaperKind.C65Envelope | PaperKind.Standard10x14))) && (this.kind != (PaperKind.B4Envelope | PaperKind.Standard10x14)))
    {
        return this.kind;
    }
    return PaperKind.Custom;
}

In StiPrintProvider.OnQueryPageSettings method the PaperSize will be evaluated by the GetPaperSize method.
The GetPaperSize method then compares the Kind-Property (which is always 0 for custom papertypes) with the effective int value of the custom paper type stored in the PaperSize Property of StiPage. So the custom paper type will never be found.

Code: Select all

private object GetPaperSize(StiPage page, System.Drawing.Printing.QueryPageSettingsEventArgs e)
    {
      if (PaperSizeForUsing != null) return PaperSizeForUsing;

      if (paperSizesStore == null) paperSizesStore = e.PageSettings.PrinterSettings.PaperSizes;

      if (page.PaperSize != PaperKind.Custom)
      {
        foreach (PaperSize ps in paperSizesStore)
        {
          if (ps.Kind == page.PaperSize) return ps;
        }
      }

Also, paper types selected in PrintDialog will always be overwritten by the PageSize object evaluated in the GetPaperSize method.

I hope I explained my problem clear enough. Let me know if there are any questions.
Thank you
Andreas

Setting Custom PaperSize

Posted: Thu Mar 22, 2012 2:53 am
by HighAley
Hello.

Sorry for the delay with response. We need some additional time to prepare the answer for you.

Thank you.

Setting Custom PaperSize

Posted: Thu Mar 29, 2012 9:24 am
by HighAley
Hello.
atastler wrote:The GetPaperSize method then compares the Kind-Property (which is always 0 for custom papertypes) with the effective int value of the custom paper type stored in the PaperSize Property of StiPage. So the custom paper type will never be found.
If you set the custom paper size then the PaperSize property will set to PaperKind.Custom and condition will work right.
The paper size could be set with GetPaperSize(e, page) method which wasn't mentioned in your code.
atastler wrote:Also, paper types selected in PrintDialog will always be overwritten by the PageSize object evaluated in the GetPaperSize method.
It should be so by design. The page size can be set in the Page settings. And there is a Page Size button in the Preview where you could scale the page size to needed size and print it.

Thank you.

Setting Custom PaperSize

Posted: Mon Apr 02, 2012 2:49 am
by Andreas Tastler
Hello Aleksey

Now I start to understand. After studying your answers and the GetPaperSize(e, page) method, I think the StiPage.PaperSize property is used only to specify page dimensions. Also when you iterate over the PageSize objects in the paperSizesStore, the first PaperSize which matches the dimensions of the page will be returned. But this is not correct. It is possible to define more than one PaperType (PaperSize) with the same dimensions on the same print server. Different paper trays will be specified for each paper type. If you just return the first matching PaperSize, this functionality will be lost.
A possible solution would be a RawKind-Property in the StiPage which could be used to identifiy the correct PaperSize object from the paperSizesStore.

Code: Select all

PaperSize custom = null;
foreach (PaperSize ps in paperSizesStore)
{
  /*
  * 
  * if (page.RawKind == ps.RawKind) return ps;
  * 
  */
  // if there are more than one PaperSizes with the same dimension, the returned ps coult be the wrong one
  if ((ps.Width == pageWidth && ps.Height == pageHeight) ||
    (ps.Height == pageWidth && ps.Width == pageHeight)) return ps;
  
  if (ps.Kind == PaperKind.Custom)
  {
    custom = new PaperSize("Custom", originPageWidth, originPageHeight);
  }
}
Thank you.
Andreas

Setting Custom PaperSize

Posted: Mon Apr 02, 2012 8:57 am
by Alex K.
Hello,

We understand the idea of your question.
Unfortunately, we do not plan to make this enhancement, as your request on this subject is the only one.
As a workaround, you can try to solve your problem in the following way:
You can subscribe to a static event

Code: Select all

StiPrintProvider.QueryPageSettings(StiReport report, StiQueryPageSettingsEventArgs e)
and in the event change e.PaperSize to the value you need.
To determine the currently printed page, use thereport.CurrentPrintPage property.

Thank you.