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 properties in the PrintInfo class are only available when saving to PDF.
The printing optimization rules, which you can turn on or off, can be customized by setting the properties of these rule objects:
Rule Object | Description |
---|---|
LandscapeRule | Determines whether to print the sheet in landscape or portrait orientation. |
ScaleRule | 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 | 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 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 object and set whether to use these rules with the UseSmartPrint property and SmartPrintRules object.
Return to the overview at Saving Data to a File.
Using Code
- Create a PrintInfo object.
- If you want to change how SmartPrint determines how best to print the sheet, create a new SmartPrintRulesCollection object.
- Set the PrintInfo object property to true.
- Set the SheetView object PrintInfo property to the PrintInfo object you just created.
Example
This example code prints using customized print rules, set up in the SmartPrintRulesCollection 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%.
C# | Copy Code |
---|---|
// Create the print rules. FarPoint.Web.Spread.SmartPrintRulesCollection printrules = new FarPoint.Web.Spread.SmartPrintRulesCollection(); printrules.Add(new FarPoint.Web.Spread.BestFitColumnRule(FarPoint.Web.Spread.ResetOption.None)); printrules.Add(new FarPoint.Web.Spread.LandscapeRule(FarPoint.Web.Spread.ResetOption.None)); printrules.Add(new FarPoint.Web.Spread.ScaleRule(FarPoint.Web.Spread.ResetOption.All, 1.0f, .4f, .2f)); // Create a PrintInfo object and set the properties. FarPoint.Web.Spread.PrintInfo printset = new FarPoint.Web.Spread.PrintInfo(); printset.SmartPrintRules = printrules; printset.UseSmartPrint = true; fpSpread1.Sheets[0].PrintInfo = printset; // Print the sheet. fpSpread1.SavePdf("c:\\test.pdf"); |
VB | Copy Code |
---|---|
' Create the print rules. Dim printrules As New FarPoint.Web.Spread.SmartPrintRulesCollection() printrules.Add(New FarPoint.Web.Spread.BestFitColumnRule(FarPoint.Web.Spread.ResetOption.None)) printrules.Add(New FarPoint.Web.Spread.LandscapeRule(FarPoint.Web.Spread.ResetOption.None)) printrules.Add(New FarPoint.Web.Spread.ScaleRule(FarPoint.Web.Spread.ResetOption.All, 1.0F, 0.4F, 0.2F)) ' Create a PrintInfo object and set the properties. Dim printset As New FarPoint.Web.Spread.PrintInfo() printset.SmartPrintRules = printrules printset.UseSmartPrint = True FpSpread1.Sheets(0).PrintInfo = printset ' Print the sheet. FpSpread1.SavePdf("C:\test.pdf") |