pgSetup.PrintArea = “A1:” + lastCell.Name; //Final Print Area
//Set the margins to remove white spacing
pgSetup.LeftMargin = 0;
pgSetup.RightMargin = 0;
pgSetup.TopMargin = 0;
pgSetup.BottomMargin = 0;
//Now you can take the print image of your worksheet ImageOrPrintOptions options = new ImageOrPrintOptions() { PrintingPage = PrintingPageType.Default, IsImageFitToPage = true, OnePagePerSheet = true };
SheetRender sheetRender = new SheetRender(ws, options);
//Save the image in jpeg format to reduce size Bitmap sheetImage = sheetRender.ToImage(0);
Thank you for the code sample. Attached is the spreadsheet for which I am attempting set the dynamic print area. As you can see, when you select any new grouping (paging filter) that causes the cells from the pivot table to change the borders of the print area, those cells will not be printed.
Hello. I already have 5.3.3.2 What feature of this release will allow me to implement a dynamic print area such that when I change the input of the pivot table the print area will also change?
If your requirement is to render only specific part of the worksheet onto the resultant PDF then you should use the PageSetup.PrintArea property to specify the desired cells range at run-time. Please check the following piece of code. In case I have misunderstood your requirement then please share more details, most preferably a sample spreadsheet along with desired range to be printed.
Please note, I have tested the code with latest version Aspose.Cells for .NET (Latest Version) , and I believe the same can be done with version 7.1.2 as well.
C#
var option = new PdfSaveOptions();
option.OnePagePerSheet = true;
var book = new Workbook(inFile);
var sheet = book.Worksheets[0];
var psetup = sheet.PageSetup;
psetup.TopMargin = 0;
psetup.LeftMargin = 0;
psetup.RightMargin = 0;
psetup.BottomMargin = 0;
//Render only one Cell A1 to PDF
psetup.PrintArea = “A1:A1”;
book.Save(“D:/OneCell.pdf”, option);
//Render display area
psetup.PrintArea = sheet.Cells.MaxDisplayRange.RefersTo;
book.Save(“D:/MaxDisplayRange.pdf”, option);
//Render range containing data
psetup.PrintArea = sheet.Cells.FirstCell.Name + “:” + CellsHelper.ColumnIndexToName(sheet.Cells.MaxDataColumn) + sheet.Cells.MaxDataRow + 1;
book.Save(“D:/DataRange.pdf”, option);