コード例 #1
0
        private void Watermark(FastString Page, ReportPage page, bool drawText)
        {
            using (PictureObject pictureWatermark = new PictureObject())
            {
                pictureWatermark.Left = 0;
                pictureWatermark.Top  = 0;

                pictureWatermark.Width  = (ExportUtils.GetPageWidth(page) - page.LeftMargin - page.RightMargin) * Units.Millimeters;
                pictureWatermark.Height = (ExportUtils.GetPageHeight(page) - page.TopMargin - page.BottomMargin) * Units.Millimeters;

                pictureWatermark.SizeMode = PictureBoxSizeMode.Normal;
                pictureWatermark.Image    = new Bitmap((int)pictureWatermark.Width, (int)pictureWatermark.Height);

                using (Graphics g = Graphics.FromImage(pictureWatermark.Image))
                {
                    g.Clear(Color.Transparent);
                    if (drawText)
                    {
                        page.Watermark.DrawText(new FRPaintEventArgs(g, 1f, 1f, Report.GraphicCache),
                                                new RectangleF(0, 0, pictureWatermark.Width, pictureWatermark.Height), Report, true);
                    }
                    else
                    {
                        page.Watermark.DrawImage(new FRPaintEventArgs(g, 1f, 1f, Report.GraphicCache),
                                                 new RectangleF(0, 0, pictureWatermark.Width, pictureWatermark.Height), Report, true);
                    }
                    pictureWatermark.Transparency = page.Watermark.ImageTransparency;
                    LayerBack(Page, pictureWatermark, null);
                    LayerPicture(Page, pictureWatermark, null);
                }
            }
        }
コード例 #2
0
        private static PrintDocument PrepareDoc(this Report report, PrinterSettings settings = null)
        {
            if (report.PreparedPages.Count < 1)
            {
                report.Prepare();
                if (report.PreparedPages.Count < 1)
                {
                    return(null);
                }
            }

            var page = 0;
            var exp  = new ImageExport {
                ImageFormat = ImageExportFormat.Png, Resolution = 600
            };

            var doc = new PrintDocument {
                DocumentName = report.Name
            };

            if (settings != null)
            {
                doc.PrinterSettings = settings;
            }

            // Ajustando o tamanho da pagina
            doc.QueryPageSettings += (sender, args) =>
            {
                var rPage = report.PreparedPages.GetPage(page);
                args.PageSettings.Landscape = rPage.Landscape;
                args.PageSettings.Margins   = new Margins((int)(scaleFactor * rPage.LeftMargin * Units.HundrethsOfInch),
                                                          (int)(scaleFactor * rPage.RightMargin * Units.HundrethsOfInch),
                                                          (int)(scaleFactor * rPage.TopMargin * Units.HundrethsOfInch),
                                                          (int)(scaleFactor * rPage.BottomMargin * Units.HundrethsOfInch));

                args.PageSettings.PaperSize = new PaperSize("Custom", (int)(ExportUtils.GetPageWidth(rPage) * scaleFactor * Units.HundrethsOfInch),
                                                            (int)(ExportUtils.GetPageHeight(rPage) * scaleFactor * Units.HundrethsOfInch));
            };

            doc.PrintPage += (sender, args) =>
            {
                using (var ms = new MemoryStream())
                {
                    exp.PageRange   = PageRange.PageNumbers;
                    exp.PageNumbers = $"{page + 1}";
                    exp.Export(report, ms);

                    args.Graphics.DrawImage(Image.FromStream(ms), args.PageBounds);
                }

                page++;

                args.HasMorePages = page < report.PreparedPages.Count;
            };

            doc.EndPrint += (sender, args) => page = 0;
            doc.Disposed += (sender, args) => exp?.Dispose();

            return(doc);
        }
コード例 #3
0
        /// <inheritdoc/>
        protected override void ExportPageBegin(ReportPage page)
        {
            base.ExportPageBegin(page);
            zoomX  = ResolutionX / 96f;
            zoomY  = ResolutionY / 96f;
            width  = (int)(ExportUtils.GetPageWidth(page) * Units.Millimeters * zoomX);
            height = (int)(ExportUtils.GetPageHeight(page) * Units.Millimeters * zoomY);
            int suffixDigits = Pages[Pages.Length - 1].ToString().Length;

            fileSuffix = firstPage ? "" : (pageNumber + 1).ToString("".PadLeft(suffixDigits, '0'));
            if (SeparateFiles || IsMultiFrameTiff)
            {
                image = CreateImage(width, height, fileSuffix);
                if (IsMultiFrameTiff && masterTiffImage == null)
                {
                    masterTiffImage = image;
                }
            }
            else
            {
                image = bigImage;
            }

            if (bigGraphics != null)
            {
                g = bigGraphics;
            }
            else
            {
                g = Graphics.FromImage(image);
            }

            state = g.Save();
            g.FillRegion(Brushes.White, new Region(new RectangleF(0, curOriginY, width, height)));

            if (image == bigImage)
            {
                g.TranslateTransform(image.Width / 2 - width / 2 + page.LeftMargin * Units.Millimeters * zoomX,
                                     curOriginY + paddingNonSeparatePages + page.TopMargin * Units.Millimeters * zoomY);
            }
            else
            {
                g.TranslateTransform(page.LeftMargin * Units.Millimeters * zoomX, page.TopMargin * Units.Millimeters * zoomY);
            }

            g.ScaleTransform(1, zoomY / zoomX);

            // export bottom watermark
            if (page.Watermark.Enabled && !page.Watermark.ShowImageOnTop)
            {
                AddImageWatermark(page);
            }
            if (page.Watermark.Enabled && !page.Watermark.ShowTextOnTop)
            {
                AddTextWatermark(page);
            }
        }
コード例 #4
0
        /// <inheritdoc/>
        protected override void ExportPageBegin(ReportPage page)
        {
            // begin and prepare
            base.ExportPageBegin(page);
            pdfPage          = new PdfPage();
            pdfPage.Parent   = pdfPagesLink;
            pdfPage.MediaBox = new System.Drawing.RectangleF(0, 0,
                                                             ExportUtils.GetPageWidth(page) * PdfWriter.PDF_PAGE_DIVIDER,
                                                             ExportUtils.GetPageHeight(page) * PdfWriter.PDF_PAGE_DIVIDER);

            // export page as one image
            {
                ClearBitmaps();

                scaleFactor = ImageDpi / 96f;
                int width  = (int)(ExportUtils.GetPageWidth(page) * scaleFactor * Units.Millimeters);
                int height = (int)(ExportUtils.GetPageHeight(page) * scaleFactor * Units.Millimeters);
                // check for max bitmap object size
                // 2GB (max .net object size) / 4 (Format32bppArgb is 4 bytes)
                // see http://stackoverflow.com/a/29175905/4667434
                const ulong maxPixels = 536870912;
                if ((ulong)width * (ulong)height < maxPixels)
                {
                    pageBitmap   = new Bitmap(width, height);
                    pageGraphics = Graphics.FromImage(pageBitmap);
                    pageGraphics.TranslateTransform(this.scaleFactor * page.LeftMargin * Units.Millimeters, this.scaleFactor * page.TopMargin * Units.Millimeters, System.Drawing.Drawing2D.MatrixOrder.Append);
                    //pageGraphics.ScaleTransform(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
                }
            }

            pageContent = new PdfContents();

            // export page background
            using (TextObject pageFill = new TextObject())
            {
                pageFill.Fill   = page.Fill;
                pageFill.Left   = -page.LeftMargin * Units.Millimeters;
                pageFill.Top    = -page.TopMargin * Units.Millimeters;
                pageFill.Width  = ExportUtils.GetPageWidth(page) * Units.Millimeters;
                pageFill.Height = ExportUtils.GetPageHeight(page) * Units.Millimeters;
                ExportObj(pageFill);
            }

            // export bottom watermark
            if (page.Watermark.Enabled && !page.Watermark.ShowImageOnTop)
            {
                AddImageWatermark(page);
            }
            if (page.Watermark.Enabled && !page.Watermark.ShowTextOnTop)
            {
                AddTextWatermark(page);
            }
        }
コード例 #5
0
        /// <inheritdoc/>
        protected override void ExportPageEnd(ReportPage page)
        {
            base.ExportPageEnd(page);

            // export top watermark
            if (page.Watermark.Enabled && page.Watermark.ShowImageOnTop)
            {
                AddImageWatermark(page);
            }
            if (page.Watermark.Enabled && page.Watermark.ShowTextOnTop)
            {
                AddTextWatermark(page);
            }

            pageGraphics.Dispose();
            pageGraphics = null;
            DrawImage(new System.Drawing.RectangleF(0, 0,
                                                    ExportUtils.GetPageWidth(page) * PdfWriter.PDF_PAGE_DIVIDER,
                                                    ExportUtils.GetPageHeight(page) * PdfWriter.PDF_PAGE_DIVIDER), pageBitmap);
            pdfPage["Contents"] = pdfWriter.Write(pageContent);

            pdfPages.Kids.Add(pdfWriter.Write(pdfPage));
        }
コード例 #6
0
        private void ExportHTMLPageLayeredBegin(HTMLData d)
        {
            if (!singlePage && !WebMode)
            {
                cssStyles.Clear();
            }

            css      = new FastString();
            htmlPage = new FastString();

            ReportPage reportPage = d.page;

            if (reportPage != null)
            {
                maxWidth  = ExportUtils.GetPageWidth(reportPage) * Units.Millimeters;
                maxHeight = ExportUtils.GetPageHeight(reportPage) * Units.Millimeters;

                if (enableMargins)
                {
                    leftMargin = reportPage.LeftMargin * Units.Millimeters;
                    topMargin  = reportPage.TopMargin * Units.Millimeters;
                }
                else
                {
                    maxWidth  -= (reportPage.LeftMargin + reportPage.RightMargin) * Units.Millimeters;
                    maxHeight -= (reportPage.TopMargin + reportPage.BottomMargin) * Units.Millimeters;
                    leftMargin = 0;
                    topMargin  = 0;
                }

                currentPage = d.PageNumber - 1;

                ExportHTMLPageStart(htmlPage, d.PageNumber, d.CurrentPage);

                doPageBreak = (singlePage && pageBreaks);

                htmlPage.Append(HTMLGetAncor((d.PageNumber).ToString()));

                htmlPage.Append("<div ").Append(doPageBreak ? "class=\"frpage\"" : String.Empty).
                Append(" style=\"position:relative;width:").Append(Px(maxWidth * Zoom + 3)).
                Append("height:").Append(Px(maxHeight * Zoom));

                if (reportPage.Fill is SolidFill)
                {
                    SolidFill fill = reportPage.Fill as SolidFill;
                    htmlPage.Append("; background-color:").
                    Append(fill.Color.A == 0 ? "transparent" : ExportUtils.HTMLColor(fill.Color));
                }
                htmlPage.Append("\">");

                if (!(reportPage.Fill is SolidFill))
                {
                    // to-do for picture background
                }

                if (reportPage.Watermark.Enabled && !reportPage.Watermark.ShowImageOnTop)
                {
                    Watermark(htmlPage, reportPage, false);
                }

                if (reportPage.Watermark.Enabled && !reportPage.Watermark.ShowTextOnTop)
                {
                    Watermark(htmlPage, reportPage, true);
                }
            }
        }
コード例 #7
0
        private void AddTextWatermark(ReportPage page)
        {
            if (pageGraphics != null)
            {
                if (string.IsNullOrEmpty(page.Watermark.Text))
                {
                    return;
                }

                page.Watermark.DrawText(new FRPaintEventArgs(pageGraphics, 1, 1, Report.GraphicCache),
                                        new RectangleF(-page.LeftMargin * Units.Millimeters, -page.TopMargin * Units.Millimeters, ExportUtils.GetPageWidth(page) * Units.Millimeters, ExportUtils.GetPageHeight(page) * Units.Millimeters),
                                        page.Report, false);
            }
        }
コード例 #8
0
 private void AddImageWatermark(ReportPage page)
 {
     if (pageGraphics != null)
     {
         page.Watermark.DrawImage(new FRPaintEventArgs(pageGraphics, 1, 1, Report.GraphicCache),
                                  new RectangleF(-page.LeftMargin * Units.Millimeters, -page.TopMargin * Units.Millimeters, ExportUtils.GetPageWidth(page) * Units.Millimeters, ExportUtils.GetPageHeight(page) * Units.Millimeters),
                                  page.Report, false);
     }
 }