/// <summary> /// Returns the number of pages that the active sheet will use when exported to pdf. /// </summary> public int TotalPagesInSheet() { int PagesInSheet; IFlxGraphics aCanvas = new PdfGraphics(PdfCanvas); LoadPageSize(); PrepareCanvas(); FRenderer.SetCanvas(aCanvas); try { TXlsCellRange[] MyPrintRange = FRenderer.InternalCalcPrintArea(FPrintRange); TXlsCellRange PagePrintRange; RectangleF[] PaintClipRect; FRenderer.InitializePrint(aCanvas, PdfGraphics.ConvertToUnits(PdfCanvas.PageSize), PdfGraphics.ConvertToUnits(PdfCanvas.PageSize), MyPrintRange, out PaintClipRect, out PagesInSheet, out PagePrintRange); return(PagesInSheet); } finally { FRenderer.SetCanvas(null); } }
private int TotalPagesInSheet(PrintPageEventArgs e, IFlxGraphics aCanvas, RectangleF VisibleClipInches100) { TXlsCellRange[] MyPrintRange = FRenderer.InternalCalcPrintArea(FPrintRange); TXlsCellRange PagePrintRange; RectangleF[] PaintClipRect; int TotalPages; bool Landscape = (Workbook.PrintOptions & TPrintOptions.Orientation) == 0; FRenderer.InitializePrint(aCanvas, ConvertToUnits(e.PageBounds, Landscape != e.PageSettings.Landscape), ConvertToMargins(e.Graphics, e.PageBounds, VisibleClipInches100, e.PageSettings.Landscape != Landscape), MyPrintRange, out PaintClipRect, out TotalPages, out PagePrintRange); return(TotalPages); }
/// <summary> /// Exports the associated xls workbook to a graphics stream. You need to provide a /// Graphics object with the correct dimensions. (To get the needed dimensions, use <see cref="GetRealPageSize()"/> /// </summary> /// <param name="imgData">Graphics where the image will be stored. Set it to null to skip the page.</param> /// <param name="exportInfo"> Information needed to export, cached for speed. The first time you call this method (or when you change xls.ActiveSheet), make exportInfo=null</param> public bool ExportNext(Graphics imgData, ref TImgExportInfo exportInfo) { FRenderer.CreateFontCache(); try { Bitmap bmp = null; try { if (imgData == null) { bmp = BitmapConstructor.CreateBitmap(1, 1); imgData = Graphics.FromImage(bmp); imgData.PageUnit = GraphicsUnit.Point; } IFlxGraphics aCanvas = new GdiPlusGraphics(imgData); GraphicsUnit OriginalUnits = imgData.PageUnit; try { imgData.PageUnit = GraphicsUnit.Point; FRenderer.SetCanvas(aCanvas); try { if (exportInfo == null) { exportInfo = GetExportInfo(aCanvas); } exportInfo.IncCurrentPage(); if (exportInfo.CurrentPage > exportInfo.TotalPages) { return(false); } int SaveActiveSheet = Workbook.ActiveSheet; try { Workbook.ActiveSheet = exportInfo.CurrentSheet; int CurrentLogicalPage = -1; if (ResetPageNumberOnEachSheet) { CurrentLogicalPage = exportInfo.ActiveSheet.FCurrentPage; } else { CurrentLogicalPage = exportInfo.CurrentPage; } TOneImgExportInfo OneResult = exportInfo.ActiveSheet; if (LastInitSheet != exportInfo.CurrentSheet) { TXlsCellRange ra; int p; RectangleF[] r; FRenderer.InitializePrint(aCanvas, OneResult.PageBounds, OneResult.PageBounds, OneResult.PrintRanges, out r, out p, out ra); LastInitSheet = exportInfo.CurrentSheet; } if (bmp == null) { OnBeforePaint(new ImgPaintEventArgs(imgData, CalcPageBounds(exportInfo.ActiveSheet.PageBounds), exportInfo.CurrentPage, exportInfo.ActiveSheet.CurrentPage, exportInfo.TotalPages)); } FRenderer.GenericPrint(aCanvas, OneResult.PageBounds, OneResult.PrintRanges, CurrentLogicalPage, OneResult.PaintClipRect, exportInfo.TotalLogicalPages(ResetPageNumberOnEachSheet), bmp == null, OneResult.PagePrintRange, ref OneResult.FCurrentPrintArea); aCanvas.ResetClip(); if (bmp == null) { OnAfterPaint(new ImgPaintEventArgs(imgData, CalcPageBounds(exportInfo.ActiveSheet.PageBounds), exportInfo.CurrentPage, exportInfo.ActiveSheet.CurrentPage, exportInfo.TotalPages)); } } finally { Workbook.ActiveSheet = SaveActiveSheet; } } finally { FRenderer.SetCanvas(null); } } finally { imgData.PageUnit = OriginalUnits; } } finally { if (bmp != null) { bmp.Dispose(); imgData.Dispose(); } } } finally { FRenderer.DisposeFontCache(); } return(true); }