Spread WPF 17
Spread WPF Documentation / Developer's Guide / Managing Data / Printing to PDF
In This Topic
    Printing to PDF
    In This Topic

    You can specify many options when saving to a PDF file. You can specify footers, headers, orientation, borders, and many other options in the PrintInfo class.

    The PdfExportSettings class can be used to specify additional information about the PDF file such as title or author.

    The following table displays the options that can be used when creating a print header or footer:

    Control Character Printed Header or Footer Action
    P Inserts the current page number
    N Inserts the total number of printed pages
    D Inserts the date
    T Inserts the time
    G Inserts an image
    S Uses strikethrough in the font
    U Uses underline in the font
    B Uses a bold font
    I Uses italics in the font
    - NoneSpecified
    \" FontPrefix
    K ColorPrefix
    F Inserts the name of the workbook (Name property)
    A Inserts the name of the sheet (Name property)

    Use the & symbol in front of the control character to specify an option in the above table. For example, &P inserts the current page number.

    Using Code

    The following example specifies several print properties and saves to a PDF file with the SavePdf method.

    CS
    Copy Code

    string fileName;
    fileName = "c:\\zipfile\\test.pdf";
    System.IO.Stream stream;
    stream = System.IO.File.Create(fileName);

    gcSpreadSheet1.Workbook.Name = "WorkBook";
    gcSpreadSheet1.Sheets[0].Name = "Sheet 0";
    GrapeCity.Windows.SpreadSheet.Data.PrintInfo printtest;
    printtest = gcSpreadSheet1.Sheets[0].PrintInfo;
    printtest.FooterCenter = "This is Page &P";
    printtest.HeaderCenter = "&A of &F";

    printtest.HeaderLeft = "&KFFFF00Color &KFF0000RedColor";
    printtest.BestFitColumns = true;
    printtest.UseMax = true;

    GrapeCity.Windows.SpreadSheet.Data.PdfExportSettings test;
    test = new GrapeCity.Windows.SpreadSheet.Data.PdfExportSettings();
    test.Title = "Print PDF";
    test.Author = "Mescius, Inc.";
    test.DisplayDocTitle = true;
    test.FitWindow = true;
    gcSpreadSheet1.SavePdf(stream, test, 0);

    VB.NET
    Copy Code

    Dim fileName As String
    fileName = "c:\zipfile\test.pdf"
    Dim stream As System.IO.Stream
    stream = System.IO.File.Create(fileName)

    GcSpreadSheet1.Workbook.Name = "WorkBook"
    GcSpreadSheet1.Sheets(0).Name = "Sheet 0"
    Dim printtest As GrapeCity.Windows.SpreadSheet.Data.PrintInfo
    printtest = GcSpreadSheet1.Sheets(0).PrintInfo
    printtest.FooterCenter = "This is Page &P"
    printtest.HeaderCenter = "&A of &F"

    printtest.HeaderLeft = "&KFFFF00Color &KFF0000RedColor"
    printtest.BestFitColumns = True
    printtest.UseMax = True


    Dim test As GrapeCity.Windows.SpreadSheet.Data.PdfExportSettings
    test = New GrapeCity.Windows.SpreadSheet.Data.PdfExportSettings()
    test.Title = "Print PDF"
    test.Author = "Mescius, Inc."
    test.DisplayDocTitle = True
    test.FitWindow = True
    GcSpreadSheet1.SavePdf(stream, test, 0)

    See Also