// Create a pdf file stream using FileStream outputStream = new FileStream("SaveSheetBackgroundToPDF.pdf", FileMode.Create); //create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Value = "Document Solutions for Excel"; worksheet.Range["A1"].Font.Size = 25; Stream stream = this.GetResourceStream("logo.png"); byte[] imageBytes = new byte[stream.Length]; stream.Read(imageBytes, 0, imageBytes.Length); //Set a background image for worksheet worksheet.BackgroundPicture = imageBytes; PdfSaveOptions pdfSaveOptions = new PdfSaveOptions { //Print the background image when saving pdf. //The background image will be centered on every page of the sheet. PrintBackgroundPicture = true }; //Save the workbook into pdf file. workbook.Save(outputStream, pdfSaveOptions);
' Create a pdf file stream Dim outputStream = File.Create("SaveSheetBackgroundToPDF.pdf") ' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range!A1.Value = "Document Solutions for Excel" worksheet.Range!A1.Font.Size = 25 Dim stream As Stream = GetResourceStream("logo.png") Dim imageBytes(CInt(stream.Length) - 1) As Byte stream.Read(imageBytes, 0, imageBytes.Length) 'Set a background image for worksheet worksheet.BackgroundPicture = imageBytes 'Print the background image when saving pdf. 'The background image will be centered on every page of the sheet. Dim pdfSaveOptions As New PdfSaveOptions With { .PrintBackgroundPicture = True } 'Save the workbook into pdf file. workbook.Save(outputStream, pdfSaveOptions)