async Task CreateDocumentImages(C1PdfDocument pdf)
        {
            // calculate page rect (discounting margins)
            var rcPage = PdfUtils.PageRectangle(pdf);
            InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();

            // title
            Font font = new Font("Segoe UI Light", 16, PdfFontStyle.Italic);

            pdf.DrawString(Strings.ImagesDocumentTitle, font, Colors.Black, new Rect(72, 72, 400, 100));

            // load image into writeable bitmap
            WriteableBitmap wb   = new WriteableBitmap(880, 660);
            var             file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///PdfSamplesLib/Assets/pic.jpg"));

            wb.SetSource(await file.OpenReadAsync());

            // simple draw image
            var rcPic = new Rect(72, 100, wb.PixelWidth / 5.0, wb.PixelHeight / 5.0);

            pdf.DrawImage(wb, rcPic);

            // draw on page preserving aspect ratio
            var delta = 100.0;

            rcPic = new Rect(new Point(delta, delta), new Point(rcPage.Width - delta, rcPage.Height - delta));
            pdf.DrawImage(wb, rcPic, ContentAlignment.MiddleCenter, Stretch.Uniform);

            // translucent rectangle
            var clr = Color.FromArgb(50, 0, 255, 0);

            pdf.FillRectangle(clr, new Rect(200, 200, 300, 400));
        }
Exemplo n.º 2
0
        static Rect RenderTableHeader(C1PdfDocument pdf, Font font, Rect rc, string[] fields)
        {
            // calculate cell width (same for all columns)
            Rect rcCell = rc;

            rcCell.Width  = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            foreach (string field in fields)
            {
                var height = pdf.MeasureString(field, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell.Height += 6; // add 6 point margin

            // render header cells
            var fmt = new StringFormat();

            fmt.LineAlignment = VerticalAlignment.Center;
            foreach (string field in fields)
            {
                pdf.FillRectangle(Colors.Black, rcCell);
                pdf.DrawString(field, font, Colors.White, rcCell, fmt);
                rcCell = PdfUtils.Offset(rcCell, rcCell.Width, 0);
            }

            // update rectangle and return it
            return(PdfUtils.Offset(rc, 0, rcCell.Height));
        }
        /// <summary>
        /// Shows how to position and align text
        /// </summary>
        static void CreateDocumentText(C1PdfDocument pdf)
        {
            // use landscape for more impact
            pdf.Landscape = true;

            // measure and show some text
            var text = Strings.DocumentBasicText;
            var font = new Font("Segoe UI Light", 12, PdfFontStyle.Italic);

            // create StringFormat used to set text alignment and line spacing
            var fmt = new StringFormat();

            fmt.LineSpacing = -1.5; // 1.5 char height
            fmt.Alignment   = HorizontalAlignment.Center;

            // measure it
            var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
            var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);

            rc = PdfUtils.Offset(rc, 110, 0);

            // draw a rounded frame
            rc = PdfUtils.Inflate(rc, 0, 0);
            pdf.FillRectangle(Colors.Teal, rc, new Size(0, 0));
            //pdf.DrawRectangle(new Pen(Colors.DarkGray, 5), rc, new Size(0, 0));
            rc = PdfUtils.Inflate(rc, -10, -10);

            // draw the text
            //pdf.RotateAngle = 90;
            pdf.DrawString(text, font, Colors.White, rc, fmt);
            //pdf.RotateAngle = 0;

            // point in center for rotate the text
            rc = pdf.PageRectangle;
            var pt = new Point(rc.X + rc.Width / 2, rc.Y + rc.Height / 2);

            // rotate the string in small increments
            var step = 6;

            text = Strings.DocumentBasicText2;
            for (int i = 0; i <= 360; i += step)
            {
                pdf.RotateAngle = i;
                var s = string.Format(text, i);
                font = new Font("Courier New", 8 + i / 30.0, PdfFontStyle.Bold);
                byte b = (byte)(255 * (1 - i / 360.0));
                pdf.DrawString(s, font, Color.FromArgb(0xff, b, b, b), pt);
            }
        }
Exemplo n.º 4
0
        private RectangleF RenderMultiPageImage(ref C1PdfDocument c1pdf, RectangleF rcPage, RectangleF rc, string fileName, Fax fax, bool addMetaText)
        {
            //Image img = Image.FromFile(fileName);
            MemoryStream ms  = new MemoryStream(File.ReadAllBytes(fileName));
            Image        img = Image.FromStream(ms);

            FrameDimension oDimension = new FrameDimension(img.FrameDimensionsList[0]);
            int            FrameCount = img.GetFrameCount(oDimension);

            for (int i = 0; i < FrameCount; i++)
            {
                // calculate image height
                // based on image size and page size
                rc.Height = Math.Min(img.Height / 96f * 72, rcPage.Height);

                // skip page if necessary
                if (rc.Bottom > rcPage.Bottom)
                {
                    c1pdf.NewPage();
                    rc.Y = rcPage.Y;
                }

                // draw solid background (mainly to see transparency)
                rc.Inflate(+2, +2);
                c1pdf.FillRectangle(Brushes.White, rc);
                rc.Inflate(-2, -2);

                // draw image (keep aspect ratio)
                img.SelectActiveFrame(oDimension, i);
                string fn = System.IO.Path.GetFileName(fileName);
                fn = _workingFolder + fn.Substring(0, fn.Length - 4) + "-" + i + ".tif";
                img.Save(fn);
                //Image img1 = Image.FromFile(fn);
                MemoryStream ms1  = new MemoryStream(File.ReadAllBytes(fn));
                Image        img1 = Image.FromStream(ms1);

                c1pdf.DrawImage(img1, rc, ContentAlignment.MiddleCenter, ImageSizeModeEnum.Scale);
                // update rectangle
                rc.Y = rc.Bottom + 20;

                if ((i == 0) && (addMetaText == true))
                {
                    AddMetaText(c1pdf, fax);
                }
            }
            return(rc);
        }
Exemplo n.º 5
0
        //---------------------------------------------------------------------------------
        #region ** text

        static void CreateDocumentText(C1PdfDocument pdf)
        {
            // use landscape for more impact
            pdf.Landscape = true;

            // measure and show some text
            var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            var font = new Font("Times New Roman", 9, PdfFontStyle.Italic);

            // create StringFormat used to set text alignment and line spacing
            var fmt = new StringFormat();

            fmt.LineSpacing = -1.5; // 1.5 char height
            fmt.Alignment   = HorizontalAlignment.Center;

            // measure it
            var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
            var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);

            rc = PdfUtils.Offset(rc, 72, 0);

            // draw a rounded frame
            rc = PdfUtils.Inflate(rc, 10, 10);
            pdf.FillRectangle(Colors.Black, rc, new Size(30, 30));
            pdf.DrawRectangle(new Pen(Colors.Red, 4), rc, new Size(30, 30));
            rc = PdfUtils.Inflate(rc, -10, -10);

            // draw the text
            pdf.DrawString(text, font, Colors.White, rc, fmt);

            // point in center for rotate the text
            rc = pdf.PageRectangle;
            var pt = new Point(rc.Location.X + rc.Width / 2, rc.Location.Y + rc.Height / 2);

            // rotate the string in small increments
            var step = 6;

            text = "PDF works in WPF!";
            for (int i = 0; i <= 360; i += step)
            {
                pdf.RotateAngle = i;
                font            = new Font("Courier New", 8 + i / 30.0, PdfFontStyle.Bold);
                byte b = (byte)(255 * (1 - i / 360.0));
                pdf.DrawString(text, font, Color.FromArgb(0xff, b, b, b), pt);
            }
        }
Exemplo n.º 6
0
        //---------------------------------------------------------------------------------
        #region ** graphics

        static void CreateDocumentGraphics(C1PdfDocument pdf)
        {
            // set up to draw
            Rect   rc   = new Rect(0, 0, 300, 200);
            string text = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font   font = new Font("Times New Roman", 12, PdfFontStyle.Italic | PdfFontStyle.Underline);

            // draw to pdf document
            int  penWidth = 0;
            byte penRGB   = 0;

            pdf.FillPie(Colors.Red, rc, 0, 20f);
            pdf.FillPie(Colors.Green, rc, 20f, 30f);
            pdf.FillPie(Colors.Blue, rc, 60f, 12f);
            pdf.FillPie(Colors.Orange, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(0xff, penRGB, penRGB, penRGB);
                Pen   pen      = new Pen(penColor, penWidth++);
                penRGB = (byte)(penRGB + 20);
                pdf.DrawArc(pen, rc, startAngle, 40f);
            }
            pdf.DrawRectangle(Colors.Red, rc);
            pdf.DrawString(text, font, Colors.Black, rc);

            // show a Bezier curve
            var pts = new Point[]
            {
                new Point(400, 100), new Point(420, 30),
                new Point(500, 140), new Point(530, 20),
            };

            // draw Bezier
            pdf.DrawBezier(new Pen(Colors.Blue, 4), pts[0], pts[1], pts[2], pts[3]);

            // show Bezier control points
            pdf.DrawLines(Colors.Gray, pts);
            foreach (Point pt in pts)
            {
                pdf.FillRectangle(Colors.Red, pt.X - 2, pt.Y - 2, 4, 4);
            }

            // title
            pdf.DrawString("Simple Bezier", font, Colors.Black, new Rect(500, 150, 100, 100));
        }
Exemplo n.º 7
0
        static void CreateDocumentGraphics(C1PdfDocument pdf)
        {
            // set up to draw
            Rect   rc   = new Rect(50, 70, 300, 300);
            string text = Strings.DocumentGraphicsText;
            Font   font = new Font("Segoe UI Light", 16, PdfFontStyle.Italic);

            // draw to pdf document
            int  penWidth = 0;
            byte penRGB   = 0;

            pdf.FillPie(Colors.DarkRed, rc, 0, 20f);
            pdf.FillPie(Colors.Green, rc, 20f, 30f);
            pdf.FillPie(Colors.Teal, rc, 60f, 12f);
            pdf.FillPie(Colors.Orange, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(0xff, penRGB, penRGB, penRGB);
                Pen   pen      = new Pen(penColor, penWidth++);
                penRGB = (byte)(penRGB + 20);
                pdf.DrawArc(pen, rc, startAngle, 40f);
            }
            //pdf.DrawRectangle(Colors.Red, rc);
            rc = new Rect(10, 20, 300, 50);
            pdf.DrawString(text, font, Colors.Black, rc);

            // show a Bezier curve
            var pts = new Point[]
            {
                new Point(400, 100), new Point(420, 30),
                new Point(500, 140), new Point(530, 20),
            };

            // draw Bezier
            pdf.DrawBezier(new Pen(Colors.Green, 4), pts[0], pts[1], pts[2], pts[3]);

            // show Bezier control points
            pdf.DrawLines(Colors.Gray, pts);
            foreach (Point pt in pts)
            {
                pdf.FillRectangle(Colors.Orange, pt.X - 2, pt.Y - 2, 4, 4);
            }

            // title
            pdf.DrawString(Strings.Bezier, font, Colors.Black, new Rect(450, 180, 100, 100));

            // figures
            Color clr     = Color.FromArgb(255, 250, 250, 0);
            Pen   linePen = new Pen(clr, 2);

            linePen.DashStyle = C1.Xaml.Pdf.DashStyle.DashDotDot;
            pdf.DrawLine(linePen, 120, 700, 550, 300);
            pts = new Point[]
            {
                new Point(200, 400), new Point(500, 300),
                new Point(500, 560), new Point(370, 660),
                new Point(250, 600), new Point(200, 400),
            };
            clr = Color.FromArgb(120, 0, 255, 0);
            pdf.FillPolygon(clr, pts);
            rc  = new Rect(120, 350, 300, 300);
            clr = Color.FromArgb(150, 0, 0, 255);
            pdf.FillEllipse(clr, rc);
            rc  = new Rect(100, 400, 250, 250);
            clr = Color.FromArgb(100, 255, 0, 0);
            pdf.FillRectangle(clr, rc);
        }
Exemplo n.º 8
0
        static Rect RenderTableHeader(C1PdfDocument pdf, Font font, Rect rc, string[] fields)
        {
            // calculate cell width (same for all columns)
            Rect rcCell = rc;
            rcCell.Width = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            foreach (string field in fields)
            {
                var height = pdf.MeasureString(field, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell.Height += 6; // add 6 point margin

            // render header cells
            var fmt = new StringFormat();
            fmt.LineAlignment = VerticalAlignment.Center;
            foreach (string field in fields)
            {
                pdf.FillRectangle(Colors.Black, rcCell);
                pdf.DrawString(field, font, Colors.White, rcCell, fmt);
                rcCell = PdfUtils.Offset(rcCell, rcCell.Width, 0);
            }

            // update rectangle and return it
            return PdfUtils.Offset(rc, 0, rcCell.Height);
        }
Exemplo n.º 9
0
        static void CreateDocumentText(C1PdfDocument pdf)
        {
            // use landscape for more impact
            pdf.Landscape = true;

            // measure and show some text
            var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            var font = new Font("Times New Roman", 9, PdfFontStyle.Italic);

            // create StringFormat used to set text alignment and line spacing
            var fmt = new StringFormat();
            fmt.LineSpacing = -1.5; // 1.5 char height
            fmt.Alignment = HorizontalAlignment.Center;

            // measure it
            var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
            var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);
            rc = PdfUtils.Offset(rc, 72, 0);

            // draw a rounded frame
            rc = PdfUtils.Inflate(rc, 10, 10);
            pdf.FillRectangle(Colors.Black, rc, new Size(30, 30));
            pdf.DrawRectangle(new Pen(Colors.Red, 4), rc, new Size(30, 30));
            rc = PdfUtils.Inflate(rc, -10, -10);

            // draw the text
            pdf.DrawString(text, font, Colors.White, rc, fmt);

            // now draw some text rotating about the center of the page
            rc = pdf.PageRectangle;
            rc = PdfUtils.Offset(rc, rc.Width / 2, rc.Height / 2);

            // build StringFormat used to rotate the text
            fmt = new StringFormat();

            // rotate the string in small increments
            var step = 6;
            text = "PDF works in WPF!";
            for (int i = 0; i <= 360; i += step)
            {
                fmt.Angle = i;
                font = new Font("Courier New", 8 + i / 30.0, PdfFontStyle.Bold);
                byte b = (byte)(255 * (1 - i / 360.0));
                pdf.DrawString(text, font, Color.FromArgb(0xff, b, b, b), rc, fmt);
            }
        }
Exemplo n.º 10
0
        static void CreateDocumentGraphics(C1PdfDocument pdf)
        {
            // set up to draw
            Rect rc = new Rect(0, 0, 300, 200);
            string text = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font font = new Font("Times New Roman", 12, PdfFontStyle.Italic | PdfFontStyle.Underline);

            // draw to pdf document
            int penWidth = 0;
            byte penRGB = 0;
            pdf.FillPie(Colors.Red, rc, 0, 20f);
            pdf.FillPie(Colors.Green, rc, 20f, 30f);
            pdf.FillPie(Colors.Blue, rc, 60f, 12f);
            pdf.FillPie(Colors.Orange, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(0xff, penRGB, penRGB, penRGB);
                Pen pen = new Pen(penColor, penWidth++);
                penRGB = (byte)(penRGB + 20);
                pdf.DrawArc(pen, rc, startAngle, 40f);
            }
            pdf.DrawRectangle(Colors.Red, rc);
            pdf.DrawString(text, font, Colors.Black, rc);

            // show a Bezier curve
            var pts = new Point[]
            {
                new Point(400, 100), new Point(420,  30),
                new Point(500, 140), new Point(530,  20),
            };

            // draw Bezier
            pdf.DrawBezier(new Pen(Colors.Blue, 4), pts[0], pts[1], pts[2], pts[3]);

            // show Bezier control points
            pdf.DrawLines(Colors.Gray, pts);
            foreach (Point pt in pts)
            {
                pdf.FillRectangle(Colors.Red, pt.X - 2, pt.Y - 2, 4, 4);
            }

            // title
            pdf.DrawString("Simple Bezier", font, Colors.Black, new Rect(500, 150, 100, 100));
        }