Spread for ASP.NET 10 Product Documentation
Setting Headers and Footers

You can provide headers and footers that appear on the printed pages when saving to a PDF file. Using the Header property and Footer property of the PrintInfo class, which may include special control commands, you can specify text and variables, such as page numbers, as well as specify the font settings. The font related commands begin with "f".

These settings are only available when saving to a PDF file.

The control commands that can be inserted in headers and footers are listed in this table:

Control Character Full Command Action in Printed Page Header or Footer
/ / Inserts a literal forward slash character (/)
/c /c Center justifies the item
/cl /cl"n" Sets the font color for text, with the zero-based index of the color, n, in quotes (n can be 0 or more)
/dl /dl Inserts the date, using the long form
/ds /ds Inserts the date, using the short form
/f /f"n" Recalls the previously saved font settings (see /fs in this table), with the zero-based index, n, in quotes (n can be 0 or more)
/fb /fb0 Turns off bold font type
  /fb1 Turns on bold font type
/fi /fi0 Turns off italics font type
  /fi1 Turns on italics font type
/fk /fk0 Turns off strikethrough
  /fk1 Turns on strikethrough
/fn /fn"name" Sets the name of the font face, with the name of the font in quotes
/fs /fs"n" Saves the font settings for re-use, with the zero-based index of the font settings, n, in quotes (see /f in this table)
/fu /fu0 Turns off underline
  /fu1 Turns on underline
/fz /fz"n" Sets the size of the font
/g /g"n" Inserts a graphic (image), with the zero-based index of the image, n, in quotes (n can be zero or more)
/l /l Left justifies the item (that is the letter l or L, as in Left)
/n /n Inserts a new line
/p /p Inserts a page number
/pc /pc Inserts a page count (the total number of pages in the print job)
/r /r Right justifies the item
/sn /sn Inserts the sheet name
/tl /tl Inserts the time, using the long form
/ts /ts Inserts the time, using the short form

If you use multiple control characters, do not put spaces between them. The letters can be lower or upper case; all commands and examples are shown here in lower case for simplicity.

Define the headers and footers (set the Header and Footer properties) before saving to PDF.

The following list provides additional information about headers and footers:

Using a Shortcut

  1. Create and set the Header and Footer properties for a PrintInfo object.
  2. Set the Sheet shortcut object PrintInfo property to the PrintInfo object you just created.

Example

This example code prints the sheet with the specified header and footer text.

C#
Copy Code
// Create PrintInfo object and set properties.
FarPoint.Web.Spread.PrintInfo printset = new FarPoint.Web.Spread.PrintInfo();
printset.Colors = new Drawing.Color[] {Drawing.Color.Green, Drawing.Color.Yellow, Drawing.Color.Gold, Drawing.Color.Indigo, Drawing.Color.Brown};
printset.Images = new System.Drawing.Image[] {System.Drawing.Image.FromFile("C:\\images\\point.jpg"), System.Drawing.Image.FromFile("C:\\images\\logo.gif"), System.Drawing.Image.FromFile("C:\\images\\icon.jpg")};
printset.Header = ""/fn\"Book Antiqua\" /fz\"14\" Print job for GrapeCity Inc./n ";
printset.Footer = "/g\"1\"/r/cl\"4\"This is page /p of /pc";
// Set the PrintInfo property for the first sheet.
fpSpread1.Sheets[0].PrintInfo = printset;
// Print the sheet.
fpSpread1.SavePdf("c:\\test.pdf"); 
VB
Copy Code
' Create PrintInfo object and set properties.
Dim printset As New FarPoint.Web.Spread.PrintInfo()
printset.Colors = New Drawing.Color() {Drawing.Color.Green, Drawing.Color.Yellow, Drawing.Color.Gold, Drawing.Color.Indigo, Drawing.Color.Brown}
printset.Images = New System.Drawing.Image() {System.Drawing.Image.FromFile("D:\images\point.jpg"), System.Drawing.Image.FromFile("D:\images\logo.gif"), System.Drawing.Image.FromFile("C:\images\icon.jpg")}
printset.Header = "/fn""Book Antiqua"" /fz""14"" Print job for GrapeCity Inc./n "
printset.Footer = "/g""1""/r/cl""4""This is page /p of /pc"
' Set the PrintInfo property for the first sheet.
FpSpread1.Sheets(0).PrintInfo = printset
' Print the sheet.
FpSpread1.SavePdf("c:\test.pdf") 

Using Code

  1. Create and set the Header and Footer properties for a PrintInfo object.
  2. Set the SheetView object PrintInfo property to the PrintInfo object you just created.

Example

This example code prints the sheet with the specified header and footer colors and images.

C#
Copy Code
// Create PrintInfo object and set properties.
FarPoint.Web.Spread.PrintInfo pi = new FarPoint.Web.Spread.PrintInfo();
pi.Footer = "This is Page /p/nof /pc Pages";
pi.Header = "Print Job For /nFPT Inc.";
pi.Colors = new Drawing.Color[] {Drawing.Color.Red, Drawing.Color.Blue};
pi.Images = new System.Drawing.Image[] {System.Drawing.Image.FromFile("D:\Corporate.jpg"), System.Drawing.Image.FromFile("D:\Building.jpg")};
pi.RepeatColEnd = 25;
pi.RepeatColStart = 1;
pi.RepeatRowEnd = 25;
pi.RepeatRowStart = 1;
fpSpread1.Sheets[0].PrintInfo = pi;
fpSpread1.SavePdf("c:\\test.pdf"); 
VB
Copy Code
' Create PrintInfo object and set properties.
Dim pi As New FarPoint.Web.Spread.PrintInfo
pi.Footer = "This is Page /p/nof /pc Pages"
pi.Header = "Print Job For /nFPT Inc."
pi.Colors = New Drawing.Color() {Drawing.Color.Red, Drawing.Color.Blue}
pi.Images = New System.Drawing.Image() {System.Drawing.Image.FromFile("D:\Corporate.jpg"), System.Drawing.Image.FromFile("D:\Building.jpg")}
pi.RepeatColEnd = 25
pi.RepeatColStart = 1
pi.RepeatRowEnd = 25
pi.RepeatRowStart = 1
FpSpread1.Sheets(0).PrintInfo = pi
FpSpread1.SavePdf("c:\test.pdf") 

Using Code

  1. Create and set the Header and Footer properties for a PrintInfo object.
  2. Set the SheetView object PrintInfo property to the PrintInfo object you just created.

Example

This example code prints the sheet with the specified header and footer text.

C#
Copy Code
// Create PrintInfo object and set properties.
FarPoint.Web.Spread.PrintInfo printset = new FarPoint.Web.Spread.PrintInfo();
printset.Header = "/lJobName";
printset.Footer = "/r/p of /pc";
// Create SheetView object and assign it to the first sheet.
FarPoint.Web.Spread.SheetView SheetToPrint = new FarPoint.Web.Spread.SheetView();
SheetToPrint.PrintInfo = printset;
// Set the PrintInfo property for the first sheet.
fpSpread1.Sheets[0] = SheetToPrint;
// Print the sheet.
fpSpread1.SavePdf("c:\\test.pdf"); 
VB
Copy Code
' Create PrintInfo object and set properties.
Dim printset As New FarPoint.Web.Spread.PrintInfo()
printset.Header = "/lJobName"
printset.Footer = "/r/p of /pc"
' Create SheetView object and assign it to the first sheet.
Dim SheetToPrint As New FarPoint.Web.Spread.SheetView()
SheetToPrint.PrintInfo = printset
FpSpread1.Sheets(0) = SheetToPrint
' Set the PrintInfo property for the first sheet.
FpSpread1.Sheets(0).PrintInfo = printset
' Print the sheet.
FpSpread1.SavePdf("c:\test.pdf") 
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback