Document Solutions for Excel, .NET Edition | Document Solutions
File Operations / Export to PDF / Customize Border Style
In This Topic
    Customize Border Style
    In This Topic

    DsExcel enables you to export PDF documents with a custom border style using BorderOptions property of PdfSaveOptions class. This property uses BorderWidth and Dashes properties of CustomBorderStyle class and BorderLineStyle enumeration to set the border width, dash length, and line style. BorderWidth property adjusts the width of a border when exporting a PDF document, whereas Dashes property adjusts the length of each segment of the dashed line. BorderLineStyle enumeration specifies the line style for the border.

    The following table lists the default values of all the border styles:

    Border Type Default Line Width (point) Dashes (point) Comment
    Hair 0.2 None -
    DashDotDot 1 9,3,3,3,3,3 -
    DashDot 1 8,2,2,2 -
    Dotted 1 1,1 -
    Dashed 1 3,1 -
    Thin 1 None -
    MediumDashDotDot 2 4.5,1.5,1.5,1.5,1.5,1.5 -
    SlantDashDot 1 11, 1,5,1 This border type comprises two lines, each with a width of 1 point.
    MediumDashDot 2 4.5,1.5,1.5,1.5 -
    MediumDashed 2 4.5,1.5 -
    Medium 2 None -
    Thick 3 None This border type comprises three lines, each with a width of 1 point.
    Double 1 None This border type comprises two lines, each with a width of 1 point.

    Refer to the following example code to adjust the border width, dash length, and line style when exporting to a PDF document:

    C#
    Copy Code
    // Create a new workbook.
    var workbook = new Workbook();
    
    // Open template file.
    workbook.Open("CustomBorderStyle.xlsx");
    
    // Customize the border style for PDF export.
    // Initialize PdfSaveOptions.
    var pdfSaveOptions = new PdfSaveOptions();
                
    // Set outer border width to 0.4.
    var thinBorderSetting = new CustomBorderStyle { BorderWidth = 0.4 };
    
    // Set middle border width to 1.5.
    var middleBorderSetting = new CustomBorderStyle { BorderWidth = 1.5 };
    
    // Set inner horizontal border width to 0.4 in dash style.
    var dashBorderSetting = new CustomBorderStyle { BorderWidth = 0.4, Dashes = new List<double> { 0.8, 0.8 } };
    
    // Add borders with custom border styles.
    pdfSaveOptions.BorderOptions.Add(BorderLineStyle.Thin, thinBorderSetting);
    pdfSaveOptions.BorderOptions.Add(BorderLineStyle.Medium, middleBorderSetting);
    pdfSaveOptions.BorderOptions.Add(workbook.ActiveSheet.Range["B13"].Borders[BordersIndex.EdgeTop].LineStyle, dashBorderSetting);
                
    // Save workbook to PDF file.
    workbook.Save("CustomBorder.pdf", pdfSaveOptions);