public static RectangleF ConvertToUnits(TPaperDimensions PageBounds) { real XConv = 1; //100F/72F; //100 is Display Units. 72 is a point. real YConv = XConv; return(new RectangleF(0, 0, PageBounds.Width * XConv, PageBounds.Height * YConv)); }
/// <summary> /// Returns the page dimensions for a sheet. You can use it to create a bitmap to export the data. /// </summary> /// <returns></returns> public TPaperDimensions GetRealPageSize(int ActiveSheet) { TPaperDimensions pd = FPageSize; if (FPageSize == null) { int SaveActiveSheet = Workbook.ActiveSheet; try { Workbook.ActiveSheet = ActiveSheet; pd = Workbook.PrintPaperDimensions; if ((Workbook.PrintOptions & TPrintOptions.Orientation) == 0) { float w = pd.Width; pd.Width = pd.Height; pd.Height = w; } } finally { Workbook.ActiveSheet = SaveActiveSheet; } } return(new TPaperDimensions(pd.PaperName, pd.Width, pd.Height)); }
private Bitmap CreateBitmap(double Resolution, TPaperDimensions pd, PixelFormat PxFormat) { Bitmap Result = new Bitmap((int)Math.Ceiling(pd.Width / 96F * Resolution), (int)Math.Ceiling(pd.Height / 96F * Resolution), PxFormat); Result.SetResolution((float)Resolution, (float)Resolution); return(Result); }
private TImgExportInfo GetExportInfo(IFlxGraphics aCanvas) { TImgExportInfo Result = new TImgExportInfo(); if (AllVisibleSheets) { int FirstVisibleSheet = -1; int SaveActiveSheet = Workbook.ActiveSheet; try { Result.Sheets = new TOneImgExportInfo[Workbook.SheetCount]; for (int sheet = 1; sheet <= Workbook.SheetCount; sheet++) { Workbook.ActiveSheet = sheet; if (Workbook.SheetVisible != TXlsSheetVisible.Visible) { continue; } if (FirstVisibleSheet < 0) { FirstVisibleSheet = sheet; } TOneImgExportInfo OneResult = new TOneImgExportInfo(); OneResult.FPrintRanges = FRenderer.InternalCalcPrintArea(FPrintRange); TPaperDimensions pd = GetRealPageSize(); OneResult.FPageBounds = new RectangleF(0, 0, pd.Width, pd.Height); FRenderer.InitializePrint(aCanvas, OneResult.PageBounds, OneResult.PageBounds, OneResult.PrintRanges, out OneResult.FPaintClipRect, out OneResult.FTotalPages, out OneResult.FPagePrintRange); Result.Sheets[sheet - 1] = OneResult; } } finally { Workbook.ActiveSheet = SaveActiveSheet; } Result.CurrentSheet = FirstVisibleSheet; } else { TOneImgExportInfo OneResult = new TOneImgExportInfo(); OneResult.FPrintRanges = FRenderer.InternalCalcPrintArea(FPrintRange); TPaperDimensions pd = GetRealPageSize(); OneResult.FPageBounds = new RectangleF(0, 0, pd.Width, pd.Height); FRenderer.InitializePrint(aCanvas, OneResult.PageBounds, OneResult.PageBounds, OneResult.PrintRanges, out OneResult.FPaintClipRect, out OneResult.FTotalPages, out OneResult.FPagePrintRange); Result.Sheets = new TOneImgExportInfo[1]; Result.Sheets[0] = OneResult; Result.CurrentSheet = Workbook.ActiveSheet; } Result.ResetCurrentPage(); LastInitSheet = 0; return(Result); }
internal void BeginSave(TPdfStream DataStream, TXRefSection XRef, TPaperDimensions PageSize, TPdfSignature Signature, string aFallbackFontList, TFontEvents FontEvents) { CatalogId = XRef.GetNewObject(DataStream); int PageTreeId = XRef.GetNewObject(DataStream); PageTree = new TPageTreeRecord(PageTreeId, aFallbackFontList, Compress, FontEvents); Info = new TInfoRecord(); AcroForm = new TAcroFormRecord(Signature); Perms = new TPermsRecord(); CreateNewPage(DataStream, XRef, PageSize); }
private void CreateNewPage(TPdfStream DataStream, TXRefSection XRef, TPaperDimensions PageSize) { int PageId = XRef.GetNewObject(DataStream); int ContentId = XRef.GetNewObject(DataStream); PageTree.AddPage(PageId, ContentId, PageSize); TIndirectRecord.SaveHeader(DataStream, ContentId); LengthId = XRef.GetNewObject(DataStream); TStreamRecord.BeginSave(DataStream, LengthId, Compress); DataStream.Compress = Compress; StartStream = DataStream.Position; }
private Bitmap CreateBitmap(float Resolution, ref TImgExportInfo ExportInfo, PixelFormat PxFormat) { if (ExportInfo == null) { ExportInfo = GetFirstPageExportInfo(); } TPaperDimensions pd = GetRealPageSize(ExportInfo.NextSheet); Bitmap Result = BitmapConstructor.CreateBitmap((int)Math.Ceiling(pd.Width / 96F * Resolution), (int)Math.Ceiling(pd.Height / 96F * Resolution), PxFormat); Result.SetResolution(Resolution, Resolution); return(Result); }
private void LoadPageSize() { TPaperDimensions pd = FPageSize; if (FPageSize == null) { pd = Workbook.PrintPaperDimensions; if ((Workbook.PrintOptions & TPrintOptions.Orientation) == 0) { float w = pd.Width; pd.Width = pd.Height; pd.Height = w; } } PdfCanvas.PageSize = pd; }
//The methods shows how to use FlexCelImgExport the "hard way", without using SaveAsImage. //For normal operation you should only need to call SaveAsImage, but you could use the code here //if you need to customize the ImgExport output, or if you need to get all the images as different files. private void CreateImg(Stream OutStream, FlexCelImgExport ImgExport, ImageFormat ImgFormat, ImageColorDepth Colors, ref TImgExportInfo ExportInfo) { TPaperDimensions pd = ImgExport.GetRealPageSize(); PixelFormat RgbPixFormat = Colors != ImageColorDepth.TrueColor ? PixelFormat.Format32bppPArgb : PixelFormat.Format24bppRgb; PixelFormat PixFormat = PixelFormat.Format1bppIndexed; switch (Colors) { case ImageColorDepth.TrueColor: PixFormat = RgbPixFormat; break; case ImageColorDepth.Color256: PixFormat = PixelFormat.Format8bppIndexed; break; } using (Bitmap OutImg = CreateBitmap(ImgExport.Resolution, pd, PixFormat)) { Bitmap ActualOutImg = Colors != ImageColorDepth.TrueColor ? CreateBitmap(ImgExport.Resolution, pd, RgbPixFormat) : OutImg; try { using (Graphics Gr = Graphics.FromImage(ActualOutImg)) { Gr.FillRectangle(Brushes.White, 0, 0, ActualOutImg.Width, ActualOutImg.Height); //Clear the background ImgExport.ExportNext(Gr, ref ExportInfo); } if (Colors == ImageColorDepth.BlackAndWhite) { FloydSteinbergDither.ConvertToBlackAndWhite(ActualOutImg, OutImg); } else if (Colors == ImageColorDepth.Color256) { OctreeQuantizer.ConvertTo256Colors(ActualOutImg, OutImg); } } finally { if (ActualOutImg != OutImg) { ActualOutImg.Dispose(); } } OutImg.Save(OutStream, ImgFormat); } }
private Bitmap CreateBitmap(double Resolution, TPaperDimensions pd, PixelFormat PxFormat) { Bitmap Result = new Bitmap((int)Math.Ceiling(pd.Width / 96F * Resolution), (int)Math.Ceiling(pd.Height / 96F * Resolution), PxFormat); float result = (float)Resolution; if (float.IsPositiveInfinity(result)) { result = float.MaxValue; } else if (float.IsNegativeInfinity(result)) { result = float.MinValue; } Result.SetResolution(result, result); return(Result); }
internal TPageContents(int aId, TPaperDimensions aPageSize) { Id = aId; PageSize = aPageSize; }
internal void AddPage(int PageId, int ContentId, TPaperDimensions PageSize) { FList.Add(new TPageInfo(PageId, new TPageContents(ContentId, PageSize), new TAnnotList())); }
internal void NewPage(TPdfStream DataStream, TXRefSection XRef, TPaperDimensions PageSize) { FinishPage(DataStream, XRef); CreateNewPage(DataStream, XRef, PageSize); }