Пример #1
0
    public static void ExportToPDF(this IRenderer renderer, String title, Stream stream)
    {
        var root = renderer.SkiaTree.Root;

        PdfDocument document = new PdfDocument();

        document.Info.Title = title;

        PdfPage page = document.AddPage();

        page.Size = PdfSharp.PageSize.A4;

        XGraphics gfx = XGraphics.FromPdfPage(page);

        PdfDrawingContext context = new PdfDrawingContext(gfx);

        context.Rendering += (sender, bounds) =>
        {
            if (bounds.Bottom > page.Height.Value * (double)document.PageCount && bounds.Height < page.Height)
            {
                page      = document.AddPage();
                page.Size = PdfSharp.PageSize.A4;
                gfx.Dispose();
                gfx = XGraphics.FromPdfPage(page);
                context.Reset(gfx, (page.Height.Value * (document.PageCount - 1)));
            }
        };

        root.Render(context, root.Bounds, root.Bounds, 1);

        document.Save(stream, false);

        gfx.Dispose();
    }
Пример #2
0
        /// <summary>
        /// Draws an image over a rectange (like those specified in a form field)
        /// </summary>
        /// <param name="PDFDocument"></param>
        /// <param name="sImage">Should work for PNG, JPG, GIF and BMP</param>
        /// <param name="rect"></param>
        /// <param name="focusPageReference"></param>
        private static void OverlayImageOnField(PdfDocument PDFDocument, byte[] image, PdfRectangle rect, PdfItem focusPageReference)
        {
            var stream = new MemoryStream(image, 0, image.Length);


            //also a bit of pain to locate the acutaly page the field is on... but OK.
            XGraphics gfxObj = null;

            foreach (var page in PDFDocument.Pages)
            {
                if (page.Reference == focusPageReference)
                {
                    if (gfxObj != null)   //dispose of object before getting a new one.  Should actually never happen... but better safe than sorry....
                    {
                        gfxObj.Dispose();
                    }
                    gfxObj = XGraphics.FromPdfPage(page);
                    break;
                }
            }

            // Draw the image


            XImage ximage = XImage.FromStream(stream);

            double xscaling = 1;
            double yscaling = 1;

            if (ximage.PointWidth / ximage.PointHeight > rect.Width / rect.Height)
            {
                yscaling = (ximage.PointWidth / ximage.PointHeight) / (rect.Width / rect.Height);
            }
            else
            {
                xscaling = (rect.Width / rect.Height) / (ximage.PointWidth / ximage.PointHeight);
            }

            double scaling = Math.Max(ximage.PointHeight / rect.Height, ximage.PointWidth / rect.Width);

            if (gfxObj.PageDirection == XPageDirection.Downwards)
            {
                gfxObj.DrawImage(ximage, rect.X1, gfxObj.PageSize.Height - rect.Y1 - rect.Height, rect.Width / xscaling, rect.Height / yscaling);
            }
            else
            {
                gfxObj.DrawImage(ximage, rect.X1, rect.Y1, rect.Width / scaling, rect.Height / scaling);
            }
            gfxObj.Dispose();
        }
Пример #3
0
        internal static byte[] CreatePDF(int minKB, int maxKB)
        {
            PdfDocument pdfDoc = new PdfDocument();

            pdfDoc.Info.Title   = "SPDG created document";
            pdfDoc.Info.Author  = "SPDG";
            pdfDoc.Info.Subject = "Sample SharePoint document";

            PdfPage page = pdfDoc.AddPage();

            page.Orientation = PdfSharp.PageOrientation.Portrait;
            XGraphics gfx = XGraphics.FromPdfPage(page);


            DrawText(gfx, 30, 30, page.Width, 20, XFontStyle.Bold, 20, SampleData.GetSampleValueRandom(SampleData.BusinessDocsTypes));

            DrawText(gfx, 30, 60, page.Width, 20, XFontStyle.Regular, 12, "Date: " + SampleData.GetRandomDate(1990, 2015).ToShortDateString());
            DrawText(gfx, 30, 80, page.Width, 20, XFontStyle.Regular, 12, "Author: " + SampleData.GetSampleValueRandom(SampleData.FirstNames) + " " + SampleData.GetSampleValueRandom(SampleData.LastNames));
            DrawText(gfx, 30, 100, page.Width - 60, 20, XFontStyle.Regular, 12, "ID: " + SampleData.GetRandomNumber(100000, 1000000).ToString());

            string lore = File.ReadAllText("SampleData\\loreIpsum.txt");

            DrawText(gfx, 30, 120, page.Width, page.Height - 100, XFontStyle.Regular, 12, lore);
            gfx.Dispose();

            int minRepeat   = minKB / 13;
            int maxRepeat   = maxKB / 13;
            int finalRepeat = 1;

            if (minRepeat > 20 && maxRepeat > 20 && minRepeat < maxKB)
            {
                finalRepeat = SampleData.GetRandomNumber(minRepeat, maxRepeat);
            }

            for (int i = 0; i < finalRepeat; i++)
            {
                page             = pdfDoc.AddPage();
                page.Orientation = PdfSharp.PageOrientation.Portrait;
                gfx = XGraphics.FromPdfPage(page);
                DrawText(gfx, 30, 30, page.Width - 60, page.Height - 100, XFontStyle.Regular, 12, lore);
                gfx.Dispose();
            }

            MemoryStream memoryStream = new MemoryStream();

            pdfDoc.Save(memoryStream);

            return(memoryStream.ToArray());
        }
Пример #4
0
        public static void DrawImageOnPage(PdfPage page, XImage image, double x, double y, double page_rotation)
        {
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // there is a bug for landscape PDF files
            Console.WriteLine("orientation {0}", page.Orientation);
            if (page.Orientation == PdfSharp.PageOrientation.Landscape)
            {
                // Translate coordinate system. To solve a strange problem.
                gfx.RotateTransform(-90);
                gfx.TranslateTransform(-page.Height, 0);
            }

            // rotate
            if (page_rotation != 0.0)
            {
                Console.WriteLine("rotate {0} degree", page_rotation);

                XPoint centerPoint = new XPoint(page.Width / 2, page.Height / 2);
                gfx.RotateAtTransform(-page_rotation, centerPoint);
            }

            gfx.DrawImage(image, x, y);
            gfx.Dispose();
        }
Пример #5
0
        PdfPage CreateWaterMark(PdfPage page, string watermark)
        {
            // Variation 1: Draw watermark as text string
            Gfx.Dispose();
            // Get an XGraphics object for drawing beneath the existing content
            XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

            // Get the size (in point) of the text
            XSize size = gfx.MeasureString(watermark, font);

            // Define a rotation transformation at the center of the page
            gfx.TranslateTransform(10, -400);

            // Create a string format
            XStringFormat format = new XStringFormat();

            format.Alignment     = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;

            // Create a dimmed red brush
            XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

            // Draw the string
            gfx.DrawString(watermark, font, brush,
                           new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                           format);
            gfx.Dispose();
            Gfx = XGraphics.FromPdfPage(Page);

            return(page);
        }
Пример #6
0
        /// <summary>
        /// Sets the form in the state FormState.Finished.
        /// </summary>
        internal virtual void Finish()
        {
            if (_formState == FormState.NotATemplate || _formState == FormState.Finished)
            {
                return;
            }
#if GDI
            if (Gfx.Metafile != null)
            {
                _gdiImage = Gfx.Metafile;
            }
#endif
            Debug.Assert(_formState == FormState.Created || _formState == FormState.UnderConstruction);
            _formState = FormState.Finished;
            Gfx.Dispose();
            Gfx = null;

            if (PdfRenderer != null)
            {
                //pdfForm.CreateStream(PdfEncoders.RawEncoding.GetBytes(PdfRenderer.GetContent()));
                PdfRenderer.Close();
                Debug.Assert(PdfRenderer == null);

                if (_document.Options.CompressContentStreams)
                {
                    _pdfForm.Stream.Value        = Filtering.FlateDecode.Encode(_pdfForm.Stream.Value, _document.Options.FlateEncodeMode);
                    _pdfForm.Elements["/Filter"] = new PdfName("/FlateDecode");
                }
                int length = _pdfForm.Stream.Length;
                _pdfForm.Elements.SetInteger("/Length", length);
            }
        }
Пример #7
0
 ///<summary>Draw to the chart's built-in PrintDocument, then set the PrintPreviewController's document to that PrintDocument.
 ///Besides keeping everything synchronized, this makes it easier to display the print preview and show the printer settings window
 ///when the user clicks Print.</summary>
 private void MakePage()
 {
     //update private variables
     FillDimensions();
     //check to see if landscape mode was toggled.
     _chartCur.Printing.PrintDocument.DefaultPageSettings.Landscape = checkLandscape.Checked;
     //reset the document margins
     _chartCur.Printing.PrintDocument.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(_marginWidth, _marginWidth, _marginHeight, _marginHeight);
     //Reset the graphics objects by disposing of them and reinitializing them.
     if (_bmpSheet != null)
     {
         _bmpSheet.Dispose();
     }
     if (_xg != null)
     {
         _xg.Dispose();
     }
     if (_g != null)
     {
         _g.Dispose();
     }
     _bmpSheet = new Bitmap(_pageWidth, _pageHeight);
     _g        = Graphics.FromImage(_bmpSheet);
     _xg       = XGraphics.FromGraphics(_g, new XSize(_bmpSheet.Width, _bmpSheet.Height));
     //draw both the chart and legend to bitmaps
     using (Bitmap chartbmp = new Bitmap(_chartCur.Width, _chartCur.Height))
         using (Bitmap legendbmp = new Bitmap(_legend.Width, _legend.Height)) {
             _chartCur.DrawToBitmap(chartbmp, new Rectangle(0, 0, _chartCur.Width, _chartCur.Height));
             _legend.DrawToBitmap(legendbmp, new Rectangle(0, 0, _legend.Width, _legend.Height));
             //draw both bitmaps to another bitmap for the whole sheet.
             _xg.DrawImage(legendbmp, _xPos + _marginWidth, _yPos + _marginHeight + chartbmp.Height, _legend.Width, _legend.Height);
             _xg.DrawImage(chartbmp, _xPos + _marginWidth, _yPos + _marginHeight, _chartCur.Width, _chartCur.Height);
         }
     printPreviewControl.Document = _chartCur.Printing.PrintDocument;
 }
Пример #8
0
        public void DodajZaglavljeLevo(Kompanija kompanija, PdfPage stranica)
        {
            XGraphics      gfx  = XGraphics.FromPdfPage(stranica);
            XFont          font = new XFont("Times New Roman", 12, XFontStyle.Regular);
            XTextFormatter tf   = new XTextFormatter(gfx);


            XRect xRect = new XRect(30, 20, 350, 220);

            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("Naziv kompanije:" + kompanija.Naziv, font,
                          XBrushes.Black, xRect, XStringFormats.TopLeft);

            xRect        = new XRect(30, 35, 350, 220);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("Lokacija kompanije:" + LokacijaHelper(kompanija.Lokacije), font,
                          XBrushes.Black, xRect, XStringFormats.TopLeft);

            xRect        = new XRect(30, 50, 350, 220);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("Kontakti kompanije:" + KontakHelper(kompanija.Kontakti), font,
                          XBrushes.Black, xRect, XStringFormats.TopLeft);

            gfx.Dispose();
        }
Пример #9
0
        private static void CreatePdfPage(List <JiraTicket> issues, ref PdfDocument pdf)
        {
            PdfPage page = pdf.AddPage();

            page.Size        = PdfSharp.PageSize.A4;
            page.Orientation = PdfSharp.PageOrientation.Landscape;

            for (int j = 0; j < issues.Count; j++)
            {
                string text = issues[j].fields.issuetype.name + System.Environment.NewLine + issues[j].key
                              + System.Environment.NewLine + issues[j].fields.summary + System.Environment.NewLine
                              + issues[j].fields.customfield_10008;

                XGraphics      gfx  = XGraphics.FromPdfPage(page);
                XFont          font = new XFont("Verdana", 20, XFontStyle.Bold);
                XTextFormatter tf   = new XTextFormatter(gfx);
                XRect          rect = new XRect();

                if (j < 3)
                {
                    rect = new XRect(15, 15 + j * 180, 400, 170);
                }
                else
                {
                    rect = new XRect(430, 15 + (j - 3) * 180, 400, 170);
                }

                gfx.DrawRectangle(XBrushes.SeaShell, rect);
                tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
                gfx.Dispose();
            }
        }
Пример #10
0
 private static long TimeGeneratePdf()
 {
     using (PdfDocument doc = new PdfDocument())
     {
         string        folderPath = "PDF\\CUTTED\\QR\\";
         DirectoryInfo dirInfo    = new DirectoryInfo(folderPath);
         sw.Start();
         foreach (var file in dirInfo.GetFiles("*.jpeg"))
         {
             PdfPage   page_    = null;
             XImage    img      = null;
             XGraphics graphics = null;
             try
             {
                 page_    = doc.AddPage();
                 img      = XImage.FromFile(file.FullName.ToString());
                 graphics = XGraphics.FromPdfPage(page_);
                 graphics.DrawImage(img, 0, 0, (int)page_.Width, (int)page_.Height);
             }
             finally
             {
                 page_.Close();
                 img.Dispose();
                 graphics.Dispose();
             }
         }
         sw.Stop();
     }
     timeForPdf = sw.ElapsedMilliseconds * pages;
     return(timeForPdf);
 }
Пример #11
0
        public void PostaviInformacije(Kompanija k, PdfPage stranica)
        {
            XGraphics      gfx      = XGraphics.FromPdfPage(stranica);
            XFont          font     = new XFont("Times New Roman", 18, XFontStyle.Regular);
            XFont          fontBold = new XFont("Times New Roman", 12, XFontStyle.BoldItalic);
            XTextFormatter tf       = new XTextFormatter(gfx);
            XRect          xRect    = new XRect(40, 410, 350, 220);

            tf.Alignment = XParagraphAlignment.Center;
            tf.DrawString("Informacije o kompaniji " + k.Naziv, font, XBrushes.Black, xRect, XStringFormats.TopLeft);
            font         = new XFont("Times New Roman", 12, XFontStyle.Regular);
            xRect        = new XRect(60, 450, 350, 220);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("Naziv kompanije: ", fontBold, XBrushes.Black, xRect, XStringFormats.TopLeft);
            xRect = new XRect(175, 450, 350, 220);
            tf.DrawString(k.Naziv, font, XBrushes.Black, xRect, XStringFormats.TopLeft);
            xRect        = new XRect(60, 465, 350, 220);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("Adresa kompanije: ", fontBold, XBrushes.Black, xRect, XStringFormats.TopLeft);
            xRect = new XRect(175, 465, 350, 220);
            tf.DrawString(HelperClass.Instance.LokacijaHelper(k.Lokacije), font, XBrushes.Black, xRect, XStringFormats.TopLeft);
            xRect        = new XRect(60, 480, 350, 220);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("Kontakti kompanije: ", fontBold, XBrushes.Black, xRect, XStringFormats.TopLeft);
            int variableHеigh = 480;

            foreach (Kontakt kontakt in k.Kontakti)
            {
                xRect = new XRect(175, variableHеigh, 350, 220);
                tf.DrawString(HelperClass.Instance.IspisiKontakt(kontakt), font, XBrushes.Black, xRect, XStringFormats.TopLeft);
                variableHеigh += 15;
            }
            gfx.Dispose();
        }
Пример #12
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         XGraphics.Dispose();
     }
 }
        /// <summary>
        /// Create a polling card for this person
        /// </summary>
        /// <param name="senderName">the name of the sender</param>
        /// <param name="senderStreet">the street of the sender</param>
        /// <param name="senderCity">the city of the sender</param>
        /// <param name="receiverFirstName">the first name of the receiver</param>
        /// <param name="receiverLastName">the last name of the receiver</param>
        /// <param name="receiverStreet">the street of the receiver</param>
        /// <param name="receiverCity">the city of the receiver</param>
        /// <param name="pollingtable">the number of the polling table</param>
        /// <param name="voterNumber">the voter number of the receiver</param>
        /// <param name="pollingVenueName">the name of the polling venue</param>
        /// <param name="pollingVenueStreet">the street of the polling venue</param>
        /// <param name="pollingVenueCity">the city of the polling venue</param>
        public void CreatePollingCard(string senderName,
                                      string senderStreet,
                                      string senderCity,
                                      string receiverFirstName,
                                      string receiverLastName,
                                      string receiverStreet,
                                      string receiverCity,
                                      string pollingtable,
                                      string voterNumber,
                                      string pollingVenueName,
                                      string pollingVenueStreet,
                                      string pollingVenueCity)
        {
            //Add a new page to the document
            PdfPage page = _document.AddPage();

            page.Width  = XUnit.FromMillimeter(Width);
            page.Height = XUnit.FromMillimeter(Height);
            XGraphics gfx = XGraphics.FromPdfPage(page);

            //Draw the template
            gfx.DrawImage(_template, 0, 0);

            //Draw the voter specific information on the polling card
            FromField(gfx, senderName, senderStreet, senderCity);
            ToField(gfx, receiverFirstName + " " + receiverLastName, receiverStreet, receiverCity);
            PollingTable(gfx, pollingtable);
            VotingNumber(gfx, voterNumber);
            PollingVenue(gfx, pollingVenueName, pollingVenueStreet, pollingVenueCity);

            //Release the XGraphics object
            gfx.Dispose();
        }
Пример #14
0
 public override void Dispose()
 {
     if (_releaseGraphics)
     {
         _g.Dispose();
     }
 }
Пример #15
0
        public void PostaviWathermark(string nazivKompanije, PdfPage strana)
        {
            XGraphics      gfx           = XGraphics.FromPdfPage(strana, XGraphicsPdfPageOptions.Prepend);
            XFont          font          = new XFont("Times New Roman", 26, XFontStyle.Bold);
            XTextFormatter textFormatter = new XTextFormatter(gfx);

            var size = gfx.MeasureString("PDFSharp", font);

            gfx.TranslateTransform(strana.Width / 2, strana.Height / 2);
            gfx.RotateTransform(-Math.Atan(strana.Height / strana.Width) * 180 / Math.PI);
            gfx.TranslateTransform(-strana.Width / 2, -strana.Height / 2);

            var format = new XStringFormat();

            format.Alignment     = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;

            XBrush brush = new XSolidBrush(XColor.FromArgb(128, 141, 184, 224));

            gfx.DrawString(nazivKompanije.ToUpper(),
                           font,
                           brush,
                           new XPoint((strana.Width - size.Width) / 2, (strana.Height - size.Height) / 2), format);

            gfx.Dispose();
        }
Пример #16
0
        public void Save(string path, Leyenda legend)
        {
            try
            {
                PdfDocument document = new PdfDocument();
                PdfPage     page     = new PdfPage();
                page.Size        = _layout.Size;
                page.Orientation = _layout.Orientation;
                document.AddPage(page);
                XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Replace);
                this.Render(gfx);

                PdfPage pageL = new PdfPage();
                pageL.Size        = PageSize.A4;
                pageL.Orientation = PageOrientation.Portrait;
                document.AddPage(pageL);
                gfx = XGraphics.FromPdfPage(pageL, XGraphicsPdfPageOptions.Replace);
                this.CreateLegend(gfx, legend);

                document.Save(path);
                gfx.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #17
0
        public void DodajSlikuUZaglavlje(Kompanija kompanija, PdfPage stranica)
        {
            XGraphics gfx = XGraphics.FromPdfPage(stranica);

            IscrtajSliku(gfx, "wwwroot/images/photo.jpg", 450, 20, 150, 50);

            gfx.Dispose();
        }
Пример #18
0
        public void DrawImage(Image image, double x, double y, double width, double heigth)
        {
            XGraphics graph = XGraphics.FromPdfPage(pdfPage);
            XImage    xi    = (XImage)image;

            graph.DrawImage(xi, x, y, width, heigth);
            graph.Dispose();
        }
Пример #19
0
        public void Print(System.Drawing.Graphics g)
        {
            g.PageUnit = System.Drawing.GraphicsUnit.Point;
            XGraphics gfx = XGraphics.FromGraphics(g, XSize.FromSize(PageSizeConverter.ToSize(_layout.Size)));

            this.Render(gfx);
            gfx.Dispose();
        }
Пример #20
0
        public void DrawVerticalLine(double pinSize, double x, double margin)
        {
            XGraphics graph = XGraphics.FromPdfPage(pdfPage);
            XPen      pen   = new XPen(XColor.FromName("Black"), pinSize);

            graph.DrawLine(pen, x, 0 + margin, x, this.Height - margin);
            graph.Dispose();
        }
Пример #21
0
        public void PrintLegend(System.Drawing.Graphics g, Leyenda legend)
        {
            g.PageUnit = System.Drawing.GraphicsUnit.Point;
            XGraphics gfx = XGraphics.FromGraphics(g, XSize.FromSize(PageSizeConverter.ToSize(PageSize.A4)));

            this.CreateLegend(gfx, legend);
            gfx.Dispose();
        }
Пример #22
0
        public void DrawHorizontalLine(double pinSize, double y, double margin)
        {
            XGraphics graph = XGraphics.FromPdfPage(pdfPage);
            XPen      pen   = new XPen(XColor.FromName("Black"), pinSize);

            graph.DrawLine(pen, 0 + margin, y, this.Width - margin, y);
            graph.Dispose();
        }
Пример #23
0
        /// <summary>
        /// Creates a meta file from the current page.
        /// </summary>
        private void miMetaFile_Click(object sender, EventArgs e)
        {
            int page = this.pagePreview.Page;

            // Reuse the renderer from the preview
            DocumentRenderer renderer = this.pagePreview.Renderer;
            PageInfo         info     = renderer.FormattedDocument.GetPageInfo(page);

            // Create an image
            float dx, dy;

            if (info.Orientation == PdfSharp.PageOrientation.Portrait)
            {
                dx = (float)(info.Width.Inch * 72);
                dy = (float)(info.Height.Inch * 72);
            }
            else
            {
                dx = (float)(info.Height.Inch * 72);
                dy = (float)(info.Width.Inch * 72);
            }

            // Create a graphics object as reference
            Graphics graphicsDisplay = CreateGraphics();
            IntPtr   hdc             = graphicsDisplay.GetHdc();

            // There is a little difference between the display resolution (i.g. 96 DPI) and the real physical solution of the display.
            // This must be taken into account...
            DeviceInfos devInfo = DeviceInfos.GetInfos(hdc);

            // Create the metafile
            Metafile metafile = new Metafile("test.emf", hdc,
                                             new RectangleF(0, 0, devInfo.ScaleX * dx, devInfo.ScaleY * dy), MetafileFrameUnit.Point);

            graphicsDisplay.ReleaseHdc(hdc);
            graphicsDisplay.Dispose();

            // Create a Graphics object for the metafile and scale it for drawing with 72 dpi
            Graphics graphics = Graphics.FromImage(metafile);

            graphics.Clear(System.Drawing.Color.White);
            //graphics.PageUnit = GraphicsUnit.Point; ???
            graphics.ScaleTransform(graphics.DpiX / 72, graphics.DpiY / 72);

            // Check if size is correct
            graphics.DrawLine(Pens.Red, 0, 0, dx, dy);

            // Create an XGraphics object and render the page
            XGraphics gfx = XGraphics.FromGraphics(graphics, new XSize(info.Width.Point, info.Height.Point));

            renderer.RenderPage(gfx, page);
            gfx.Dispose();

            metafile.Dispose();

            Process.Start("test.emf");
        }
Пример #24
0
        /// <summary>
        /// Prints the formula of the competition.
        /// </summary>
        private void printCompetitionFormula()
        {
            //Starting on a new page if the given page is not empty.
            if (currentYCoordinate > pageTopSize)
            {
                currentYCoordinate = 810;
            }

            XGraphics graphics    = XGraphics.FromPdfPage(getCurrentPage());
            XFont     font1       = new XFont(FONT_TYPE, 11, XFontStyle.Bold);
            XFont     font2       = new XFont(FONT_TYPE, 10);
            double    font1Height = font1.GetHeight();
            double    font2Height = font2.GetHeight();
            double    x           = DEFAULT_START_X;

            graphics.DrawString(FRCPrinterConstants.FORMULA_OF_COMPETITION, font1, XBrushes.Black, x, currentYCoordinate);
            currentYCoordinate += font1Height * 2;
            string s1 = fencer.Count.ToString() + " " + FRCPrinterConstants.FENCERS_LOWER;

            graphics.DrawString(s1, font2, XBrushes.Black, x, currentYCoordinate);
            currentYCoordinate += font2Height * 3;

            for (int i = 0; i < pouleRound.Count; i++)
            {
                double totalY = currentYCoordinate + font2Height * 4.6;
                graphics = checkYCoordinate(graphics, totalY);

                string s2 = FRCPrinterConstants.POULES_ROUND + " " + (i + 1).ToString() + ":";
                graphics.DrawString(s2, font2, XBrushes.Black, x, currentYCoordinate);
                currentYCoordinate += font2Height * 2;
                string s3 = pouleRound[i].amountOfFencers().ToString() + " " + FRCPrinterConstants.FENCERS_LOWER;
                graphics.DrawString(s3, font2, XBrushes.Black, x, currentYCoordinate);
                currentYCoordinate += font2Height * 1.3;
                string s4 = pouleRound[i].amountOfPoules().ToString() + " " + FRCPrinterConstants.POULES_LOWER + " ";
                graphics.DrawString(s4, font2, XBrushes.Black, x, currentYCoordinate);
                currentYCoordinate += font2Height * 1.3;
                string s5 = pouleRound[i].NumOfQualifiers.ToString() + " " + FRCPrinterConstants.QUALIFIERS;
                graphics.DrawString(s5, font2, XBrushes.Black, x, currentYCoordinate);
                currentYCoordinate += font2Height * 2;
            }

            if (interpreter.Tableau.amountOfFencers() > 0)
            {
                double totalY = currentYCoordinate + font2Height * 3;
                graphics = checkYCoordinate(graphics, totalY);

                string s6 = "----------------------------------------------------";
                graphics.DrawString(s6, font2, XBrushes.Black, x, currentYCoordinate);
                currentYCoordinate += font2Height * 3;
                string s7 = FRCPrinterConstants.DIRECT_ELIMINATION + ": " + interpreter.Tableau.amountOfFencers().ToString() +
                            " " + FRCPrinterConstants.FENCERS_LOWER;
                graphics.DrawString(s7, font2, XBrushes.Black, x, currentYCoordinate);
                currentYCoordinate += font2Height * 2;
            }
            graphics.Dispose();
        }
Пример #25
0
 private void CloseAll()
 {
     if (gfx != null)
     {
         gfx.Dispose();
     }
     if (_Doc != null)
     {
         _Doc.Dispose();
     }
 }
Пример #26
0
        /// <summary>
        /// Check that the given y coordinate is within range before a new page must be added.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private XGraphics checkYCoordinate(XGraphics graphics, double y)
        {
            if (y >= 810)
            {
                currentYCoordinate = 810;
                graphics.Dispose();
                graphics = XGraphics.FromPdfPage(getCurrentPage());
            }

            return(graphics);
        }
Пример #27
0
        /// <summary>
        /// Prints an individual string to a pdf document
        /// </summary>
        /// <param name="pdf">Pdf to print to</param>
        /// <param name="pageNumber"></param>
        /// <param name="top">Distancefrom top in pts for printing text</param>
        /// <param name="left">Distancefrom top in pts for printing text</param>
        /// <param name="fontFamily"></param>
        /// <param name="fontSize"></param>
        /// <param name="fontStyle"></param>
        /// <param name="textToPrint"></param>
        void PrintElement(PdfDocument pdf, int pageNumber, double top, double left, string fontFamily, double fontSize, string fontStyle, string textToPrint)
        {
            XGraphics gfx = XGraphics.FromPdfPage(pdf.Pages[pageNumber - 1]);

            XFont font = new XFont(fontFamily, fontSize, (XFontStyle)Enum.Parse(typeof(XFontStyle), fontStyle));

            XPoint xTL = new XPoint(left, top);

            gfx.DrawString(textToPrint, font, XBrushes.Black, new XRect(xTL, xTL));
            gfx.Dispose();
        }
Пример #28
0
        /// <summary>
        /// Creates a new new page and adds it to the pdf document.
        /// </summary>
        private void AddPage()
        {
            //Releases the Xgraphics object for the previous page
            if (_gfx != null)
            {
                _gfx.Dispose();
            }
            PdfPage page = _document.AddPage();

            //Size of the page
            page.Size = PageSize.A4;

            //Sets the Xgraphics associated with the current page
            _gfx = XGraphics.FromPdfPage(page);

            //Reset the row counter
            _count = 0;

            //Draw the template
            DrawTemplate(page);
        }
Пример #29
0
        /// <summary>
        /// Sets the render function.
        /// </summary>
        public void SetRenderFunction(Action <XGraphics> renderFunction)
        {
            if (canvas.Children.Count > 0)
            {
                canvas.Children.Clear();
            }

            XGraphics gfx = XGraphics.FromCanvas(canvas, new XSize(100, 100), XGraphicsUnit.Presentation);

            renderFunction(gfx);
            gfx.Dispose();  // necessary in WPF
        }
Пример #30
0
        public static Boolean FarpointToPDF0(FpSpread fpSpread, String pdfFile, Int32 reportIndex)
        {
            Boolean flag = false;

            if (fpSpread == null || fpSpread.Sheets.Count == 0)
            {
                return(flag);
            }
            PrintInfo Info = new PrintInfo();

            Info.CopyFrom(fpSpread.Sheets[0].PrintInfo);
            Info.ShowGrid = false;
            Bitmap Panel = new Bitmap(Info.PaperSize.Width, Info.PaperSize.Height);

            using (Graphics g = Graphics.FromImage(Panel))
            {
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

                System.Drawing.Rectangle r = new System.Drawing.Rectangle(
                    Info.Margin.Left,
                    Info.Margin.Top,
                    Info.PaperSize.Width - Info.Margin.Left - Info.Margin.Right,
                    Info.PaperSize.Height - Info.Margin.Top - Info.Margin.Bottom
                    );

                int Foot, Heard;
                Foot  = (int)Math.Round(g.MeasureString(Info.Footer, fpSpread.Font).Height);
                Heard = (int)Math.Round(g.MeasureString(Info.Header, fpSpread.Font).Height);

                r = new System.Drawing.Rectangle(r.X, r.Y + Heard, r.Width, r.Height - Foot - Heard);
                fpSpread.OwnerPrintDraw(g, r, 0, 1);
            }
            Info = null;
            PdfDocument doc = new PdfDocument();

            doc.Pages.Add(new PdfPage());
            XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
            XImage    img = XImage.FromGdiPlusImage(Panel);

            xgr.DrawImage(img, 0, 0);

            doc.Save(pdfFile);
            doc.Close();
            xgr.Dispose();
            img.Dispose();
            doc.Dispose();
            Panel.Dispose();
            GC.Collect();
            flag = true;
            return(flag);
        }