Document Solutions for Excel, .NET Edition | Document Solutions
File Operations / Export to PDF / Configure Fonts and Set Style
In This Topic
    Configure Fonts and Set Style
    In This Topic

    DsExcel .NET allows users to configure fonts and set style while saving their worksheets into the PDF format.

    Before performing the export operation, users need to ensure that they set the FontsFolderPath property of the Workbook class in order to specify the font that should be used while saving the PDF.

    If the folder path to the font is not specified and the user is working on Windows OS, the path "C:\Windows\Fonts" will be used by default. However, if the folder path to the font is not specified and the user is working on any other operating system, it is necessary that the user sets the font folder path and copies the used font files to it from the folder "C:\Windows\Fonts".

    You can use the GetUsedFonts() method of the IWorkbook interface in order to get the collection of all the fonts that are used in the workbook.

    While saving PDF, DsExcel .NET uses the fonts specified in the Workbook.FontsFolderPath in order to render the PDF. However, if the used font doesn't exist, it will make use of some fallback fonts. In case, fallback fonts don't exist in the file, DsExcel .NET will throw the exception :"There is no available fonts. Please set a valid path to the FontsFolderPath property of the Workbook!"

    Refer to the following example code to see how you can confirgure fonts and set style while saving to a PDF.

    C#
    Copy Code
    //create workbook and add two sheets.
    Workbook workbook = new Workbook();
    IWorksheet sheet1 = workbook.Worksheets[0];
    IWorksheet sheet2 = workbook.Worksheets.Add();
    
    //set style.
    sheet1.Range["A1"].Value = "Sheet1";
    sheet1.Range["A1"].Font.Name = "Wide Latin";
    sheet1.Range["A1"].Font.Color = Color.Red;
    sheet1.Range["A1"].Interior.Color = Color.Green;
    
    //create a table in sheet1.
    sheet1.Tables.Add(sheet1.Range["C1:E5"], true);
    
    sheet2.Range["A1"].Value = "Sheet2";
    
    //specify font path.
    Workbook.FontsFolderPath = @"D:\Fonts";
    
    //get the used fonts list in workbook, the list are:"Wide Latin", "Calibri"
    var fonts = workbook.GetUsedFonts();
    
    //export workbook to pdf file, the exported file has two pages.
    workbook.Save(@"D:\workbook.pdf", SaveFileFormat.Pdf);
    
    //just export sheet1 to pdf file.
    sheet1.Save(@"D:\sheet1.pdf", SaveFileFormat.Pdf);
    

    Note: The Export to PDF feature doesn't support the following styles:

    a) Usage of Double, Single Acounting, Double Accounting underline, Superscript effect, Subscript effect.

    b) Alignment Preferences like Center across selection, Fill alignment, Orientation, Text reading order etc.

    c) Rectangle Gradient Fill is not supported.