Change papesize from code (Delphi)

I am trying to to change the height and width of the report page, selecting one of the supported sizes for the printer, I managed to get a list of the suported papers but I get only the papersize not the paper height or width individually, so, I tried selecting one of the papersizes on a combo and the passing that from Delphi to the report but the paper width and height do not change automatically as it says it does on the documentation.


do you know if it is a bug? because I do not have the personalized papersize selected and it doesn???t change width and height automatically.


if you know how to change the papersize from Delphi by code, could you show me?
I was trying to do something like this:


Page.PaperSize:= frxPrinters.Printer.PaperNameToNumber(ComboPapel.Items[ComboPapel.ItemIndex]);

Comments

  • PolomintPolomint Australia
    edited 8:45AM
    hirambambu wrote: »
    Page.PaperSize:= frxPrinters.Printer.PaperNameToNumber(ComboPapel.Items[ComboPapel.ItemIndex]);
    When you say this doesn't work, do you mean it has "no effect"? Or do you mean you get an error / exception?

    I am wondering for example how you define / derive the parameter <Page>.

    We have some reports where we allow the user to change between Portrait and Landscape modes, which might help you.

    In our Reports' Common Code
    Page := TfrxReportPage (Report.Pages [1]);
    
    where <Report> is the TfrxReport Component's name.

    We use <Page> to set the necessary TfrxReportPage Properties (Orientation, BottomMargin etc.).
      with Page do begin
        if Orientation <> Value then begin
          SaveBottom := BottomMargin;
          SaveLeft := LeftMargin;
          SaveRight := RightMargin;
          SaveTop := TopMargin;
          Orientation := Value;
          BottomMargin := SaveBottom;
          LeftMargin := SaveLeft;
          RightMargin := SaveRight;
          TopMargin := SaveTop;
        end;
      end;
    

    I believe you could use <Page> to set the PaperSize Property, or PaperHeight / PaperWidth. Reading those values in our test module, we get PaperSize=9 PaperHeight=297 PaperWidth=210 (for A4 Portrait).

    Note the <Index> of "1" in the <Page> assignment statement. Our Report designs have avoided multi-page definitions.

    If your reports contain more than one page definition you will need to consider iterating through of them.

    Hope this helps [img]style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> Cheers, Paul[/img]
  • edited 8:45AM
    Polomint wrote: »
    Polomint wrote: »
    Page.PaperSize:= frxPrinters.Printer.PaperNameToNumber(ComboPapel.Items[ComboPapel.ItemIndex]);
    When you say this doesn't work, do you mean it has "no effect"? Or do you mean you get an error / exception?

    I am wondering for example how you define / derive the parameter <Page>.

    We have some reports where we allow the user to change between Portrait and Landscape modes, which might help you.

    In our Reports' Common Code
    Page := TfrxReportPage (Report.Pages [1]);
    
    where <Report> is the TfrxReport Component's name.

    We use <Page> to set the necessary TfrxReportPage Properties (Orientation, BottomMargin etc.).
      with Page do begin
        if Orientation <> Value then begin
          SaveBottom := BottomMargin;
          SaveLeft := LeftMargin;
          SaveRight := RightMargin;
          SaveTop := TopMargin;
          Orientation := Value;
          BottomMargin := SaveBottom;
          LeftMargin := SaveLeft;
          RightMargin := SaveRight;
          TopMargin := SaveTop;
        end;
      end;
    

    I believe you could use <Page> to set the PaperSize Property, or PaperHeight / PaperWidth. Reading those values in our test module, we get PaperSize=9 PaperHeight=297 PaperWidth=210 (for A4 Portrait).

    Note the <Index> of "1" in the <Page> assignment statement. Our Report designs have avoided multi-page definitions.

    If your reports contain more than one page definition you will need to consider iterating through of them.

    Hope this helps [img]style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> Cheers, Paul[/img]


    Hi Paul, first, thank you so much for replying.
    now, im using: Page:= rfxReport.FindObject('Page1') as TfrxReportPage; in order to get the page from the report, and it does change the integer value of the papersize in the report but it has no effect, and I read on the fasReports documentation that changing the papersize should change automatically the width and height of the page, that???s what I want to do but it is having no effect. my report is single page and I use it for printing labels in a thermal brother printer.


    if you know how to fix that problem I would be pretty thankful, thanks in advance and for replying

    Hiram.
  • edited October 2020

    It's work!


    case ATicketSize of

      ttt58mm: TFrxReportPage(AReport.Pages[1]).PaperWidth := 58;

      ttt80mm: TFrxReportPage(AReport.Pages[1]).PaperWidth := 80;

    end;

    if AReport.PrepareReport() then

    begin

       Result := AReport.Print;

    end;

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.