# Optimizing the Printing Using Rules

Learn how to optimize printing with rules for landscape or portrait orientation, scale, and column fitting using SmartPrint in Spread.NET.

## Content

Spread provides a way to automatically determine the best way to print your sheet. By using rules that you can choose, it can decide, for example, whether it is best to print your sheet on landscape- or portrait-oriented pages.
The rules, that you can turn on or off, that optimize the printing can be customized by setting the properties of these rule objects:

| **Rule Object** | **Description** |
| ----------- | ----------- |
| [LandscapeRule](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.LandscapeRule.html) | Determines whether to print the sheet in landscape or portrait orientation. |
| [ScaleRule](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.ScaleRule.html) | Determines the best scale at which to print the sheet, starting with 100% (Start Factor = 1), and decreasing at set intervals to a minimum size (End Factor).Default settings are Start Factor = 1, End Factor = 0.6, and Interval = 0.1. |
| [BestFitColumnRule](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.BestFitColumnRule.html) | Determines how best to fit the columns in the sheet on the page. |

By default, optimizing the printing of the sheet uses the following logic:

* If the information can be printed without making any changes to the settings that you have defined in the [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object, the sheet prints in portrait mode.
* If the sheet is wider than a portrait page, the sheet prints in landscape mode.
* If the information does not fit in landscape mode, but does fit in landscape mode if the sheet is reduced up to 60% of its original size, the sheet is scaled to fit within the page.
* If the information cannot be scaled to fit, the sheet tries to reduce column widths to accommodate the widest string within each column.
* If all attempts to make the sheet print within a page fail, printing resumes normally in the current printer orientation with no reductions.

You can customize how this logic is applied through the rule objects. If you customize the rule object, the default rules are ignored and only the custom rules are used for printing. You can set up a collection of these rules with the [SmartPrintRulesCollection](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SmartPrintRulesCollection.html) object and set whether to use these rules with the [UseSmartPrint](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.UseSmartPrint.html) property.

## Using the Properties Window

1. At design time, in the **Properties** window, select the Spread component.
2. Select the **Sheets** property.
3. Click the button to display the **SheetView Collection Editor**.
4. In the **Members** list, select the sheet for which to use SmartPrint.
5. In the properties list, double-click the **PrintInfo** property to display the settings for the **PrintInfo** class.
6. Set the **UseSmartPrint** property to true.
7. If you want to customize the SmartPrint rules, select the SmartPrintRules and click the button to display the **SmartPrintRule Collection Editor**. Customize the rules as you want, then click **OK** to close the **SmartPrintRule Collection Editor**.
8. Click **OK** to close the **SheetView Collection** editor.

## Using a Shortcut

1. Create a [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object.
2. If you want to change how SmartPrint determines how best to print the sheet, create a new [SmartPrintRulesCollection](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SmartPrintRulesCollection.html) object.
3. Set the [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object [UseSmartPrint](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.UseSmartPrint.html) property to true.
4. Set the Sheets shortcut object [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.PrintInfo.html) property to the [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object you just created.

**Example**
This example code prints using customized print rules, set up in the [SmartPrintRulesCollection](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SmartPrintRulesCollection.html) object. In this example, if the sheet does fit on a page by shrinking columns to the longest text string, it prints with the columns shrunk. If it does not fit with the columns shrunk, it keeps them shrunk and tries to print in landscape orientation. If it does not fit with the columns shrunk and in landscape orientation, it keeps these settings and tries to scale the sheet, starting at 100%, then decreasing by 20% intervals down to 40%.

```csharp
// Create the print rules.
FarPoint.Win.Spread.SmartPrintRulesCollection printrules = new FarPoint.Win.Spread.SmartPrintRulesCollection();
printrules.Add(new FarPoint.Win.Spread.BestFitColumnRule(FarPoint.Win.Spread.ResetOption.None));
printrules.Add(new FarPoint.Win.Spread.LandscapeRule(FarPoint.Win.Spread.ResetOption.None));
printrules.Add(new FarPoint.Win.Spread.ScaleRule(FarPoint.Win.Spread.ResetOption.All, 1.0f, .4f, .2f));
// Create a PrintInfo object and set the properties.
FarPoint.Win.Spread.PrintInfo printset = new FarPoint.Win.Spread.PrintInfo();
printset.SmartPrintRules = printrules;
printset.UseSmartPrint = true;
// Set the PrintInfo property for the first sheet.
fpSpread1.Sheets[0].PrintInfo = printset;
// Print the sheet.
fpSpread1.PrintSheet(0);
```

```vbnet
' Create the print rules.
Dim printrules As New FarPoint.Win.Spread.SmartPrintRulesCollection()
printrules.Add(New FarPoint.Win.Spread.BestFitColumnRule(FarPoint.Win.Spread.ResetOption.None))
printrules.Add(New FarPoint.Win.Spread.LandscapeRule(FarPoint.Win.Spread.ResetOption.None))
printrules.Add(New FarPoint.Win.Spread.ScaleRule(FarPoint.Win.Spread.ResetOption.All, 1.0F, 0.4F, 0.2F))
' Create a PrintInfo object and set the properties.
Dim printset As New FarPoint.Win.Spread.PrintInfo()
printset.SmartPrintRules = printrules
printset.UseSmartPrint = True
' Set the PrintInfo property for the first sheet.
fpSpread1.Sheets(0).PrintInfo = printset
' Print the sheet.
fpSpread1.PrintSheet(0)
```

## Using Code

1. Create a [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object.
2. If you want to change how SmartPrint determines how best to print the sheet, create a new [SmartPrintRulesCollection](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SmartPrintRulesCollection.html) object.
3. Set the [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object [UseSmartPrint](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.UseSmartPrint.html) property to true.
4. Set the [SheetView](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.html) object [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.PrintInfo.html) property to the [PrintInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.html) object you just created.

**Example**
This example code prints using customized print rules, set up in the [SmartPrintRulesCollection](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SmartPrintRulesCollection.html) object. In this example, if the sheet does fit on a page by shrinking columns to the longest text string, it prints with the columns shrunk. If it does not fit with the columns shrunk, it keeps them shrunk and tries to print in landscape orientation. If it does not fit with the columns shrunk and in landscape orientation, it keeps these settings and tries to scale the sheet, starting at 100%, then decreasing by 20% intervals down to 40%.

```csharp
// Create the print rules.
FarPoint.Win.Spread.SmartPrintRulesCollection printrules = new FarPoint.Win.Spread.SmartPrintRulesCollection();
printrules.Add(new FarPoint.Win.Spread.BestFitColumnRule(FarPoint.Win.Spread.ResetOption.None));
printrules.Add(new FarPoint.Win.Spread.LandscapeRule(FarPoint.Win.Spread.ResetOption.None));
printrules.Add(new FarPoint.Win.Spread.ScaleRule(FarPoint.Win.Spread.ResetOption.All, 1.0f, .4f, .2f));
// Create a PrintInfo object and set the properties.
FarPoint.Win.Spread.PrintInfo printset = new FarPoint.Win.Spread.PrintInfo();
printset.SmartPrintRules = printrules;
printset.UseSmartPrint = true;
// Create a SheetView object and assign it to the first sheet.
FarPoint.Win.Spread.SheetView SheetToPrint = new FarPoint.Win.Spread.SheetView();
SheetToPrint.PrintInfo = printset;
fpSpread1.Sheets[0] = SheetToPrint;
// Print the sheet.
fpSpread1.PrintSheet(0);
```

```vbnet
' Create the print rules.
Dim printrules As New FarPoint.Win.Spread.SmartPrintRulesCollection()
printrules.Add(New FarPoint.Win.Spread.BestFitColumnRule(FarPoint.Win.Spread.ResetOption.None))
printrules.Add(New FarPoint.Win.Spread.LandscapeRule(FarPoint.Win.Spread.ResetOption.None))
printrules.Add(New FarPoint.Win.Spread.ScaleRule(FarPoint.Win.Spread.ResetOption.All, 1.0F, 0.4F, 0.2F))
' Create a PrintInfo object and set the properties.
Dim printset As New FarPoint.Win.Spread.PrintInfo()
printset.SmartPrintRules = printrules
printset.UseSmartPrint = True
' Create a SheetView object and assign it to the first sheet.
Dim SheetToPrint As New FarPoint.Win.Spread.SheetView()
SheetToPrint.PrintInfo = printset
fpSpread1.Sheets(0) = SheetToPrint
' Print the sheet.
fpSpread1.PrintSheet(0)
```

## Using the Spread Designer

1. Select the sheet tab for the sheet for which you want to set print settings.
2. Select the **Page Layout** option.
3. Click the **SmartPrint** tab.
4. Select the **Use SmartPrint** check box if you want to print using the SmartPrint feature.
5. The default printing rules for SmartPrint are listed in the text box. If you want to do so, delete those rules by clicking the **Delete** button, then use the controls below the text box to add rules and rule options.
6. Click **OK** to close the **Sheet Print Options** dialog.
7. From the **File** menu choose **Apply and Exit** to apply your changes to the component and exit Spread Designer.

## See Also

[Optimizing the Printing Using Size](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-printing/spwin-printoptimize/spwin-printbest)