C# .NET - Set Page Print Property of Fast Report .Net

Asked By stefan on 26-Nov-11 01:39 AM
Hi all

I have a small problem. I have a Fast Report that is designed to be an A3 size but i want to be able to Print it on an A4 aswell. Is there a way of setting the Print Property to do this
Thanks for the help

Stefan
Suchit shah replied to stefan on 26-Nov-11 01:45 AM
You can set the Paper Size property like below sample
// Add list of supported paper sizes found on the printer.
      // The DisplayMember property is used to identify the property that will provide the display string.
      comboPaperSize.DisplayMember = "PaperName";
 
      PaperSize pkSize;
      for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
        pkSize = printDoc.PrinterSettings.PaperSizes[i];
        comboPaperSize.Items.Add(pkSize);
      }
 
      // Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
      PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);
 
      comboPaperSize.Items.Add(pkCustomSize1);
 
 
 
...
 
 
// Add list of paper sources found on the printer to the combo box.
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSource.DisplayMember="SourceName";
 
PaperSource pkSource;
for (int i = 0; i < printDoc.PrinterSettings.PaperSources.Count; i++){
  pkSource = printDoc.PrinterSettings.PaperSources[i];
  comboPaperSource.Items.Add(pkSource);
}
 
 
...
 
 
// Add list of printer resolutions found on the printer to the combobox.
// The PrinterResolution's ToString() method will be used to provide the display string.
 
PrinterResolution pkResolution;
for (int i = 0; i < printDoc.PrinterSettings.PrinterResolutions.Count; i++){
  pkResolution = printDoc.PrinterSettings.PrinterResolutions[i];
  comboPrintResolution.Items.Add(pkResolution);
}
 
 
...
 
 
private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
  // Set the paper size based upon the selection in the combo box.
  if (comboPaperSize.SelectedIndex != -1) {
    printDoc.DefaultPageSettings.PaperSize =
      printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
  }
 
  // Set the paper source based upon the selection in the combo box.
  if (comboPaperSource.SelectedIndex != -1) {
    printDoc.DefaultPageSettings.PaperSource =
      printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
  }
 
  // Set the printer resolution based upon the selection in the combo box.
  if (comboPrintResolution.SelectedIndex != -1)
  {
    printDoc.DefaultPageSettings.PrinterResolution=
      printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
  }
 
  // Print the document with the specified paper size, source, and print resolution.
  printDoc.Print();
}

Suchit shah replied to stefan on 26-Nov-11 01:46 AM
You can also set Landscape or Portioret resettion like below one
public void Printing() {
   try {
   streamToPrint = new StreamReader (filePath);
   try {
     printFont = new Font("Arial", 10);
     PrintDocument pd = new PrintDocument();
     pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
     pd.PrinterSettings.PrinterName = printer;
     // Set the page orientation to landscape.
     pd.DefaultPageSettings.Landscape = true;
     pd.Print();
   }
   finally {
     streamToPrint.Close() ;
   }
   }
   catch(Exception ex) {
   MessageBox.Show(ex.Message);
   }
}
 


Jitendra Faye replied to stefan on 28-Nov-11 02:10 AM
You can use PrinterSettings class for this.

Try this code-


public void Printing(string printer) {
  try {
    streamToPrint = new StreamReader (filePath);
    try {
      printFont = new Font("Arial", 10);
      PrintDocument pd = new PrintDocument(); 
      pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
      // Specify the printer to use.
      pd.PrinterSettings.PrinterName = printer;
      if (pd.PrinterSettings.IsValid) {
         pd.Print();
      } 
      else {	
         MessageBox.Show("Printer is invalid.");
      }
    } 
    finally {
      streamToPrint.Close();
    }
  } 
  catch(Exception ex) {
    MessageBox.Show(ex.Message);
  }
}


Try this and let me know.