Document Solutions for Excel, .NET Edition | Document Solutions
File Operations / Export to PDF / Support Background Color Transparency
In This Topic
    Support Background Color Transparency
    In This Topic

    When backcolor is applied on a cell or range, any background image or data gets hidden behind it while exporting to PDF.

    DsExcel allows you to make the cell's backcolor transparent when exported to PDF by using the PrintTransparentCell property of the PdfSaveOptions class. The default value of this property is false. When set to true, it prints the transparency of the cell's background color which makes any background image or data visible.

    Refer to the following example code to make cell's backcolor transparent to view the background image in PDF document.

    C#
    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
    
    // Fetch default worksheet
    IWorksheet worksheet = workbook.Worksheets[0];
    
    // Set the background color of range ["A1:K20"]
    worksheet.Range["A1:K20"].Interior.Color = System.Drawing.Color.FromArgb(50, 255, 0, 0);
    
    // Add a background picture
    IBackgroundPicture picture = worksheet.BackgroundPictures.AddPictureInPixel("image.png", 0, 0, 300, 200);
    
    // Set the transparency of cell's background color, so the background picture will come out to the front
    PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
    pdfSaveOptions.PrintTransparentCell = true;
    
    // Save to pdf file
    workbook.Save("PrintTransparentCell.pdf", pdfSaveOptions);