Document Solutions for Excel, Java 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 getBorderOptions method of PdfSaveOptions class. This method uses setBorderWidth and setDashes properties of CustomBorderStyle class and BorderLineStyle enumeration to set the border width, dash length, and line style. setBorderWidth method adjusts the width of a border when exporting a PDF document, whereas setDashes method 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:

    Java
    Copy Code
    // Create a new workbook.
    Workbook workbook = new Workbook();
            
    // Open template file.
    workbook.open("CustomBorderStyle.xlsx");
    
    // Customize the border style for PDF export.
    // Initialize PdfSaveOptions.
    PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
            
    // Set outer border width to 0.4.
    CustomBorderStyle thinBorderSetting = new CustomBorderStyle();
    thinBorderSetting.setBorderWidth(0.4);
            
    // Set middle border width to 1.5.
    CustomBorderStyle middleBorderSetting = new CustomBorderStyle();
    middleBorderSetting.setBorderWidth(1.5);
            
    // Set inner horizontal border width to 0.4 in dash style.
    CustomBorderStyle dashBorderSetting = new CustomBorderStyle();
    dashBorderSetting.setBorderWidth(0.4);
    dashBorderSetting.setDashes(new ArrayList<>(Arrays.asList(0.8, 0.8)));
            
    // Add borders with custom border styles.
    pdfSaveOptions.getBorderOptions().put(BorderLineStyle.Thin, thinBorderSetting);
    pdfSaveOptions.getBorderOptions().put(BorderLineStyle.Medium, middleBorderSetting);
    pdfSaveOptions.getBorderOptions().put(workbook.getActiveSheet().getRange("B13").getBorders().get(BordersIndex.EdgeTop).getLineStyle(), dashBorderSetting);
            
    // Save workbook to PDF file.
    workbook.save("CustomBorder.pdf", pdfSaveOptions);