Пример #1
0
        /// <summary>
        /// Initializes the PDF exporting to a new file. After calling this method
        /// you can call <see cref="ExportSheet()"/> to export different xls files to the same pdf.
        /// You should always end the document with a call to <see cref="EndExport"/>
        /// </summary>
        /// <param name="pdfStream">Stream that will contain the new pdf file.</param>
        public void BeginExport(Stream pdfStream)
        {
            FCanceled = false;
            PdfCanvas = new PdfWriter();
            PdfCanvas.Sign(FSignature);
            PdfCanvas.Compress      = FCompress;
            PdfCanvas.Kerning       = FKerning;
            PdfCanvas.Properties    = FProperties;
            PdfCanvas.GetFontData   = GetFontData;
            PdfCanvas.GetFontFolder = GetFontFolder;
            PdfCanvas.OnFontEmbed   = OnFontEmbed;
            PdfCanvas.FallbackFonts = FFallbackFonts;
            CurrentTotalPage        = 1;
            FirstPageInSheet        = 0;
            FPdfStream = pdfStream;

            FRenderer.CreateFontCache();

            FirstPage = true;
            FProgress.Clear();
        }
Пример #2
0
 /// <summary>
 /// Raises the BeginPrint event. It is called after the Print method is called and before the first page of the document prints.
 /// </summary>
 /// <param name="e">A <see cref="PrintEventArgs"/> that contains the event data.</param>
 /// <remarks>
 /// This method is overridden to print an Excel document.
 /// Before doing its own initialization, it will call <see cref="PrintDocument.OnBeginPrint"/> so you can do your own.
 /// </remarks>
 protected override void OnBeginPrint(PrintEventArgs e)
 {
     base.OnBeginPrint(e);
     SaveActiveSheet     = Workbook.ActiveSheet;
     CurrentSheetPage    = 1;
     CurrentPrintArea    = 0;
     CurrentWorkbookPage = 1;
     TotalSheetPages     = 0;
     if (AllVisibleSheets)
     {
         GotoFirstVisibleSheet();
     }
     PagesToPrint = 0;
     FRenderer.CreateFontCache();
     Workbook.Recalc(false);
 }
Пример #3
0
        /// <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);
        }